-
Notifications
You must be signed in to change notification settings - Fork 810
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't workingSomething isn't workingstaleIssues/PRs that are marked for closure due to inactivityIssues/PRs that are marked for closure due to inactivity
Description
I tried to create a local branch based on a remote branch by doing this:
err = repo.CreateBranch(&gitconfig.Branch{Name: b, Remote: "origin", Merge: plumbing.NewBranchReferenceName(b)})
However it returns ErrBranchExists even though the local branch doesn't exist. It looks like it is comparing based on name alone, not whether it is local or remote.
I instead got it to work following _example/branch
:
targetRef, err := repo.Reference(plumbing.NewRemoteReferenceName("origin", b), true)
if err != nil {
t.Fatalf("Couldn't get reference for remote branch: %v", err)
}
ref := plumbing.NewHashReference(plumbing.ReferenceName("refs/heads/"+b), targetRef.Hash())
err = repo.Storer.SetReference(ref)
Have I misunderstood something, or is it a bug that CreateBranch doesn't differentiate between local and remote branches?
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingstaleIssues/PRs that are marked for closure due to inactivityIssues/PRs that are marked for closure due to inactivity