braid 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37be2b94c125a05dd9b215f3146a4938cebcc5ed
4
- data.tar.gz: 9b83f817454c020924e75e88fe2aa19cef967b81
3
+ metadata.gz: cab5b4a0635df158bf25ffe1fa9d32f5b7f3bf30
4
+ data.tar.gz: b435890d0ed321e80b89cb56b71a46c6e638add8
5
5
  SHA512:
6
- metadata.gz: 06a6f9f7aefd950057e3708c3c86d0d98222fff882740d8efa82c36ef1e77eb1a8c9f618b6bd865b7e294fc6b8f4adc1db3cbcca9d48ab8aba07d325a45935b1
7
- data.tar.gz: 22ba789027b7a1612fa4f84fcbacf4fdd90ec8c8867d612a9d0182cbd0492337354e2771b44ddee79a0fb27fd9fd08d3db60556b44d27bf01c4a72a603ede5e4
6
+ metadata.gz: 16333b71784a667c94a8250e26f0ce82c5edf73060b388538cb5fbdf9cd892aab10fef7375e50592d358c0e8e90cc4cd693ec94120e7c448169fb639a47cdf76
7
+ data.tar.gz: c65b7965793f1a0350e480f9eb395073e2a875a7a42f2d5c4d900effe63a9d3af8c70ae092c043829815ecfd73afbbf1e19f806c2cd1ac1840b6c4595ece9301
data/bin/braid CHANGED
@@ -55,6 +55,7 @@ Main {
55
55
  * get new changes from remote
56
56
  * always creates a merge commit
57
57
  * updates metadata in .braids.json when revisions are changed
58
+ * removes the git remote by default, --keep can be used to suppress that
58
59
 
59
60
  Defaults to updating all unlocked mirrors if none is specified.
60
61
  TXT
@@ -64,11 +65,16 @@ Main {
64
65
  . braid update local/dir
65
66
  TXT
66
67
 
67
- mixin :optional_path, :option_revision, :option_head, :option_verbose
68
+ mixin :optional_path, :option_revision, :option_head, :option_verbose, :option_keep_remote
68
69
 
69
70
  run {
71
+ options = {
72
+ 'revision' => revision,
73
+ 'head' => head,
74
+ 'keep' => keep
75
+ }
70
76
  Braid.verbose = verbose
71
- Braid::Command.run(:update, path, {'revision' => revision, 'head' => head})
77
+ Braid::Command.run(:update, path, options)
72
78
  }
73
79
  }
74
80
 
@@ -88,8 +94,8 @@ Main {
88
94
  mixin :argument_path, :option_verbose, :option_keep_remote
89
95
 
90
96
  run {
91
- options = {
92
- :keep => keep
97
+ options = {
98
+ :keep => keep
93
99
  }
94
100
  Braid.verbose = verbose
95
101
  Braid::Command.run(:remove, path, options)
@@ -101,10 +107,13 @@ Main {
101
107
  Show diff of local changes to mirror.
102
108
  TXT
103
109
 
104
- mixin :argument_path, :option_verbose
110
+ mixin :optional_path, :option_verbose, :option_keep_remote
105
111
 
106
112
  run {
107
- Braid::Command.run(:diff, path)
113
+ options = {
114
+ 'keep' => keep
115
+ }
116
+ Braid::Command.run(:diff, path, options)
108
117
  }
109
118
  }
110
119
 
@@ -113,11 +122,14 @@ Main {
113
122
  Push local mirror changes to remote.
114
123
  TXT
115
124
 
116
- mixin :argument_path, :option_verbose
125
+ mixin :argument_path, :option_verbose, :option_keep_remote
117
126
 
118
127
  run {
128
+ options = {
129
+ 'keep' => keep
130
+ }
119
131
  Braid.verbose = verbose
120
- Braid::Command.run(:push, path)
132
+ Braid::Command.run(:push, path, options)
121
133
  }
122
134
  }
123
135
 
@@ -154,6 +166,17 @@ Main {
154
166
  }
155
167
  }
156
168
 
169
+ mode(:status) {
170
+ description 'Show the status of all tracked mirrors (and if updates are available).'
171
+
172
+ mixin :optional_path, :option_verbose
173
+
174
+ run {
175
+ Braid.verbose = verbose
176
+ Braid::Command.run(:status, path)
177
+ }
178
+ }
179
+
157
180
  mixin(:argument_path) {
158
181
  argument(:path) {
159
182
  attr
@@ -48,3 +48,4 @@ require 'braid/commands/push'
48
48
  require 'braid/commands/remove'
49
49
  require 'braid/commands/setup'
50
50
  require 'braid/commands/update'
51
+ require 'braid/commands/status'
@@ -48,6 +48,10 @@ module Braid
48
48
  Command.run(:setup, mirror.path)
49
49
  end
50
50
 
51
+ def clear_remote(mirror, options)
52
+ git.remote_rm(mirror.remote) unless options['keep']
53
+ end
54
+
51
55
  def use_local_cache?
52
56
  Braid.use_local_cache
53
57
  end
@@ -30,6 +30,8 @@ module Braid
30
30
 
31
31
  git.commit("Add mirror '#{mirror.path}' at #{display_revision(mirror)}")
32
32
  msg "Added mirror at #{display_revision(mirror)}."
33
+
34
+ clear_remote(mirror, options)
33
35
  end
34
36
  end
35
37
  end
@@ -1,12 +1,33 @@
1
1
  module Braid
2
2
  module Commands
3
3
  class Diff < Command
4
- def run(path)
4
+ def run(path = nil, options = {})
5
+ with_reset_on_error do
6
+ path ? diff_one(path, options) : diff_all(options)
7
+ end
8
+ end
9
+
10
+ protected
11
+
12
+ def diff_all(options = {})
13
+ print "\n"
14
+ msg "Diffing all mirrors.\n=======================================================\n"
15
+ config.mirrors.each do |path|
16
+ msg "Diffing #{path}\n=======================================================\n"
17
+ diff_one(path, options)
18
+ msg "=======================================================\n"
19
+ end
20
+ print "\n"
21
+ end
22
+
23
+ def diff_one(path, options = {})
5
24
  mirror = config.get!(path)
6
25
  setup_remote(mirror)
7
26
 
8
27
  diff = mirror.diff
9
28
  puts diff unless diff.empty?
29
+
30
+ clear_remote(mirror, options)
10
31
  end
11
32
  end
12
33
  end
@@ -2,37 +2,9 @@ module Braid
2
2
  module Commands
3
3
  class List < Command
4
4
  def run(path = nil, options = {})
5
- with_reset_on_error do
6
- path ? list_one(path, options) : list_all(options)
7
- end
5
+ msg "WARNING: list command is deprecated. Please use \"braid status\" instead.\n"
6
+ Command.run(:status, path, options)
8
7
  end
9
-
10
- protected
11
- def list_all(options = {})
12
- options.reject! { |k, v| %w(revision head).include?(k) }
13
- print "\n"
14
- msg "Listing all mirrors.\n=======================================================\n"
15
- config.mirrors.each do |path|
16
- mirror = config.get!(path)
17
- print path.to_s
18
- print ' (' + mirror.base_revision + ')'
19
- print ' [LOCKED]' if mirror.locked?
20
- setup_remote(mirror)
21
- msg "Fetching new commits for '#{mirror.path}'." if verbose?
22
- mirror.fetch
23
- new_revision = validate_new_revision(mirror, options['revision'])
24
- print ' (Remote Modified)' if new_revision.to_s != mirror.base_revision.to_s
25
- local_file_count = git.read_ls_files(mirror.path).split.size
26
- if 0 == local_file_count
27
- print ' (Removed Locally)'
28
- elsif !mirror.diff.empty?
29
- print ' (Locally Modified)'
30
- end
31
- print "\n"
32
- end
33
- print "\n"
34
- end
35
-
36
8
  end
37
9
  end
38
10
  end
@@ -41,6 +41,8 @@ module Braid
41
41
  git.push(remote_url, "HEAD:#{mirror.branch}")
42
42
  end
43
43
  FileUtils.rm_r(clone_dir)
44
+
45
+ clear_remote(mirror, options)
44
46
  end
45
47
  end
46
48
  end
@@ -27,7 +27,7 @@ module Braid
27
27
  end
28
28
  end
29
29
 
30
- msg "Setup: Creating remote for '#{mirror.path}'."
30
+ msg "Setup: Creating remote for '#{mirror.path}'." if verbose?
31
31
  url = use_local_cache? ? git_cache.path(mirror.url) : mirror.url
32
32
  git.remote_add(mirror.remote, url, mirror.branch)
33
33
  end
@@ -0,0 +1,42 @@
1
+ module Braid
2
+ module Commands
3
+ class Status < Command
4
+ def run(path = nil, options = {})
5
+ with_reset_on_error do
6
+ path ? status_one(path, options) : status_all(options)
7
+ end
8
+ end
9
+
10
+ protected
11
+
12
+ def status_all(options = {})
13
+ print "\n"
14
+ msg "Listing all mirrors.\n=======================================================\n"
15
+ config.mirrors.each do |path|
16
+ list_one(path, options)
17
+ end
18
+ print "\n"
19
+ end
20
+
21
+ def status_one(path, options = {})
22
+ mirror = config.get!(path)
23
+ setup_remote(mirror)
24
+ mirror.fetch
25
+ print path.to_s
26
+ print ' (' + mirror.base_revision + ')'
27
+ print ' [LOCKED]' if mirror.locked?
28
+ msg "Fetching new commits for '#{mirror.path}'." if verbose?
29
+ new_revision = validate_new_revision(mirror, options['revision'])
30
+ print ' (Remote Modified)' if new_revision.to_s != mirror.base_revision.to_s
31
+ local_file_count = git.read_ls_files(mirror.path).split.size
32
+ if 0 == local_file_count
33
+ print ' (Removed Locally)'
34
+ elsif !mirror.diff.empty?
35
+ print ' (Locally Modified)'
36
+ end
37
+ print "\n"
38
+ clear_remote(mirror, options)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,9 +2,7 @@ module Braid
2
2
  module Commands
3
3
  class Update < Command
4
4
  def run(path, options = {})
5
- with_reset_on_error do
6
- path ? update_one(path, options) : update_all(options)
7
- end
5
+ path ? update_one(path, options) : update_all(options)
8
6
  end
9
7
 
10
8
  protected
@@ -13,6 +11,7 @@ module Braid
13
11
  options.reject! { |k, v| %w(revision head).include?(k) }
14
12
  msg 'Updating all mirrors.'
15
13
  config.mirrors.each do |path|
14
+ bail_on_local_changes!
16
15
  update_one(path, options)
17
16
  end
18
17
  end
@@ -44,13 +43,14 @@ module Braid
44
43
  begin
45
44
  new_revision = validate_new_revision(mirror, options['revision'])
46
45
  rescue InvalidRevision
47
- # Ignored as it means the revision matches expecte
46
+ # Ignored as it means the revision matches expected
48
47
  end
49
48
  target_revision = determine_target_revision(new_revision)
50
49
 
51
50
  if (options['revision'] && was_locked && target_revision == mirror.base_revision) ||
52
51
  (options['revision'].nil? && !was_locked && mirror.merged?(target_revision))
53
52
  msg "Mirror '#{mirror.path}' is already up to date."
53
+ clear_remote(mirror, options)
54
54
  return
55
55
  end
56
56
 
@@ -63,6 +63,7 @@ module Braid
63
63
  mirror.lock = new_revision if options['revision']
64
64
 
65
65
  msg "Merging in mirror '#{mirror.path}'." if verbose?
66
+ in_error = false
66
67
  begin
67
68
  if mirror.squashed?
68
69
  local_hash = git.rev_parse('HEAD')
@@ -75,6 +76,7 @@ module Braid
75
76
  git.merge_subtree(target_revision)
76
77
  end
77
78
  rescue Operations::MergeError => error
79
+ in_error = true
78
80
  print error.conflicts_text
79
81
  msg 'Caught merge error. Breaking.'
80
82
  end
@@ -83,13 +85,14 @@ module Braid
83
85
  add_config_file
84
86
 
85
87
  commit_message = "Update mirror '#{mirror.path}' to #{display_revision(mirror)}"
86
- if error
88
+ if in_error
87
89
  File.open('.git/MERGE_MSG', 'w') { |f| f.puts(commit_message) }
88
90
  return
89
91
  end
90
92
 
91
93
  git.commit(commit_message)
92
94
  msg "Updated mirror to #{display_revision(mirror)}."
95
+ clear_remote(mirror, options)
93
96
  end
94
97
 
95
98
  def generate_tree_hash(mirror, revision)
@@ -97,7 +100,7 @@ module Braid
97
100
  git.read_tree_im('HEAD')
98
101
  git.rm_r_cached(mirror.path)
99
102
  git.read_tree_prefix_i(revision, mirror.path)
100
- git.write_tree()
103
+ git.write_tree
101
104
  end
102
105
  end
103
106
  end
@@ -1,6 +1,6 @@
1
1
  module Braid
2
2
  class Mirror
3
- ATTRIBUTES = %w(url remote branch squashed revision lock)
3
+ ATTRIBUTES = %w(url branch squashed revision lock)
4
4
 
5
5
  class UnknownType < BraidError
6
6
  def message
@@ -27,14 +27,12 @@ module Braid
27
27
 
28
28
  branch = options['branch'] || 'master'
29
29
 
30
- unless path = options['path'] || extract_path_from_url(url)
31
- raise PathRequired
32
- end
30
+ path = (options['path'] || extract_path_from_url(url)).sub(/\/$/, '')
31
+ raise PathRequired unless path
33
32
 
34
- remote = "#{branch}/braid/#{path}"
35
33
  squashed = !options['full']
36
34
 
37
- attributes = {'url' => url, 'remote' => remote, 'branch' => branch, 'squashed' => squashed}
35
+ attributes = {'url' => url, 'branch' => branch, 'squashed' => squashed}
38
36
  self.new(path, attributes)
39
37
  end
40
38
 
@@ -90,11 +88,7 @@ module Braid
90
88
  end
91
89
 
92
90
  def remote
93
- if (attributes['remote'] && attributes['remote'] =~ /^braid\//)
94
- attributes['remote'] = "#{branch}/#{attributes['remote']}"
95
- else
96
- attributes['remote']
97
- end
91
+ "#{branch}/braid/#{path}"
98
92
  end
99
93
 
100
94
  private
@@ -147,14 +147,6 @@ module Braid
147
147
  [status, out, err]
148
148
  end
149
149
 
150
- def sh(cmd, message = nil)
151
- message ||= 'could not fetch' if cmd =~ /fetch/
152
- log(cmd)
153
- `#{cmd}`
154
- raise ShellExecutionError, message unless $?.exitstatus == 0
155
- true
156
- end
157
-
158
150
  def msg(str)
159
151
  puts "Braid: #{str}"
160
152
  end
@@ -193,8 +185,7 @@ module Braid
193
185
 
194
186
  def fetch(remote = nil, *args)
195
187
  args.unshift "-n #{remote}" if remote
196
- # open4 messes with the pipes of index-pack
197
- sh("git fetch #{args.join(' ')} > #{Gem.win_platform? ? 'nul' : '/dev/null'}")
188
+ exec!("git fetch #{args.join(' ')} > #{Gem.win_platform? ? 'nul' : '/dev/null'}")
198
189
  end
199
190
 
200
191
  def checkout(treeish)
@@ -1,3 +1,3 @@
1
1
  module Braid
2
- VERSION = '1.0.10'
2
+ VERSION = '1.0.11'
3
3
  end
@@ -36,7 +36,6 @@ describe 'Adding a mirror in a clean repository' do
36
36
  braids['skit1']['url'].should == @skit1
37
37
  braids['skit1']['revision'].should_not be_nil
38
38
  braids['skit1']['branch'].should == 'master'
39
- braids['skit1']['remote'].should == 'master/braid/skit1'
40
39
  end
41
40
  end
42
41
  end
@@ -10,6 +10,11 @@ describe 'Braid::Mirror.new_from_options' do
10
10
  new_from_options('http://path.git')
11
11
  @mirror.path.should == 'path'
12
12
  end
13
+
14
+ it 'should strip trailing slash from specified path' do
15
+ new_from_options('http://path.git', 'path' => 'vendor/tools/mytool/')
16
+ @mirror.path.should == 'vendor/tools/mytool'
17
+ end
13
18
  end
14
19
 
15
20
  describe 'Braid::Mirror#diff' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: braid
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristi Balan
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-22 00:00:00.000000000 Z
13
+ date: 2017-03-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: main
@@ -93,6 +93,7 @@ files:
93
93
  - lib/braid/commands/push.rb
94
94
  - lib/braid/commands/remove.rb
95
95
  - lib/braid/commands/setup.rb
96
+ - lib/braid/commands/status.rb
96
97
  - lib/braid/commands/update.rb
97
98
  - lib/braid/config.rb
98
99
  - lib/braid/mirror.rb