braid 1.0.16 → 1.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78d66492c589068152aee142e694bf02ee1201bd
4
- data.tar.gz: 54d080bf631011a6c09e8882337539eaed2b510f
3
+ metadata.gz: 6b8ca4b2ca46100c1204aa7e8303d29f0ca2f827
4
+ data.tar.gz: 2762804b4104a9102b215ae04c697607d279667a
5
5
  SHA512:
6
- metadata.gz: dbde11ac65aae3c78581e0d99e90def3b997d72929723abcb9fb097d7743cd8ebb8697a8ae161a5af1795fdc632745f86928bddae45b08cc847d6ded37dbdebb
7
- data.tar.gz: 1e52e6ad9304532cf6c8e340b9b57643e5550e9f4858ac1d798abcc116d1cc1e45355ada3b92cd76ac3d60ffcb9b4ad0c03650ea3b3550032b26fb1d24c83a6d
6
+ metadata.gz: d482a938bccaec81fdaf42c058a6d90fc88915335cf46b6a6896e00542850040a3de103026013cb974010389667397393efe1371108afc386f90ed02500b796a
7
+ data.tar.gz: 7a8eae42c2d2f5d41b6c1f8f18c34d3ee670c5acef87e79c24965a61b71808a16a81d676f00de2dc84ad5725292b046b4b9fe9a0d778d0372e1fa8e3fc52150a
data/.travis.yml CHANGED
@@ -14,6 +14,4 @@ git:
14
14
  depth: 10
15
15
  before_install:
16
16
  - git --version
17
- - git config --global user.name "Somebody"
18
- - git config --global user.email "you@example.com"
19
17
  - gem update bundler
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Braid
2
2
 
3
3
  [![Build Status](https://secure.travis-ci.org/cristibalan/braid.png?branch=master)](http://travis-ci.org/cristibalan/braid)
4
- [![Gem](https://img.shields.io/gem/v/braid.svg?maxAge=2592000)]()
4
+ [![Gem](https://img.shields.io/gem/v/braid.svg?maxAge=2592000)](https://rubygems.org/gems/braid)
5
5
 
6
6
  Braid is a simple tool to help track vendor branches in a
7
7
  [Git](http://git-scm.com/) repository.
@@ -35,17 +35,11 @@ repositories and use an automated mechanism for updating the external library
35
35
  and generating patches to upgrade the external library.
36
36
 
37
37
  Braid creates a file `.braids.json` in the root of your repository that contains
38
- references to external libraries or mirrors. There are two types of mirrors in
39
- Braid: squashed and full. Mirrors are squashed by default, which is what you'll
40
- generally want because they're faster and don't pollute your history with
41
- commits from the mirrors.
38
+ references to external libraries or mirrors. The configuration allows you to control
39
+ aspects of the mirroring process such as;
42
40
 
43
- Full mirrors are useful when you want to view imported history in your own
44
- project. You usually want this if the mirror is also a repository you have
45
- access to, for example, when using shared code across projects.
46
-
47
- Please note that you cannot change between mirror types after the initial add.
48
- You'll have to remove the mirror and add it again.
41
+ * whether the mirror is locked to a particular version of the external library.
42
+ * whether the mirror includes the entire external library or just a subdirectory.
49
43
 
50
44
  ## Installation
51
45
 
@@ -99,13 +93,15 @@ Use the built in help system to find out about all commands and options:
99
93
 
100
94
  braid add git://github.com/rails/rails.git vendor/rails
101
95
 
102
- #### Adding mirrors with revisions
96
+ #### Adding a subdirectory from a mirror
103
97
 
104
- braid add --revision bf1b1e0 git://github.com/rails/rails.git vendor/rails
98
+ This is useful if you want to add a subdirectory from a mirror into your own project.
105
99
 
106
- #### Adding mirrors with full history
100
+ braid add --path dist https://github.com/twbs/bootstrap.git vendor/assets/bootstrap
107
101
 
108
- braid add --full git://github.com/mislav/will_paginate.git vendor/plugins/will_paginate
102
+ #### Adding mirrors with revisions
103
+
104
+ braid add --revision bf1b1e0 git://github.com/rails/rails.git vendor/rails
109
105
 
110
106
  #### Updating mirrors
111
107
 
data/bin/braid CHANGED
@@ -40,11 +40,11 @@ Main {
40
40
  . braid add http://remote/path local/dir
41
41
  TXT
42
42
 
43
- mixin :argument_url, :optional_path, :option_branch, :option_revision, :option_full, :option_verbose, :option_remote_path
43
+ mixin :argument_url, :optional_local_path, :option_branch, :option_revision, :option_verbose, :option_path
44
44
 
45
45
  run {
46
46
  Braid.verbose = verbose
47
- Braid::Command.run(:add, url, {'path' => path, 'branch' => branch, 'revision' => revision, 'full' => full, 'remote_path' => remote_path})
47
+ Braid::Command.run(:add, url, {'path' => local_path, 'branch' => branch, 'revision' => revision, 'remote_path' => path})
48
48
  }
49
49
  }
50
50
 
@@ -65,7 +65,7 @@ Main {
65
65
  . braid update local/dir
66
66
  TXT
67
67
 
68
- mixin :optional_path, :option_revision, :option_head, :option_verbose, :option_keep_remote
68
+ mixin :optional_local_path, :option_revision, :option_head, :option_verbose, :option_keep_remote
69
69
 
70
70
  run {
71
71
  options = {
@@ -74,7 +74,7 @@ Main {
74
74
  'keep' => keep
75
75
  }
76
76
  Braid.verbose = verbose
77
- Braid::Command.run(:update, path, options)
77
+ Braid::Command.run(:update, local_path, options)
78
78
  }
79
79
  }
80
80
 
@@ -91,14 +91,14 @@ Main {
91
91
  . braid remove local/dir
92
92
  TXT
93
93
 
94
- mixin :argument_path, :option_verbose, :option_keep_remote
94
+ mixin :argument_local_path, :option_verbose, :option_keep_remote
95
95
 
96
96
  run {
97
97
  options = {
98
98
  :keep => keep
99
99
  }
100
100
  Braid.verbose = verbose
101
- Braid::Command.run(:remove, path, options)
101
+ Braid::Command.run(:remove, local_path, options)
102
102
  }
103
103
  }
104
104
 
@@ -107,14 +107,14 @@ Main {
107
107
  Show diff of local changes to mirror.
108
108
  TXT
109
109
 
110
- mixin :optional_path, :option_verbose, :option_keep_remote
110
+ mixin :optional_local_path, :option_verbose, :option_keep_remote
111
111
 
112
112
  run {
113
113
  options = {
114
114
  'keep' => keep
115
115
  }
116
116
  Braid.verbose = verbose
117
- Braid::Command.run(:diff, path, options)
117
+ Braid::Command.run(:diff, local_path, options)
118
118
  }
119
119
  }
120
120
 
@@ -123,7 +123,7 @@ Main {
123
123
  Push local mirror changes to remote.
124
124
  TXT
125
125
 
126
- mixin :argument_path, :option_branch, :option_verbose, :option_keep_remote
126
+ mixin :argument_local_path, :option_branch, :option_verbose, :option_keep_remote
127
127
 
128
128
  run {
129
129
  options = {
@@ -131,7 +131,7 @@ Main {
131
131
  'branch' => branch
132
132
  }
133
133
  Braid.verbose = verbose
134
- Braid::Command.run(:push, path, options)
134
+ Braid::Command.run(:push, local_path, options)
135
135
  }
136
136
  }
137
137
 
@@ -140,12 +140,12 @@ Main {
140
140
  Set up git remotes.
141
141
  TXT
142
142
 
143
- mixin :optional_path, :option_verbose, :option_force
143
+ mixin :optional_local_path, :option_verbose, :option_force
144
144
 
145
145
  run {
146
146
  Braid.verbose = verbose
147
147
  Braid.force = force
148
- Braid::Command.run(:setup, path)
148
+ Braid::Command.run(:setup, local_path)
149
149
  }
150
150
  }
151
151
 
@@ -157,36 +157,25 @@ Main {
157
157
  }
158
158
  }
159
159
 
160
- mode(:list) {
161
- description 'Show all tracked mirrors (and if updates are available).'
162
-
163
- mixin :option_verbose
164
-
165
- run {
166
- Braid.verbose = verbose
167
- Braid::Command.run(:list)
168
- }
169
- }
170
-
171
160
  mode(:status) {
172
161
  description 'Show the status of all tracked mirrors (and if updates are available).'
173
162
 
174
- mixin :optional_path, :option_verbose
163
+ mixin :optional_local_path, :option_verbose
175
164
 
176
165
  run {
177
166
  Braid.verbose = verbose
178
- Braid::Command.run(:status, path)
167
+ Braid::Command.run(:status, local_path)
179
168
  }
180
169
  }
181
170
 
182
- mixin(:argument_path) {
183
- argument(:path) {
171
+ mixin(:argument_local_path) {
172
+ argument(:local_path) {
184
173
  attr
185
174
  }
186
175
  }
187
176
 
188
- mixin(:optional_path) {
189
- argument(:path) {
177
+ mixin(:optional_local_path) {
178
+ argument(:local_path) {
190
179
  optional
191
180
  attr
192
181
  }
@@ -207,8 +196,8 @@ Main {
207
196
  }
208
197
  }
209
198
 
210
- mixin(:option_remote_path) {
211
- option(:remote_path, :p) {
199
+ mixin(:option_path) {
200
+ option(:path, :p) {
212
201
  optional
213
202
  argument :required
214
203
  desc 'remote path'
@@ -233,14 +222,6 @@ Main {
233
222
  }
234
223
  }
235
224
 
236
- mixin(:option_full) {
237
- option(:full) {
238
- optional
239
- desc 'include mirror history' # FIXME
240
- attr
241
- }
242
- }
243
-
244
225
  mixin(:option_verbose) {
245
226
  option(:verbose, :v) {
246
227
  optional
data/braid.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |s|
28
28
  s.add_dependency(%q<main>, ['>= 4.7.3'])
29
29
  s.add_dependency(%q<open4>, ['>= 1.0.1']) unless defined?(JRUBY_VERSION)
30
30
 
31
- s.add_development_dependency(%q<rspec>, ['>= 2.12.0'])
31
+ s.add_development_dependency(%q<rspec>, ['>= 3.4.4'])
32
32
  s.add_development_dependency(%q<mocha>, ['>= 0.9.11'])
33
33
  end
@@ -19,9 +19,6 @@ module Braid
19
19
  new_revision = validate_new_revision(mirror, options['revision'])
20
20
  target_revision = determine_target_revision(mirror, new_revision)
21
21
 
22
- unless mirror.squashed?
23
- git.merge_ours(target_revision)
24
- end
25
22
  git.read_tree_prefix_u(target_revision, mirror.path)
26
23
 
27
24
  mirror.revision = new_revision
@@ -8,24 +8,33 @@ module Braid
8
8
  protected
9
9
 
10
10
  def diff_all(options = {})
11
- print "\n"
12
- msg "Diffing all mirrors.\n=======================================================\n"
13
11
  config.mirrors.each do |path|
14
- msg "Diffing #{path}\n=======================================================\n"
15
- diff_one(path, options)
16
- msg "=======================================================\n"
12
+ separator
13
+ msg "Diffing #{path}\n"
14
+ separator
15
+ diff = perform_diff(path, options)
16
+ puts diff unless diff.empty?
17
17
  end
18
- print "\n"
19
18
  end
20
19
 
21
20
  def diff_one(path, options = {})
21
+ diff = perform_diff(path, options)
22
+ puts diff unless diff.empty?
23
+ end
24
+
25
+ def separator
26
+ puts "=======================================================\n"
27
+ end
28
+
29
+ def perform_diff(path, options = {})
22
30
  mirror = config.get!(path)
23
31
  setup_remote(mirror)
24
32
 
25
33
  diff = mirror.diff
26
- puts diff unless diff.empty?
27
34
 
28
35
  clear_remote(mirror, options)
36
+
37
+ diff
29
38
  end
30
39
  end
31
40
  end
@@ -34,9 +34,13 @@ module Braid
34
34
  elsif File.directory?(remote_url)
35
35
  remote_url = File.expand_path(remote_url)
36
36
  end
37
+ user_name = git.config(%w(--local --get user.name))
38
+ user_email = git.config(%w(--local --get user.email))
37
39
  Dir.chdir(clone_dir) do
38
40
  msg 'Cloning mirror with local changes.'
39
41
  git.init
42
+ git.config(['--local', 'user.name', "\"#{user_name}\""]) if user_name
43
+ git.config(['--local', 'user.email', "\"#{user_email}\""]) if user_email
40
44
  git.fetch(mirror.cached_url) if File.exist?(mirror.cached_url)
41
45
  git.fetch(remote_url, "+refs/heads/#{mirror.branch}")
42
46
  git.checkout(base_revision)
@@ -2,9 +2,7 @@ module Braid
2
2
  module Commands
3
3
  class Status < Command
4
4
  def run(path = nil, options = {})
5
- with_reset_on_error do
6
- path ? status_one(path, options) : status_all(options)
7
- end
5
+ path ? status_one(path, options) : status_all(options)
8
6
  end
9
7
 
10
8
  protected
@@ -55,7 +55,7 @@ module Braid
55
55
  return
56
56
  end
57
57
 
58
- base_revision = mirror.base_revision if mirror.squashed?
58
+ base_revision = mirror.base_revision
59
59
 
60
60
  mirror.revision = new_revision
61
61
  mirror.lock = new_revision if options['revision']
@@ -63,16 +63,12 @@ module Braid
63
63
  msg "Merging in mirror '#{mirror.path}'." if verbose?
64
64
  in_error = false
65
65
  begin
66
- if mirror.squashed?
67
- local_hash = git.rev_parse('HEAD')
68
- base_hash = generate_tree_hash(mirror, mirror.versioned_path(base_revision))
69
- remote_hash = generate_tree_hash(mirror, target_revision)
70
- ENV["GITHEAD_#{local_hash}"] = 'HEAD'
71
- ENV["GITHEAD_#{remote_hash}"] = target_revision
72
- git.merge_trees(base_hash, local_hash, remote_hash)
73
- else
74
- git.merge_subtree(target_revision)
75
- end
66
+ local_hash = git.rev_parse('HEAD')
67
+ base_hash = generate_tree_hash(mirror, mirror.versioned_path(base_revision))
68
+ remote_hash = generate_tree_hash(mirror, target_revision)
69
+ ENV["GITHEAD_#{local_hash}"] = 'HEAD'
70
+ ENV["GITHEAD_#{remote_hash}"] = target_revision
71
+ git.merge_trees(base_hash, local_hash, remote_hash)
76
72
  rescue Operations::MergeError => error
77
73
  in_error = true
78
74
  print error.conflicts_text
data/lib/braid/mirror.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Braid
2
2
  class Mirror
3
- ATTRIBUTES = %w(url branch squashed revision lock remote_path)
3
+ ATTRIBUTES = %w(url branch revision lock path)
4
4
 
5
5
  class UnknownType < BraidError
6
6
  def message
@@ -30,11 +30,9 @@ module Braid
30
30
  path = (options['path'] || extract_path_from_url(url)).sub(/\/$/, '')
31
31
  raise PathRequired unless path
32
32
 
33
- squashed = !options['full']
34
-
35
33
  remote_path = options['remote_path']
36
34
 
37
- attributes = {'url' => url, 'branch' => branch, 'squashed' => squashed, 'remote_path' => remote_path}
35
+ attributes = {'url' => url, 'branch' => branch, 'path' => remote_path}
38
36
  self.new(path, attributes)
39
37
  end
40
38
 
@@ -46,19 +44,11 @@ module Braid
46
44
  !!lock
47
45
  end
48
46
 
49
- def squashed?
50
- !!squashed
51
- end
52
-
53
47
  def merged?(commit)
54
48
  # tip from spearce in #git:
55
49
  # `test z$(git merge-base A B) = z$(git rev-parse --verify A)`
56
50
  commit = git.rev_parse(commit)
57
- if squashed?
58
- !!base_revision && git.merge_base(commit, base_revision) == commit
59
- else
60
- git.merge_base(commit, 'HEAD') == commit
61
- end
51
+ !!base_revision && git.merge_base(commit, base_revision) == commit
62
52
  end
63
53
 
64
54
  def versioned_path(revision)
@@ -89,6 +79,14 @@ module Braid
89
79
  end
90
80
  end
91
81
 
82
+ def remote_path
83
+ self.attributes['path']
84
+ end
85
+
86
+ def remote_path=(remote_path)
87
+ self.attributes['path'] = remote_path
88
+ end
89
+
92
90
  def cached_url
93
91
  git_cache.path(url)
94
92
  end
@@ -315,6 +315,10 @@ module Braid
315
315
  end
316
316
  end
317
317
 
318
+ def config(args)
319
+ invoke(:config, args) rescue nil
320
+ end
321
+
318
322
  def rm_r(path)
319
323
  invoke(:rm, '-r', path)
320
324
  true
data/lib/braid/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Braid
2
- VERSION = '1.0.16'
2
+ VERSION = '1.0.17'
3
3
  end
data/lib/braid.rb CHANGED
@@ -43,7 +43,6 @@ require 'braid/config'
43
43
  require 'braid/command'
44
44
  require 'braid/commands/add'
45
45
  require 'braid/commands/diff'
46
- require 'braid/commands/list'
47
46
  require 'braid/commands/push'
48
47
  require 'braid/commands/remove'
49
48
  require 'braid/commands/setup'
data/spec/config_spec.rb CHANGED
@@ -10,14 +10,14 @@ describe 'Braid::Config, when empty' do
10
10
  end
11
11
 
12
12
  it 'should not get a mirror by name' do
13
- @config.get('path').should be_nil
14
- lambda { @config.get!('path') }.should raise_error(Braid::Config::MirrorDoesNotExist)
13
+ expect(@config.get('path')).to be_nil
14
+ expect { @config.get!('path') }.to raise_error(Braid::Config::MirrorDoesNotExist)
15
15
  end
16
16
 
17
17
  it 'should add a mirror and its params' do
18
18
  @mirror = build_mirror
19
19
  @config.add(@mirror)
20
- @config.get('path').path.should_not be_nil
20
+ expect(@config.get('path').path).not_to be_nil
21
21
  end
22
22
  end
23
23
 
@@ -33,27 +33,27 @@ describe 'Braid::Config, with one mirror' do
33
33
  end
34
34
 
35
35
  it 'should get the mirror by name' do
36
- @config.get('path').should == @mirror
37
- @config.get!('path').should == @mirror
36
+ expect(@config.get('path')).to eq(@mirror)
37
+ expect(@config.get!('path')).to eq(@mirror)
38
38
  end
39
39
 
40
40
  it 'should raise when trying to overwrite a mirror on add' do
41
- lambda { @config.add(@mirror) }.should raise_error(Braid::Config::PathAlreadyInUse)
41
+ expect { @config.add(@mirror) }.to raise_error(Braid::Config::PathAlreadyInUse)
42
42
  end
43
43
 
44
44
  it 'should remove the mirror' do
45
45
  @config.remove(@mirror)
46
- @config.get('path').should be_nil
46
+ expect(@config.get('path')).to be_nil
47
47
  end
48
48
 
49
49
  it 'should update the mirror with new params' do
50
50
  @mirror.branch = 'other'
51
51
  @config.update(@mirror)
52
- @config.get('path').attributes.should == {'branch' => 'other'}
52
+ expect(@config.get('path').attributes).to eq({'branch' => 'other'})
53
53
  end
54
54
 
55
55
  it 'should raise when trying to update nonexistent mirror' do
56
56
  @mirror.instance_variable_set('@path', 'other')
57
- lambda { @config.update(@mirror) }.should raise_error(Braid::Config::MirrorDoesNotExist)
57
+ expect { @config.update(@mirror) }.to raise_error(Braid::Config::MirrorDoesNotExist)
58
58
  end
59
59
  end
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../integration_helper'
1
+ require File.dirname(__FILE__) + '/integration_helper'
2
2
 
3
3
  describe 'Adding a mirror in a clean repository' do
4
4
 
@@ -9,33 +9,55 @@ describe 'Adding a mirror in a clean repository' do
9
9
 
10
10
  describe 'from a git repository' do
11
11
  before do
12
- @shiny = create_git_repo_from_fixture('shiny')
13
- @skit1 = create_git_repo_from_fixture('skit1')
14
- end
12
+ @repository_dir = create_git_repo_from_fixture('shiny', :name => 'Some body', :email => 'somebody@example.com')
13
+ @vendor_repository_dir = create_git_repo_from_fixture('skit1')
15
14
 
16
- it 'should add the files and commit' do
17
- in_dir(@shiny) do
18
- run_command("#{BRAID_BIN} add #{@skit1}")
15
+ in_dir(@repository_dir) do
16
+ run_command("#{BRAID_BIN} add #{@vendor_repository_dir}")
19
17
  end
18
+ end
20
19
 
21
- file_name = 'skit1/layouts/layout.liquid'
22
- run_command("diff -U 3 #{File.join(FIXTURE_PATH, file_name)} #{File.join(TMP_PATH, 'shiny', file_name)}")
20
+ it 'should add the files and commit' do
21
+ assert_no_diff("#{FIXTURE_PATH}/skit1/layouts/layout.liquid", "#{@repository_dir}/skit1/layouts/layout.liquid")
23
22
 
24
- output = run_command('git log --pretty=oneline').split("\n")
25
- output.length.should == 2
26
- output[0].should =~ /Braid: Add mirror 'skit1' at '[0-9a-f]{7}'/
23
+ assert_commit_subject(/Braid: Add mirror 'skit1' at '[0-9a-f]{7}'/)
24
+ assert_commit_author('Some body')
25
+ assert_commit_email('somebody@example.com')
27
26
  end
28
27
 
29
28
  it 'should create .braids.json and add the mirror to it' do
30
- in_dir(@shiny) do
31
- run_command("#{BRAID_BIN} add #{@skit1}")
29
+ braids = YAML::load_file("#{@repository_dir}/.braids.json")
30
+ expect(braids['skit1']['url']).to eq(@vendor_repository_dir)
31
+ expect(braids['skit1']['revision']).not_to be_nil
32
+ expect(braids['skit1']['branch']).to eq('master')
33
+ expect(braids['skit1']['path']).to be_nil
34
+ end
35
+ end
36
+
37
+ describe 'from a subdirectory in a git repository' do
38
+ before do
39
+ @repository_dir = create_git_repo_from_fixture('shiny', :name => 'Some body', :email => 'somebody@example.com')
40
+ @vendor_repository_dir = create_git_repo_from_fixture('skit1')
41
+
42
+ in_dir(@repository_dir) do
43
+ run_command("#{BRAID_BIN} add --path layouts #{@vendor_repository_dir}")
32
44
  end
45
+ end
46
+
47
+ it 'should add the files and commit' do
48
+ assert_no_diff("#{FIXTURE_PATH}/skit1/layouts/layout.liquid", "#{@repository_dir}/skit1/layout.liquid")
33
49
 
34
- braids = YAML::load_file("#{@shiny}/.braids.json")
35
- braids['skit1']['squashed'].should == true
36
- braids['skit1']['url'].should == @skit1
37
- braids['skit1']['revision'].should_not be_nil
38
- braids['skit1']['branch'].should == 'master'
50
+ assert_commit_subject(/Braid: Add mirror 'skit1' at '[0-9a-f]{7}'/)
51
+ assert_commit_author('Some body')
52
+ assert_commit_email('somebody@example.com')
53
+ end
54
+
55
+ it 'should create .braids.json and add the mirror to it' do
56
+ braids = YAML::load_file("#{@repository_dir}/.braids.json")
57
+ expect(braids['skit1']['url']).to eq(@vendor_repository_dir)
58
+ expect(braids['skit1']['revision']).not_to be_nil
59
+ expect(braids['skit1']['branch']).to eq('master')
60
+ expect(braids['skit1']['path']).to eq('layouts')
39
61
  end
40
62
  end
41
63
  end