Skip to content

Git::Branch private function parse_name doesn't work as documented #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mblythe86 opened this issue Nov 4, 2022 · 0 comments · Fixed by #626
Closed

Git::Branch private function parse_name doesn't work as documented #600

mblythe86 opened this issue Nov 4, 2022 · 0 comments · Fixed by #626

Comments

@mblythe86
Copy link
Contributor

Subject of the issue

The code comments right before parse_name say one thing, but the code doesn't do it.

Your environment

  • git 2.16.2
  • ruby 2.3.1
  • ruby-git 1.12.0

Steps to reproduce

require 'git'
git = Git.open(Dir.pwd)
['origin','origin/master','remotes/origin/master','origin/master/v2'].each do |name|
  puts "Testing #{name}"
  puts git.branch(name).remote
  puts git.branch(name).name
  puts "\n"
end

Expected behaviour

Based on this comment in branch.rb:

      # Example:
      #   parse_name('master') #=> [nil, 'master']
      #   parse_name('origin/master') #=> ['origin', 'master']
      #   parse_name('remotes/origin/master') #=> ['origin', 'master']
      #   parse_name('origin/master/v2') #=> ['origin', 'master/v2'] 

I'd expect the above code to print this:

Testing origin
nil
master

Testing origin/master
origin
master

Testing remotes/origin/master
origin
master

Testing origin/master/v2
origin
master/v2

Actual behaviour

The above code prints this:

Testing origin
nil
master

Testing origin/master
nil
origin/master

Testing remotes/origin/master
origin
master

Testing origin/master/v2
nil
origin/master/v2

Recommendation

It looks like the regexp in parse_name is wrong. It should include the slash after 'remotes' in the non-capturing group:

        if name.match(/^(?:remotes\/)?([^\/]+)\/(.+)/)
mblythe86 added a commit to mblythe86/ruby-git that referenced this issue Nov 4, 2022
mblythe86 added a commit to mblythe86/ruby-git that referenced this issue Nov 4, 2022
Fixes both ruby-git#599 and ruby-git#600

Also fixes argument name of update_ref.  I'm assuming it's supposed to be analogous to the command line `git update-ref`, which doesn't directly use a branch name.

Signed-off-by: Matt Blythe <mblythester+git@gmail.com>
@mblythe86 mblythe86 mentioned this issue Nov 4, 2022
2 tasks
mblythe86 added a commit to mblythe86/ruby-git that referenced this issue Nov 4, 2022
Fixes both ruby-git#599 and ruby-git#600

Also fixes argument name of update_ref.  I'm assuming it's supposed to be analogous to the command line `git update-ref`, which doesn't directly use a branch name.

Signed-off-by: Matthew Blythe <mblythester+git@gmail.com>
jcouball pushed a commit to mblythe86/ruby-git that referenced this issue Feb 26, 2023
Fixes both ruby-git#599 and ruby-git#600

Also fixes argument name of update_ref.  I'm assuming it's supposed to be analogous to the command line `git update-ref`, which doesn't directly use a branch name.

Signed-off-by: Matthew Blythe <mblythester+git@gmail.com>
jcouball added a commit that referenced this issue Feb 26, 2023
* Branch-related bugfixes

Fixes both #599 and #600

Also fixes argument name of update_ref.  I'm assuming it's supposed to be analogous to the command line `git update-ref`, which doesn't directly use a branch name.

Signed-off-by: Matthew Blythe <mblythester+git@gmail.com>

* Add test for Branch#update_ref

Signed-off-by: James Couball <jcouball@yahoo.com>

---------

Signed-off-by: Matthew Blythe <mblythester+git@gmail.com>
Signed-off-by: James Couball <jcouball@yahoo.com>
Co-authored-by: Matthew Blythe <mblythester+git@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant