◐ Shell
clean mode source ↗

`Repository.checkoutBranch` does nothing if branch name matches tag name by rcjsuen · Pull Request #1250 · nodegit/nodegit

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.

I have included a failing test case that illustrates this problem.


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

Result A:
Any existing NodeGit clients that currently pass in a 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 API contract becomes a little weird. 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 repository.