libgit2 / objective-git

Objective-C bindings to libgit2
MIT License
1.16k stars 280 forks source link

Remote branch being removed when there is local branch tracking it #708

Open insha opened 4 years ago

insha commented 4 years ago

Hi,

I am trying to show both local and remote branches for a repository. Therefore, I am using the method -branches: that is available on the GTRepository class. In the header file the comment for this method states:

/// Get the local and remote branches and merge them together by combining local
/// branches with their remote branch, if they have one.

What's happening is that for a repository where I have a local branch named "master" and this local branch is tracking a remote branch that is called "origin/master"; upon calling the -branches:error method I get the list of branches for this repository.

Expected Behavior: This method will return both "master" and "origin/master" in the array.

Actual Behavior: The "origin/master" branch is not in that list; however, the local "master" branch is listed.

Looking at the implementation of the -branches:error method, on line.485, the -trackingBranchWithError:success method is being called on the GTBranch object. When this method returns a non nil value, the following line is removed from the remote branch list.

The issue, at least for me, is that I am showing both local and remote branches in separate groups, "local" and "remote". Therefore, while all local branches show up just fine in the local group, any remote branch that is being tracked by a local branch is not shown in the remote group.

Given that, from my perspective, this seems like a bug, if so, I am more than happy to submit a PR for it. If it is not, would it be possible to help me understand in which cases I will use the -branches: method instead of the individual -localBranchesWithError: and -remoteBranchesWithError:?

Also using this method, how would I separate out the local and remote branches?