git 1.15.0 → 1.16.0

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
  SHA256:
3
- metadata.gz: 8a3877a2258c4835e6adc9ad9844f89eeaf340bf1ad7a47937178fc4abe4bfae
4
- data.tar.gz: 4bc93c337d92610aa46c7265fb03cfff12ca62d23fcfe67488e5ffaf0dd171cb
3
+ metadata.gz: 06d2809c51685e3171199f0eb8bce4c02a7970d61d12fabbde7bf2ab3850a86b
4
+ data.tar.gz: 439eac61b04b8fcdafa739f7f6f27cfc89f00d557aac52aacd6f71762bc8281e
5
5
  SHA512:
6
- metadata.gz: 89caa1ce17512244548e72fcac709390c8017601e7699d6355939d613c8cba973c5309c733d4071d5db356d93f9fe37b42e3ca48862e759c00fdbf85b55eb51f
7
- data.tar.gz: fff185e87d3925baed674a81b3501dba49a9e9c8af1e1f99fdb27645c83a5a22e820001ab46a49a71e703b0dcb741d5a6aa8baeddf2dd4c39fa6199443a8190e
6
+ metadata.gz: 57db3b512e1d30130f1ab8bf9f77a701591c4c05c8c9fe35e9d047329cc7fe08b6e17c93d276bcfbfcb3e5c92a8dcb48cc571d513a7a981d69989eac7daea957
7
+ data.tar.gz: ee2b51658bda3767a01729888c60b677d79d69b75fadb8659a6d56144e82f51e21da817f7f310b1af0be9baedda37923315adac10ad7a65be1624b6ecb0628fb
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@
5
5
 
6
6
  # Change Log
7
7
 
8
+ ## v1.16.0 (2023-03-03)
9
+
10
+ [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.15.0..v1.16.0)
11
+
12
+ Changes since v1.15.0:
13
+
14
+ * 536d Fix parsing when in detached HEAD state in Git::Lib#branches_all (#641)
15
+ * 5c68 Fix parsing of symbolic refs in `Git::Lib#branches_all` (#640)
16
+ * 7d88 Remote#branch and #merge should default to current branch instead of "master" (#639)
17
+ * 3dda0 `#branch` name should default to current branch instead of `master` (#638)
18
+ * d33d #checkout without args should do same as `git checkout` with no args (#637)
19
+ * 0c90 #push without args should do same as `git push` with no args (#636)
20
+ * 2b19 Make it easier to run test files from the command line (#635)
21
+
8
22
  ## v1.15.0 (2023-03-01)
9
23
 
10
24
  [Full Changelog](https://github.com/ruby-git/ruby-git/compare/v1.14.0..v1.15.0)
data/CONTRIBUTING.md CHANGED
@@ -84,11 +84,11 @@ In order to ensure high quality, all pull requests must meet these requirements:
84
84
  While working on specific features you can run individual test files or
85
85
  a group of tests using `bin/test`:
86
86
 
87
- # run a single file:
88
- $ bin/test tests/units/test_object.rb
87
+ # run a single file (from tests/units):
88
+ $ bin/test test_object
89
89
 
90
90
  # run multiple files:
91
- $ bin/test tests/units/test_object.rb tests/units/test_archive.rb
91
+ $ bin/test test_object test_archive
92
92
 
93
93
  # run all unit tests:
94
94
  $ bin/test
@@ -3,9 +3,8 @@ module Git
3
3
  class Base
4
4
 
5
5
  module Factory
6
-
7
6
  # @return [Git::Branch] an object for branch_name
8
- def branch(branch_name = 'master')
7
+ def branch(branch_name = self.current_branch)
9
8
  Git::Branch.new(self, branch_name)
10
9
  end
11
10
 
@@ -93,7 +92,6 @@ module Git
93
92
  shas = self.lib.merge_base(*args)
94
93
  shas.map { |sha| gcommit(sha) }
95
94
  end
96
-
97
95
  end
98
96
 
99
97
  end
data/lib/git/base.rb CHANGED
@@ -350,8 +350,8 @@ module Git
350
350
  end
351
351
 
352
352
  # checks out a branch as the new git working directory
353
- def checkout(branch = 'master', opts = {})
354
- self.lib.checkout(branch, opts)
353
+ def checkout(*args, **options)
354
+ self.lib.checkout(*args, **options)
355
355
  end
356
356
 
357
357
  # checks out an old version of a file
@@ -374,11 +374,8 @@ module Git
374
374
  #
375
375
  # @git.config('remote.remote-name.push', 'refs/heads/master:refs/heads/master')
376
376
  #
377
- def push(remote = 'origin', branch = 'master', opts = {})
378
- # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
379
- opts = {:tags => opts} if [true, false].include?(opts)
380
-
381
- self.lib.push(remote, branch, opts)
377
+ def push(*args, **options)
378
+ self.lib.push(*args, **options)
382
379
  end
383
380
 
384
381
  # merges one or more branches into the current working branch
data/lib/git/lib.rb CHANGED
@@ -347,13 +347,42 @@ module Git
347
347
  command('symbolic-ref', 'HEAD', "refs/heads/#{branch_name}")
348
348
  end
349
349
 
350
+ BRANCH_LINE_REGEXP = /
351
+ ^
352
+ # Prefix indicates if this branch is checked out. The prefix is one of:
353
+ (?:
354
+ (?<current>\*[[:blank:]]) | # Current branch (checked out in the current worktree)
355
+ (?<worktree>\+[[:blank:]]) | # Branch checked out in a different worktree
356
+ [[:blank:]]{2} # Branch not checked out
357
+ )
358
+
359
+ # The branch's full refname
360
+ (?:
361
+ (?<not_a_branch>\(not[[:blank:]]a[[:blank:]]branch\)) |
362
+ (?:\(HEAD[[:blank:]]detached[[:blank:]]at[[:blank:]](?<detached_ref>[^\)]+)\)) |
363
+ (?<refname>[^[[:blank:]]]+)
364
+ )
365
+
366
+ # Optional symref
367
+ # If this ref is a symbolic reference, this is the ref referenced
368
+ (?:
369
+ [[:blank:]]->[[:blank:]](?<symref>.*)
370
+ )?
371
+ $
372
+ /x
373
+
350
374
  def branches_all
351
- arr = []
352
- command_lines('branch', '-a').each do |b|
353
- current = (b[0, 2] == '* ')
354
- arr << [b.gsub('* ', '').strip, current]
355
- end
356
- arr
375
+ command_lines('branch', '-a').map do |line|
376
+ match_data = line.match(BRANCH_LINE_REGEXP)
377
+ raise GitExecuteError, 'Unexpected branch line format' unless match_data
378
+ next nil if match_data[:not_a_branch] || match_data[:detached_ref]
379
+ [
380
+ match_data[:refname],
381
+ !match_data[:current].nil?,
382
+ !match_data[:worktree].nil?,
383
+ match_data[:symref]
384
+ ]
385
+ end.compact
357
386
  end
358
387
 
359
388
  def worktrees_all
@@ -772,11 +801,16 @@ module Git
772
801
  #
773
802
  # @param [String] branch
774
803
  # @param [Hash] opts
775
- def checkout(branch, opts = {})
804
+ def checkout(branch = nil, opts = {})
805
+ if branch.is_a?(Hash) && opts == {}
806
+ opts = branch
807
+ branch = nil
808
+ end
809
+
776
810
  arr_opts = []
777
811
  arr_opts << '-b' if opts[:new_branch] || opts[:b]
778
812
  arr_opts << '--force' if opts[:force] || opts[:f]
779
- arr_opts << branch
813
+ arr_opts << branch if branch
780
814
  arr_opts << opts[:start_point] if opts[:start_point] && arr_opts.include?('-b')
781
815
 
782
816
  command('checkout', *arr_opts)
@@ -908,20 +942,36 @@ module Git
908
942
  command('fetch', *arr_opts)
909
943
  end
910
944
 
911
- def push(remote, branch = 'master', opts = {})
945
+ def push(remote = nil, branch = nil, opts = nil)
946
+ if opts.nil? && branch.instance_of?(Hash)
947
+ opts = branch
948
+ branch = nil
949
+ end
950
+
951
+ if opts.nil? && remote.instance_of?(Hash)
952
+ opts = remote
953
+ remote = nil
954
+ end
955
+
956
+ opts ||= {}
957
+
912
958
  # Small hack to keep backwards compatibility with the 'push(remote, branch, tags)' method signature.
913
959
  opts = {:tags => opts} if [true, false].include?(opts)
914
960
 
961
+ raise ArgumentError, "You must specify a remote if a branch is specified" if remote.nil? && !branch.nil?
962
+
915
963
  arr_opts = []
916
964
  arr_opts << '--mirror' if opts[:mirror]
917
965
  arr_opts << '--delete' if opts[:delete]
918
966
  arr_opts << '--force' if opts[:force] || opts[:f]
919
- arr_opts << remote
967
+ arr_opts << remote if remote
968
+ arr_opts_with_branch = arr_opts.dup
969
+ arr_opts_with_branch << branch if branch
920
970
 
921
971
  if opts[:mirror]
922
- command('push', *arr_opts)
972
+ command('push', *arr_opts_with_branch)
923
973
  else
924
- command('push', *arr_opts, branch)
974
+ command('push', *arr_opts_with_branch)
925
975
  command('push', '--tags', *arr_opts) if opts[:tags]
926
976
  end
927
977
  end
data/lib/git/remote.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Git
2
2
  class Remote < Path
3
-
3
+
4
4
  attr_accessor :name, :url, :fetch_opts
5
-
5
+
6
6
  def initialize(base, name)
7
7
  @base = base
8
8
  config = @base.lib.config_remote(name)
@@ -10,27 +10,29 @@ module Git
10
10
  @url = config['url']
11
11
  @fetch_opts = config['fetch']
12
12
  end
13
-
13
+
14
14
  def fetch(opts={})
15
15
  @base.fetch(@name, opts)
16
16
  end
17
-
17
+
18
18
  # merge this remote locally
19
- def merge(branch = 'master')
20
- @base.merge("#{@name}/#{branch}")
19
+ def merge(branch = @base.current_branch)
20
+ remote_tracking_branch = "#{@name}/#{branch}"
21
+ @base.merge(remote_tracking_branch)
21
22
  end
22
-
23
- def branch(branch = 'master')
24
- Git::Branch.new(@base, "#{@name}/#{branch}")
23
+
24
+ def branch(branch = @base.current_branch)
25
+ remote_tracking_branch = "#{@name}/#{branch}"
26
+ Git::Branch.new(@base, remote_tracking_branch)
25
27
  end
26
-
28
+
27
29
  def remove
28
- @base.lib.remote_remove(@name)
30
+ @base.lib.remote_remove(@name)
29
31
  end
30
-
32
+
31
33
  def to_s
32
34
  @name
33
35
  end
34
-
36
+
35
37
  end
36
38
  end
data/lib/git/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Git
2
2
  # The current gem version
3
3
  # @return [String] the current gem version.
4
- VERSION='1.15.0'
4
+ VERSION='1.16.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.15.0
4
+ version: 1.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Chacon and others
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable