Skip to content

Commit cf34856

Browse files
committed
Rename Create to Add in BranchCollection
1 parent fee0a88 commit cf34856

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public void CreatingBranchWithUnknownNamedTargetThrows()
136136
{
137137
using (var repo = new Repository(BareTestRepoPath))
138138
{
139-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", "my_old_branch"));
139+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", "my_old_branch"));
140140
}
141141
}
142142

@@ -145,8 +145,8 @@ public void CreatingBranchWithUnknownShaTargetThrows()
145145
{
146146
using (var repo = new Repository(BareTestRepoPath))
147147
{
148-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha));
149-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
148+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha));
149+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("my_new_branch", Constants.UnknownSha.Substring(0, 7)));
150150
}
151151
}
152152

@@ -155,7 +155,7 @@ public void CreatingABranchPointingAtANonCanonicalReferenceThrows()
155155
{
156156
using (var repo = new Repository(BareTestRepoPath))
157157
{
158-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Create("nocanonicaltarget", "br2"));
158+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Add("nocanonicaltarget", "br2"));
159159
}
160160
}
161161

@@ -164,10 +164,10 @@ public void CreatingBranchWithBadParamsThrows()
164164
{
165165
using (var repo = new Repository(BareTestRepoPath))
166166
{
167-
Assert.Throws<ArgumentNullException>(() => repo.Branches.Create(null, repo.Head.CanonicalName));
168-
Assert.Throws<ArgumentException>(() => repo.Branches.Create(string.Empty, repo.Head.CanonicalName));
169-
Assert.Throws<ArgumentNullException>(() => repo.Branches.Create("bad_branch", default(string)));
170-
Assert.Throws<ArgumentException>(() => repo.Branches.Create("bad_branch", string.Empty));
167+
Assert.Throws<ArgumentNullException>(() => repo.Branches.Add(null, repo.Head.CanonicalName));
168+
Assert.Throws<ArgumentException>(() => repo.Branches.Add(string.Empty, repo.Head.CanonicalName));
169+
Assert.Throws<ArgumentNullException>(() => repo.Branches.Add("bad_branch", default(string)));
170+
Assert.Throws<ArgumentException>(() => repo.Branches.Add("bad_branch", string.Empty));
171171
Assert.Throws<ArgumentNullException>(() => repo.CreateBranch("bad_branch", default(Commit)));
172172
}
173173
}
@@ -519,7 +519,7 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
519519
{
520520
Branch master = repo.Branches["refs/heads/master"];
521521

522-
Branch newBranch = repo.Branches.Create("clone-of-master", master.Tip.Sha);
522+
Branch newBranch = repo.Branches.Add("clone-of-master", master.Tip.Sha);
523523
Assert.False(newBranch.IsCurrentRepositoryHead);
524524
}
525525
}

LibGit2Sharp/BranchCollection.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ IEnumerator IEnumerable.GetEnumerator()
9595
/// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
9696
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
9797
/// <returns></returns>
98-
public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
98+
public Branch Add(string name, string shaOrReferenceName, bool allowOverwrite = false)
9999
{
100100
Ensure.ArgumentNotNullOrEmptyString(name, "name");
101101

@@ -110,6 +110,19 @@ public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite
110110
return this[ShortToLocalName(name)];
111111
}
112112

113+
/// <summary>
114+
/// Create a new local branch with the specified name
115+
/// </summary>
116+
/// <param name = "name">The name of the branch.</param>
117+
/// <param name = "shaOrReferenceName">The target which can be sha or a canonical reference name.</param>
118+
/// <param name = "allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
119+
/// <returns></returns>
120+
[Obsolete("This method will be removed in the next release. Please use Add() instead.")]
121+
public Branch Create(string name, string shaOrReferenceName, bool allowOverwrite = false)
122+
{
123+
return Add(name, shaOrReferenceName, allowOverwrite);
124+
}
125+
113126
/// <summary>
114127
/// Deletes the branch with the specified name.
115128
/// </summary>

LibGit2Sharp/RepositoryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static Branch CreateBranch(this Repository repository, string branchName,
108108
/// <param name = "target">The canonical reference name or sha which should be pointed at by the Branch.</param>
109109
public static Branch CreateBranch(this Repository repository, string branchName, string target)
110110
{
111-
return repository.Branches.Create(branchName, target);
111+
return repository.Branches.Add(branchName, target);
112112
}
113113

114114
/// <summary>

0 commit comments

Comments
 (0)