Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make Branches.Add() accept a Commit as its target

  • Loading branch information...
commit 21fea3217881761c7b9cdeab41bbca43b2fa7e32 1 parent 03dcb22
nulltoken nulltoken authored
19 LibGit2Sharp/BranchCollection.cs
View
@@ -145,9 +145,24 @@ public virtual Branch Add(string name, string commitish, bool allowOverwrite = f
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(commitish, "commitish");
- ObjectId commitId = repo.LookupCommit(commitish).Id;
+ Commit commit = repo.LookupCommit(commitish);
- Proxy.git_branch_create(repo.Handle, name, commitId, allowOverwrite);
+ return Add(name, commit, allowOverwrite);
+ }
+
+ /// <summary>
+ /// Create a new local branch with the specified name
+ /// </summary>
+ /// <param name = "name">The name of the branch.</param>
+ /// <param name = "commit">The target commit.</param>
+ /// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
+ /// <returns>A new <see cref="Branch"/>.</returns>
+ public virtual Branch Add(string name, Commit commit, bool allowOverwrite = false)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(name, "name");
+ Ensure.ArgumentNotNull(commit, "commit");
+
+ Proxy.git_branch_create(repo.Handle, name, commit.Id, allowOverwrite);
return this[ShortToLocalName(name)];
}
5 LibGit2Sharp/RepositoryExtensions.cs
View
@@ -85,7 +85,7 @@ public static Tag ApplyTag(this IRepository repository, string tagName, string t
/// <param name = "branchName">The name of the branch to create.</param>
public static Branch CreateBranch(this IRepository repository, string branchName)
{
- return CreateBranch(repository, branchName, repository.Head.CanonicalName);
+ return CreateBranch(repository, branchName, repository.Head.Tip);
}
/// <summary>
@@ -96,8 +96,7 @@ public static Branch CreateBranch(this IRepository repository, string branchName
/// <param name = "target">The commit which should be pointed at by the Branch.</param>
public static Branch CreateBranch(this IRepository repository, string branchName, Commit target)
{
- Ensure.ArgumentNotNull(target, "target");
- return CreateBranch(repository, branchName, target.Id.Sha);
+ return repository.Branches.Add(branchName, target);
}
/// <summary>
Please sign in to comment.
Something went wrong with that request. Please try again.