braid 1.1.7 → 1.1.8

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
  SHA256:
3
- metadata.gz: ad14f6dd7a5d428c5796bbd19039aae6e59f5803d93da3889fe0a92a8afd032b
4
- data.tar.gz: 9d6bcfd73c5a306f853e6b9653edda5aff6a7bbd3541b6ab644bd7b96bc510e6
3
+ metadata.gz: 6efac3d863ec38976f90032c012ebe9acca8911a9316608d7dfe704cc0d8925b
4
+ data.tar.gz: 5c5c8870bbf0702767234ee5b467324c7c25914ed3de06ac67ef903f87ca4ee7
5
5
  SHA512:
6
- metadata.gz: 817cd08525921352f103a81f05b6c550e8eaff62fb647c04d0ecb746e6ed425a78ef1bea4a477786675c406b0e23982f36a52eea205278a3b25ccee6e64ecdf5
7
- data.tar.gz: 76d9e62b1d58a437a8eae77f879b5a66ec6a30cda270d267cc458e621a3f1560fa192f5cc435b5e718c9f093691464d458b049d2e236864d0faea6e801c89629
6
+ metadata.gz: dcb55a781668a47cdae99c5e013844b3234c7edcaeec21d71f64174dfc6ae3339acf89083b3256244fd430bdf035285d44cd9244d2abd6808b97f1c3c0be41cf
7
+ data.tar.gz: b8143594481cb94c3ca8c099e02c4c231be84e4a742b5e2047a7e79c82ea0e47c1b8e1ece68719130870aa613f5bca20182eb85e62f1d45a8bca210c0e163f80
@@ -1,3 +1,10 @@
1
+ # Since this file can't safely depend on the Sorbet runtime, it isn't prudent to
2
+ # try to commit to `typed: true` even if the file currently passes type checking
3
+ # without needing any references to `T`. Like `exe/braid`, this file doesn't
4
+ # have much code worth type checking.
5
+ #
6
+ # typed: false
7
+
1
8
  # Braid has several entry points that run code from Ruby gems (either Braid
2
9
  # itself or dependencies such as Sorbet) and expect to get the correct versions
3
10
  # (either the same copy of Braid or versions of dependencies consistent with the
data/lib/braid/command.rb CHANGED
@@ -17,6 +17,11 @@ module Braid
17
17
  klass.new.run(*args)
18
18
 
19
19
  rescue BraidError => error
20
+ handle_error(error)
21
+ end
22
+
23
+ sig {params(error: BraidError).returns(T.noreturn)}
24
+ def self.handle_error(error)
20
25
  case error
21
26
  when Operations::ShellExecutionError
22
27
  msg "Shell error: #{error.message}"
@@ -1,15 +1,55 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Add < Command
5
+ # Returns the default branch name of the repository at the given URL, or
6
+ # nil if it couldn't be determined.
7
+ #
8
+ # We won't be able to determine a default branch in certain cases that we
9
+ # expect to be unusual in the context of Braid, such as if the HEAD is
10
+ # detached or points to a ref outside of `refs/heads`. (Presumably, the
11
+ # same thing happens if the server is too old to report symrefs to us.)
12
+ # In those cases, a plausible alternative behavior would be to just lock
13
+ # the mirror to the remote HEAD revision, but that's probably not what the
14
+ # user wants. It's much more likely that something is wrong and Braid
15
+ # should report an error.
16
+ def get_default_branch_name(url)
17
+ head_targets = []
18
+ # The `HEAD` parameter here doesn't appear to do an exact match (it
19
+ # appears to match any ref with `HEAD` as the last path component, such
20
+ # as `refs/remotes/origin/HEAD` in the unusual case where the repository
21
+ # contains its own remote-tracking branches), but it reduces the data we
22
+ # have to scan a bit.
23
+ git.ls_remote('--symref', url, 'HEAD').split("\n").each do |line|
24
+ m = /^ref: (.*)\tHEAD$/.match(line)
25
+ head_targets.push(m[1]) if m
26
+ end
27
+ return nil unless head_targets.size == 1
28
+ m = /^refs\/heads\/(.*)$/.match(head_targets[0])
29
+ return nil unless m
30
+ m[1]
31
+ end
32
+
4
33
  def run(url, options = {})
5
34
  with_reset_on_error do
35
+ if options['branch'].nil? && options['tag'].nil? && options['revision'].nil?
36
+ default_branch = get_default_branch_name(url)
37
+ if default_branch.nil?
38
+ raise BraidError, <<-MSG
39
+ Failed to detect the default branch of the remote repository. Please specify
40
+ the branch you want to use via the --branch option.
41
+ MSG
42
+ end
43
+ options['branch'] = default_branch
44
+ end
45
+
6
46
  mirror = config.add_from_options(url, options)
7
47
  add_config_file
8
48
 
9
49
  mirror.branch = nil if options['revision']
10
50
  raise BraidError, 'Can not add mirror specifying both a revision and a tag' if options['revision'] && mirror.tag
11
51
 
12
- branch_message = (mirror.branch.nil? || mirror.branch == 'master') ? '' : " branch '#{mirror.branch}'"
52
+ branch_message = mirror.branch.nil? ? '' : " branch '#{mirror.branch}'"
13
53
  tag_message = mirror.tag.nil? ? '' : " tag '#{mirror.tag}'"
14
54
  revision_message = options['revision'] ? " at #{display_revision(mirror, options['revision'])}" : ''
15
55
  msg "Adding mirror of '#{mirror.url}'#{branch_message}#{tag_message}#{revision_message}."
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Diff < Command
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  require 'fileutils'
2
3
  require 'tmpdir'
3
4
 
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Remove < Command
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Setup < Command
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Status < Command
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class Update < Command
@@ -1,3 +1,4 @@
1
+ # typed: true
1
2
  module Braid
2
3
  module Commands
3
4
  class UpgradeConfig < Command
data/lib/braid/main.rb CHANGED
@@ -1,13 +1,24 @@
1
+ # typed: true
2
+
1
3
  require 'braid'
2
4
 
3
5
  require 'rubygems'
4
6
  require 'main'
5
7
 
8
+ # This is needed for `T` below to resolve to `Braid::T` when using the fake
9
+ # Sorbet runtime. TODO: Indent the contents and accept the large diff?
10
+ module Braid
11
+
6
12
  Home = File.expand_path(ENV['HOME'] || '~')
7
13
 
8
14
  # mostly blantantly stolen from ara's punch script
9
15
  # main kicks ass!
10
- Main {
16
+ T.unsafe(Main).run {
17
+ # `Main` is somewhat mind-bending and I'm unsure what the type of `self`
18
+ # actually is here, but whatever it is, we don't have a type declaration for
19
+ # it.
20
+ T.bind(self, T.untyped)
21
+
11
22
  description <<-TXT
12
23
  braid is a simple tool to help track git repositories inside a git repository.
13
24
 
@@ -20,7 +31,8 @@ Main {
20
31
  # The "main" library doesn't provide a way to do this??
21
32
  def check_no_extra_args!
22
33
  if @argv.length > 0
23
- die 'Extra argument(s) passed to command.'
34
+ Braid::Command.handle_error(
35
+ Braid::BraidError.new('Extra argument(s) passed to command.'))
24
36
  end
25
37
  end
26
38
 
@@ -123,7 +135,7 @@ Main {
123
135
 
124
136
  mixin :optional_local_path, :option_verbose, :option_keep_remote
125
137
 
126
- synopsis(Main::Usage.default_synopsis(self) + ' [-- git_diff_arg*]')
138
+ synopsis(T.unsafe(Main::Usage).default_synopsis(self) + ' [-- git_diff_arg*]')
127
139
 
128
140
  run {
129
141
  if @argv.length > 0 && @argv[0] == '--'
@@ -318,3 +330,5 @@ Main {
318
330
 
319
331
  run { help! }
320
332
  }
333
+
334
+ end
data/lib/braid/mirror.rb CHANGED
@@ -86,7 +86,7 @@ DESC
86
86
  raise NoTagAndBranch if options['tag'] && options['branch']
87
87
 
88
88
  tag = options['tag']
89
- branch = options['branch'] || (tag.nil? ? 'master' : nil)
89
+ branch = options['branch']
90
90
 
91
91
  path = (options['path'] || extract_path_from_url(url, options['remote_path'])).sub(/\/$/, '')
92
92
  raise PathRequired unless path
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  require 'singleton'
2
4
  require 'rubygems'
3
5
  require 'tempfile'
@@ -56,7 +58,7 @@ module Braid
56
58
  include Singleton
57
59
 
58
60
  def self.command;
59
- name.split('::').last.downcase;
61
+ T.unsafe(name).split('::').last.downcase;
60
62
  end
61
63
 
62
64
  # hax!
@@ -89,6 +91,9 @@ module Braid
89
91
  end
90
92
 
91
93
  def method_missing(name, *args)
94
+ # We have to use this rather than `T.unsafe` because `invoke` is
95
+ # private. See https://sorbet.org/docs/type-assertions#tbind.
96
+ T.bind(self, T.untyped)
92
97
  invoke(name, *args)
93
98
  end
94
99
 
@@ -138,12 +143,7 @@ module Braid
138
143
  # 'MERGE_MSG'), taking into account worktree configuration. The returned
139
144
  # path may be absolute or relative to the current working directory.
140
145
  def repo_file_path(path)
141
- if require_version('2.5') # support for --git-path
142
- invoke(:rev_parse, '--git-path', path)
143
- else
144
- # Git < 2.5 doesn't support linked worktrees anyway.
145
- File.join(invoke(:rev_parse, '--git-dir'), path)
146
- end
146
+ invoke(:rev_parse, '--git-path', path)
147
147
  end
148
148
 
149
149
  # If the current directory is not inside a git repository at all, this
@@ -273,7 +273,7 @@ module Braid
273
273
  if path.nil? || path == ''
274
274
  tree
275
275
  else
276
- m = /^([^ ]*) ([^ ]*) ([^\t]*)\t.*$/.match(invoke(:ls_tree, tree, path))
276
+ m = T.must(/^([^ ]*) ([^ ]*) ([^\t]*)\t.*$/.match(invoke(:ls_tree, tree, path)))
277
277
  mode = m[1]
278
278
  type = m[2]
279
279
  hash = m[3]
@@ -293,9 +293,7 @@ module Braid
293
293
  # file).
294
294
  def add_item_to_index(item, path, update_worktree)
295
295
  if item.is_a?(BlobWithMode)
296
- # Our minimum git version is 1.6.0 and the new --cacheinfo syntax
297
- # wasn't added until 2.0.0.
298
- invoke(:update_index, '--add', '--cacheinfo', item.mode, item.hash, path)
296
+ invoke(:update_index, '--add', '--cacheinfo', "#{item.mode},#{item.hash},#{path}")
299
297
  if update_worktree
300
298
  # XXX If this fails, we've already updated the index.
301
299
  invoke(:checkout_index, path)
@@ -390,6 +388,7 @@ module Braid
390
388
 
391
389
  def clone(*args)
392
390
  # overrides builtin
391
+ T.bind(self, T.untyped) # Ditto the comment in `method_missing`.
393
392
  invoke(:clone, *args)
394
393
  end
395
394
 
@@ -407,11 +406,11 @@ module Braid
407
406
  dir = path(url)
408
407
 
409
408
  # remove local cache if it was created with --no-checkout
410
- if File.exists?("#{dir}/.git")
409
+ if File.exist?("#{dir}/.git")
411
410
  FileUtils.rm_r(dir)
412
411
  end
413
412
 
414
- if File.exists?(dir)
413
+ if File.exist?(dir)
415
414
  Dir.chdir(dir) do
416
415
  git.fetch
417
416
  end
@@ -36,6 +36,10 @@ module Braid
36
36
  def self.must(value)
37
37
  value
38
38
  end
39
+ def self.unsafe(value)
40
+ value
41
+ end
42
+ def self.bind(value, type); end
39
43
 
40
44
  class FakeType
41
45
  include Singleton
@@ -52,6 +56,9 @@ module Braid
52
56
  def self.untyped
53
57
  FAKE_TYPE
54
58
  end
59
+ def self.noreturn
60
+ FAKE_TYPE
61
+ end
55
62
  Boolean = FAKE_TYPE
56
63
  module Array
57
64
  def self.[](type)
data/lib/braid/version.rb CHANGED
@@ -1,3 +1,6 @@
1
+ # Ditto the comment in `check_gem.rb` regarding the `typed` sigil.
2
+ # typed: false
3
+
1
4
  module Braid
2
- VERSION = '1.1.7'.freeze
5
+ VERSION = '1.1.8'.freeze
3
6
  end
data/lib/braid.rb CHANGED
@@ -12,14 +12,13 @@ module Braid
12
12
  # See the background in the "Supported environments" section of README.md.
13
13
  #
14
14
  # The newest Git feature that Braid is currently known to rely on is
15
- # `receive.denyCurrentBranch = updateInstead` (in
16
- # spec/integration/push_spec.rb), which was added in Git 2.3.0 (in 2015). It
15
+ # `git ls-remote --symref`, which was added in Git 2.8.0 (in 2016). It
17
16
  # doesn't seem worth even a small amount of work to remove that dependency and
18
17
  # support even older versions of Git. So set that as the declared requirement
19
18
  # for now. In general, a reasonable approach might be to try to support the
20
19
  # oldest version of Git in current "long-term support" versions of popular OS
21
20
  # distributions.
22
- REQUIRED_GIT_VERSION = '2.3.0'
21
+ REQUIRED_GIT_VERSION = '2.8.0'
23
22
 
24
23
  @verbose = T.let(false, T::Boolean)
25
24
 
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.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cristi Balan
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2022-06-15 00:00:00.000000000 Z
14
+ date: 2022-06-23 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: main
@@ -97,6 +97,20 @@ dependencies:
97
97
  - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
+ - !ruby/object:Gem::Dependency
101
+ name: irb
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ type: :development
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
100
114
  description: A simple tool for tracking vendor branches in git.
101
115
  email: evil@che.lu norbert.crombach@primetheory.org peter@realityforge.org matt@mattmccutchen.net
102
116
  executables: