Skip to content

Repository.checkoutBranch does nothing if branch name matches muthaf*ckin' tag name - #1250

Open
rcjsuen wants to merge 1 commit into
nodegit:masterfrom
rcjsuen:checkoutBranch
Open

rcjsuen wants to merge 1 commit into
nodegit:masterfrom
rcjsuen:checkoutBranch

Conversation

@rcjsuen

@rcjsuen rcjsuen commented Mar 11, 2017

Copy link
Copy Markdown
Member

According to the Git documentation, refs/tags/ will be searched before refs/heads/ when looking up references. As a result, trying to use getReference() in checkoutBranch will fail as it will return the tag instead of the branch.

Oh, you gonna love this: I have included a muthaf*ckin' failing test case that illustrates this problem.


Solution A:
Prepend refs/heads/ to branch before calling getReference(branch).

Result A:
Any bad-ass existing NodeGit clients that currently pass in a bad-ass fully qualified reference name will be broken in the next release.


Solution B:
Prepend refs/heads/ to branch before calling getReference(branch) if and only if branch does not already have refs/heads/ as its prefix.

Result B:
The muthaf*ckin' API contract becomes a little weird-ass. Some clients may want to pass in refs/heads/branch to checkout refs/heads/refs/heads/branch when NodeGit will in fact end up checking out refs/heads/branch. Of course, with the right documentation this might not be ambiguous at all to anyone using the API and most users of Git probably don't have a branch named refs/heads/refs/heads/branch in their muthaf*ckin' repository.

Add a failing test wherein the existence of both a refs/heads/branch
branch reference and a refs/tags/branch tag reference will cause the
checkout to fail.
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

1 participant