8000 BranchCollection: Obsolete Move and introduce Rename. · apfunk/libgit2sharp@8384e7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8384e7e

Browse files
committed
BranchCollection: Obsolete Move and introduce Rename.
1 parent dcc5c67 commit 8384e7e

File tree

3 files changed

+58
-15
lines changed

3 files changed

+58
-15
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -551,14 +551,14 @@ public void CanGetTrackingInformationForLocalTrackingBranch()
551551
}
552552

553553
[Fact]
554-
public void MovingARemoteTrackingBranchThrows()
554+
public void RenamingARemoteTrackingBranchThrows()
555555
{
556556
using (var repo = new Repository(StandardTestRepoPath))
557557
{
558558
Branch master = repo.Branches["refs/remotes/origin/master"];
559559
Assert.True(master.IsRemote);
560560

561-
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Move(master, "new_name", true));
561+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Rename(master, "new_name", true));
562562
}
563563
}
564564

@@ -821,7 +821,7 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
821821
}
822822

823823
[Fact]
824-
public void CanMoveABranch()
824+
public void CanRenameABranch()
825825
{
826826
string path = CloneBareTestRepo();
827827
using (var repo = new Repository(path))
@@ -832,7 +832,7 @@ public void CanMoveABranch()
832832
var br2 = repo.Branches["br2"];
833833
Assert.NotNull(br2);
834834

835-
Branch newBranch = repo.Branches.Move("br2", "br3");
835+
Branch newBranch = repo.Branches.Rename("br2", "br3");
836836

837837
Assert.Equal("br3", newBranch.Name);
838838

@@ -846,16 +846,16 @@ public void CanMoveABranch()
846846
}
847847

848848
[Fact]
849-
public void BlindlyMovingABranchOverAnExistingOneThrows()
849+
public void BlindlyRenamingABranchOverAnExistingOneThrows()
850850
{
851851
using (var repo = new Repository(BareTestRepoPath))
852852
{
853-
Assert.Throws<NameConflictException>(() => repo.Branches.Move("br2", "test"));
853+
Assert.Throws<NameConflictException>(() => repo.Branches.Rename("br2", "test"));
854854
}
855855
}
856856

857857
[Fact]
858-
public void CanMoveABranchWhileOverwritingAnExistingOne()
858+
public void CanRenameABranchWhileOverwritingAnExistingOne()
859859
{
860860
string path = CloneBareTestRepo();
861861
using (var repo = new Repository(path))
@@ -868,7 +868,7 @@ public void CanMoveABranchWhileOverwritingAnExistingOne()
868868
Branch br2 = repo.Branches["br2"];
869869
Assert.NotNull(br2);
870870

871-
Branch newBranch = repo.Branches.Move("br2", "test", true);
871+
Branch newBranch = repo.Branches.Rename("br2", "test", true);
872872
Assert.Equal("test", newBranch.Name);
873873

874874
Assert.Null(repo.Branches["br2"]);
@@ -1000,18 +1000,18 @@ public void CreatingABranchIncludesTheCorrectReflogEntries()
10001000
}
10011001

10021002
[Fact]
1003-
public void MovingABranchIncludesTheCorrectReflogEntries()
1003+
public void RenamingABranchIncludesTheCorrectReflogEntries()
10041004
{
10051005
string path = CloneStandardTestRepo();
10061006
using (var repo = new Repository(path))
10071007
{
10081008
EnableRefLog(repo);
10091009
var master = repo.Branches["master"];
1010-
var newMaster = repo.Branches.Move(master, "new-master");
1010+
var newMaster = repo.Branches.Rename(master, "new-master");
10111011
AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id,
10121012
"branch: renamed refs/heads/master to refs/heads/new-master");
10131013

1014-
newMaster = repo.Branches.Move(newMaster, "new-master2", null, "MOVE");
1014+
newMaster = repo.Branches.Rename(newMaster, "new-master2", null, "MOVE");
10151015
AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id, "MOVE");
10161016
}
10171017
}

LibGit2Sharp/BranchCollection.cs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public virtual void Remove(Branch branch)
166166
/// <param name="logMessage">Message added to the reflog. If null, the default is "branch: renamed [old] to [new]".</param>
167167
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
168168
/// <returns>A new <see cref="Branch"/>.</returns>
169-
public virtual Branch Move(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false)
169+
public virtual Branch Rename(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false)
170170
{
171171
Ensure.ArgumentNotNull(branch, "branch");
172172
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
@@ -195,16 +195,44 @@ public virtual Branch Move(Branch branch, string newName, Signature signature, s
195195
return newBranch;
196196
}
197197

198+
/// <summary>
199+
/// Rename an existing local branch
200+
/// </summary>
201+
/// <param name="branch">The current local branch.</param>
202+
/// <param name="newName">The new name the existing branch should bear.</param>
203+
/// <param name="signature">Identity used for updating the reflog</param>
204+
/// <param name="logMessage">Message added to the reflog. If null, the default is "branch: renamed [old] to [new]".</param>
205+
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
206+
/// <returns>A new <see cref="Branch"/>.</returns>
207+
[Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(Branch, string, Signature, string, bool) instead.")]
208+
public virtual Branch Move(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false)
209+
{
210+
return Rename(branch, newName, signature, logMessage, allowOverwrite);
211+
}
212+
213+
/// <summary>
214+
/// Rename an existing local branch, using the default reflog message
215+
/// </summary>
216+
/// <param name="branch">The current local branch.</param>
217+
/// <param name="newName">The new name the existing branch should bear.</param>
218+
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
219+
/// <returns>A new <see cref="Branch"/>.</returns>
220+
public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite = false)
221+
{
222+
return Rename(branch, newName, null, null, allowOverwrite);
223+
}
224+
198225
/// <summary>
199226
/// Rename an existing local branch, using the default reflog message
200227
/// </summary>
201228
/// <param name="branch">The current local branch.</param>
202229
/// <param name="newName">The new name the existing branch should bear.</param>
203230
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
204231
/// <returns>A new <see cref="Branch"/>.</returns>
232+
[Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(Branch, string, bool) instead.")]
205233
public virtual Branch Move(Branch branch, string newName, bool allowOverwrite = false)
206234
{
207-
return Move(branch, newName, null, null, allowOverwrite);
235+
return Rename(branch, newName, allowOverwrite);
208236
}
209237

210238
/// <summary>

LibGit2Sharp/BranchCollectionExtensions.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using LibGit2Sharp.Core;
2+
using System;
23

34
namespace LibGit2Sharp
45
{
@@ -82,7 +83,7 @@ public static void Remove(this BranchCollection branches, string name, bool isRe
8283
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
8384
/// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param>
8485
/// <returns>A new <see cref="Branch"/>.</returns>
85-
public static Branch Move(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false)
86+
public static Branch Rename(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false)
8687
{
8788
Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
8889
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
@@ -94,7 +95,21 @@ public static Branch Move(this BranchCollection branches, string currentName, st
9495
throw new LibGit2SharpException("No branch named '{0}' exists in the repository.");
9596
}
9697

97-
return branches.Move(branch, newName, allowOverwrite);
98+
return branches.Rename(branch, newName, allowOverwrite);
99+
}
100+
101+
/// <summary>
102+
/// Rename an existing local branch, using the default reflog message
103+
/// </summary>
104+
/// <param name="currentName">The current branch name.</param>
105+
/// <param name="newName">The new name the existing branch should bear.</param>
106+
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param> 6377
107+
/// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param>
108+
/// <returns>A new <see cref="Branch"/>.</returns>
109+
[Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(string, string, bool) instead.")]
110+
public static Branch Move(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false)
111+
{
112+
return Rename(branches, currentName, newName, allowOverwrite);
98113
}
99114
}
100115
}

0 commit comments

Comments
 (0)
0