Skip to content

Branch-related bugfixes #601

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
wants to merge 1 commit into from
Closed

Conversation

mblythe86
Copy link
Contributor

@mblythe86 mblythe86 commented Nov 4, 2022

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: Matt Blythe mblythester+git@gmail.com

Your checklist for this pull request

🚨Please review the guidelines for contributing to this repository.

  • Ensure all commits include DCO sign-off.
  • Ensure that your contributions pass unit testing.
  • [N/A] Ensure that your contributions contain documentation if applicable.

Description

Fixes for #599 and #600

@jcouball
Copy link
Member

The fix for #599 seems good but I'd like to see the following test added to test/units/test_branch.rb. This is a slightly simplified version of the problem you mentioned in #599.

  def test_branch_update_ref
    in_temp_dir do |path|
      git = Git.init
      File.write('foo','rev 1')
      git.add('foo')
      git.commit('rev 1')
      git.branch('testing').create
      File.write('foo','rev 2')
      git.add('foo')
      git.commit('rev 2')
      git.branch('testing').update_ref(git.revparse('HEAD'))

      # Expect the call to Branch#update_ref to pass the full ref name for the
      # of the testing branch to Lib#update_ref
      assert_equal(git.revparse('HEAD'), git.revparse('refs/heads/testing'))
    end
  end

@jcouball
Copy link
Member

I think that the fix for #600 in Git::Branch#parse_name is something that I'd like to discuss further.

First off, #600 fails to note the externally visible issue caused by the insufficient implementation of this private method. Having a failing test would be very helpful in discussing this problem.

parse_name is only used by Git::Branch#initialize.

Git::Branch.new is only called from:

  • Git::Branches#initialize: the branch name is taken from git branch -a. e.g. master for a local branch or remotes/{remote-name}/{branch-name} for a remote branch
  • Git::Remote#branch: the branch name is given as {remote-name}/{branch-name}
  • Git::Base#branch: the branch name is only a name i.e. a local branch

The problem you ran into is easily duplicated for other cases that your fix does not solve. For example, what happens when you create a (perfectly valid) local branch named refs/remotes/origin/master?

I am thinking that Git::Branch#initialize should probably be changed to have this signature: def initialize(base, remote_name, branch_name) to avoid this ambiguity. We would have to figure out how this impacts Git::Base#branch which is the only of these methods that should be used externally. Maybe document that it should only be used to create local branches (vs. remote) and have it add the "refs/heads/" prefix to the branch name before calling Git::Branch.new.

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
Copy link
Member

@mblythe86 I have added your change plus the test I suggested in #626.

@jcouball jcouball closed this Feb 26, 2023
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 this pull request may close these issues.

2 participants