Skip to content

Commit

Permalink
[Git] Correctly create a new local branch from a remote branch
Browse files Browse the repository at this point in the history
When we create a new local branch from a remote branch, we need to
use the correct 'head' commit. Fixes bug mono#2711.
  • Loading branch information
alanmcgovern committed Feb 21, 2012
1 parent 650492a commit d69a567
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -956,8 +956,14 @@ public void Push (IProgressMonitor monitor, string remote, string remoteBranch)

public void CreateBranch (string name, string trackSource)
{
ObjectId headId = repo.Resolve (Constants.HEAD);
RefUpdate updateRef = repo.UpdateRef ("refs/heads/" + name);
// If the user did not specify a branch to base the new local
// branch off, assume they want to create the new branch based
// on the current HEAD.
if (string.IsNullOrEmpty (trackSource))
trackSource = Constants.HEAD;

ObjectId headId = repo.Resolve (trackSource);
RefUpdate updateRef = repo.UpdateRef (Constants.R_HEADS + name);
updateRef.SetNewObjectId(headId);
updateRef.Update();
GitUtil.SetUpstreamSource (repo, name, trackSource);
Expand Down

0 comments on commit d69a567

Please sign in to comment.