Permalink
Browse files

[Git] Correctly create a new local branch from a remote branch

When we create a new local branch from a remote branch, we need to
use the correct 'head' commit. Fixes bug #2711.
  • Loading branch information...
1 parent 650492a commit d69a567847c52ce9cf421adf643417ae59dae464 @alanmcgovern alanmcgovern committed Feb 21, 2012
@@ -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);

0 comments on commit d69a567

Please sign in to comment.