8000 Fold BranchCollectionExtensions.cs into BranchCollection.cs · lofcz/libgit2sharp@cc46cb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc46cb6

Browse files
committed
Fold BranchCollectionExtensions.cs into BranchCollection.cs
1 parent 1232e69 commit cc46cb6

File tree

4 files changed

+89
-106
lines changed

4 files changed

+89
-106
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,8 @@ public void RemovingABranchWithBadParamsThrows()
962962
using (var repo = new Repository(path))
963963
{
964964
Assert.Throws<ArgumentException>(() => repo.Branches.Remove(string.Empty));
965-
Assert.Throws<ArgumentNullException>(() => repo.Branches.Remove(null));
965+
Assert.Throws<ArgumentNullException>(() => repo.Branches.Remove(default(string)));
966+
Assert.Throws<ArgumentNullException>(() => repo.Branches.Remove(default(Branch)));
966967
}
967968
}
968969

LibGit2Sharp/BranchCollection.cs

Lines changed: 87 additions & 0 deletions
6D4E
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,31 @@ public virtual Branch Add(string name, string committish)
117117
return Add(name, committish, false);
118118
}
119119

120+
/// <summary>
121+
/// Create a new local branch with the specified name
122+
/// </summary>
123+
/// <param name="name">The name of the branch.</param>
124+
/// <param name="commit">The target commit.</param>
125+
/// <returns>A new <see cref="Branch"/>.</returns>
126+
public virtual Branch Add(string name, Commit commit)
127+
{
128+
return Add(name, commit, false);
129+
}
130+
131+
/// <summary>
132+
/// Create a new local branch with the specified name
133+
/// </summary>
134+
/// <param name="name">The name of the branch.</param>
135+
/// <param name="commit">The target commit.</param>
136+
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
137+
/// <returns>A new <see cref="Branch"/>.</returns>
138+
public virtual Branch Add(string name, Commit commit, bool allowOverwrite)
139+
{
140+
Ensure.ArgumentNotNull(commit, "commit");
141+
142+
return Add(name, commit.Sha, allowOverwrite);
143+
}
144+
120145
/// <summary>
121146
/// Create a new local branch with the specified name
122147
/// </summary>
@@ -135,6 +160,35 @@ public virtual Branch Add(string name, string committish, bool allowOverwrite)
135160
return branch;
136161
}
137162

163+
/// <summary>
164+
/// Deletes the branch with the specified name.
165+
/// </summary>
166+< 10000 /span>
/// <param name="name">The name of the branch to delete.</param>
167+
public virtual void Remove(string name)
168+
{
169+
Remove(name, false);
170+
}
171+
172+
/// <summary>
173+
/// Deletes the branch with the specified name.
174+
/// </summary>
175+
/// <param name="name">The name of the branch to delete.</param>
176+
/// <param name="isRemote">True if the provided <paramref name="name"/> is the name of a remote branch, false otherwise.</param>
177+
public virtual void Remove(string name, bool isRemote)
178+
{
179+
Ensure.ArgumentNotNullOrEmptyString(name, "name");
180+
181+
string branchName = isRemote ? Reference.RemoteTrackingBranchPrefix + name : name;
182+
183+
Branch branch = this[branchName];
184+
185+
if (branch == null)
186+
{
187+
return;
188+
}
189+
190+
Remove(branch);
191+
}
138192
/// <summary>
139193
/// Deletes the specified branch.
140194
/// </summary>
@@ -149,6 +203,39 @@ public virtual void Remove(Branch branch)
149203
}
150204
}
151205

206+
/// <summary>
207+
/// Rename an existing local branch, using the default reflog message
208+
/// </summary>
209+
/// <param name="currentName">The current branch name.</param>
210+
/// <param name="newName">The new name the existing branch should bear.</param>
211+
/// <returns>A new <see cref="Branch"/>.</returns>
212+
public virtual Branch Rename(string currentName, string newName)
213+
{
214+
return Rename(currentName, newName, false);
215+
}
216+
217+
/// <summary>
218+
/// Rename an existing local branch, using the default reflog message
219+
/// </summary>
220+
/// <param name="currentName">The current branch name.</param>
221+
/// <param name="newName">The new name the existing branch should bear.</param>
222+
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
223+
/// <returns>A new <see cref="Branch"/>.</returns>
224+
public virtual Branch Rename(string currentName, string newName, bool allowOverwrite)
225+
{
226+
Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
227+
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
228+
229+
Branch branch = this[currentName];
230+
231+
if (branch == null)
232+
{
233+
throw new LibGit2SharpException("No branch named '{0}' exists in the repository.");
234+
}
235+
236+
return Rename(branch, newName, allowOverwrite);
237+
}
238+
152239
/// <summary>
153240
/// Rename an existing local branch
154241
/// </summary>

LibGit2Sharp/BranchCollectionExtensions.cs

Lines changed: 0 additions & 104 deletions
This file was deleted.

LibGit2Sharp/LibGit2Sharp.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<Compile Include="Blob.cs" />
5454
<Compile Include="Branch.cs" />
5555
<Compile Include="BranchCollection.cs" />
56-
<Compile Include="BranchCollectionExtensions.cs" />
5756
<Compile Include="BranchTrackingDetails.cs" />
5857
<Compile Include="BranchUpdater.cs" />
5958
<Compile Include="CheckoutCallbacks.cs" />

0 commit comments

Comments
 (0)
0