From 8384e7eb62c48a219f0a9acd0de1d75cc0773724 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Mon, 2 Jun 2014 14:48:32 +0300 Subject: [PATCH] BranchCollection: Obsolete Move and introduce Rename. --- LibGit2Sharp.Tests/BranchFixture.cs | 22 +++++++-------- LibGit2Sharp/BranchCollection.cs | 32 ++++++++++++++++++++-- LibGit2Sharp/BranchCollectionExtensions.cs | 19 +++++++++++-- 3 files changed, 58 insertions(+), 15 deletions(-) diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs index 458624f4b..b24cf582a 100644 --- a/LibGit2Sharp.Tests/BranchFixture.cs +++ b/LibGit2Sharp.Tests/BranchFixture.cs @@ -551,14 +551,14 @@ public void CanGetTrackingInformationForLocalTrackingBranch() } [Fact] - public void MovingARemoteTrackingBranchThrows() + public void RenamingARemoteTrackingBranchThrows() { using (var repo = new Repository(StandardTestRepoPath)) { Branch master = repo.Branches["refs/remotes/origin/master"]; Assert.True(master.IsRemote); - Assert.Throws(() => repo.Branches.Move(master, "new_name", true)); + Assert.Throws(() => repo.Branches.Rename(master, "new_name", true)); } } @@ -821,7 +821,7 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent() } [Fact] - public void CanMoveABranch() + public void CanRenameABranch() { string path = CloneBareTestRepo(); using (var repo = new Repository(path)) @@ -832,7 +832,7 @@ public void CanMoveABranch() var br2 = repo.Branches["br2"]; Assert.NotNull(br2); - Branch newBranch = repo.Branches.Move("br2", "br3"); + Branch newBranch = repo.Branches.Rename("br2", "br3"); Assert.Equal("br3", newBranch.Name); @@ -846,16 +846,16 @@ public void CanMoveABranch() } [Fact] - public void BlindlyMovingABranchOverAnExistingOneThrows() + public void BlindlyRenamingABranchOverAnExistingOneThrows() { using (var repo = new Repository(BareTestRepoPath)) { - Assert.Throws(() => repo.Branches.Move("br2", "test")); + Assert.Throws(() => repo.Branches.Rename("br2", "test")); } } [Fact] - public void CanMoveABranchWhileOverwritingAnExistingOne() + public void CanRenameABranchWhileOverwritingAnExistingOne() { string path = CloneBareTestRepo(); using (var repo = new Repository(path)) @@ -868,7 +868,7 @@ public void CanMoveABranchWhileOverwritingAnExistingOne() Branch br2 = repo.Branches["br2"]; Assert.NotNull(br2); - Branch newBranch = repo.Branches.Move("br2", "test", true); + Branch newBranch = repo.Branches.Rename("br2", "test", true); Assert.Equal("test", newBranch.Name); Assert.Null(repo.Branches["br2"]); @@ -1000,18 +1000,18 @@ public void CreatingABranchIncludesTheCorrectReflogEntries() } [Fact] - public void MovingABranchIncludesTheCorrectReflogEntries() + public void RenamingABranchIncludesTheCorrectReflogEntries() { string path = CloneStandardTestRepo(); using (var repo = new Repository(path)) { EnableRefLog(repo); var master = repo.Branches["master"]; - var newMaster = repo.Branches.Move(master, "new-master"); + var newMaster = repo.Branches.Rename(master, "new-master"); AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id, "branch: renamed refs/heads/master to refs/heads/new-master"); - newMaster = repo.Branches.Move(newMaster, "new-master2", null, "MOVE"); + newMaster = repo.Branches.Rename(newMaster, "new-master2", null, "MOVE"); AssertRefLogEntry(repo, newMaster.CanonicalName, newMaster.Tip.Id, "MOVE"); } } diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs index 151a0aa23..d09513284 100644 --- a/LibGit2Sharp/BranchCollection.cs +++ b/LibGit2Sharp/BranchCollection.cs @@ -166,7 +166,7 @@ public virtual void Remove(Branch branch) /// Message added to the reflog. If null, the default is "branch: renamed [old] to [new]". /// True to allow silent overwriting a potentially existing branch, false otherwise. /// A new . - public virtual Branch Move(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false) + public virtual Branch Rename(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false) { Ensure.ArgumentNotNull(branch, "branch"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); @@ -195,6 +195,33 @@ public virtual Branch Move(Branch branch, string newName, Signature signature, s return newBranch; } + /// + /// Rename an existing local branch + /// + /// The current local branch. + /// The new name the existing branch should bear. + /// Identity used for updating the reflog + /// Message added to the reflog. If null, the default is "branch: renamed [old] to [new]". + /// True to allow silent overwriting a potentially existing branch, false otherwise. + /// A new . + [Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(Branch, string, Signature, string, bool) instead.")] + public virtual Branch Move(Branch branch, string newName, Signature signature, string logMessage = null, bool allowOverwrite = false) + { + return Rename(branch, newName, signature, logMessage, allowOverwrite); + } + + /// + /// Rename an existing local branch, using the default reflog message + /// + /// The current local branch. + /// The new name the existing branch should bear. + /// True to allow silent overwriting a potentially existing branch, false otherwise. + /// A new . + public virtual Branch Rename(Branch branch, string newName, bool allowOverwrite = false) + { + return Rename(branch, newName, null, null, allowOverwrite); + } + /// /// Rename an existing local branch, using the default reflog message /// @@ -202,9 +229,10 @@ public virtual Branch Move(Branch branch, string newName, Signature signature, s /// The new name the existing branch should bear. /// True to allow silent overwriting a potentially existing branch, false otherwise. /// A new . + [Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(Branch, string, bool) instead.")] public virtual Branch Move(Branch branch, string newName, bool allowOverwrite = false) { - return Move(branch, newName, null, null, allowOverwrite); + return Rename(branch, newName, allowOverwrite); } /// diff --git a/LibGit2Sharp/BranchCollectionExtensions.cs b/LibGit2Sharp/BranchCollectionExtensions.cs index c63dd3217..4adebf68e 100644 --- a/LibGit2Sharp/BranchCollectionExtensions.cs +++ b/LibGit2Sharp/BranchCollectionExtensions.cs @@ -1,4 +1,5 @@ using LibGit2Sharp.Core; +using System; namespace LibGit2Sharp { @@ -82,7 +83,7 @@ public static void Remove(this BranchCollection branches, string name, bool isRe /// True to allow silent overwriting a potentially existing branch, false otherwise. /// The being worked with. /// A new . - public static Branch Move(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false) + public static Branch Rename(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false) { Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName"); Ensure.ArgumentNotNullOrEmptyString(newName, "newName"); @@ -94,7 +95,21 @@ public static Branch Move(this BranchCollection branches, string currentName, st throw new LibGit2SharpException("No branch named '{0}' exists in the repository."); } - return branches.Move(branch, newName, allowOverwrite); + return branches.Rename(branch, newName, allowOverwrite); + } + + /// + /// Rename an existing local branch, using the default reflog message + /// + /// The current branch name. + /// The new name the existing branch should bear. + /// True to allow silent overwriting a potentially existing branch, false otherwise. + /// The being worked with. + /// A new . + [Obsolete("This will be removed in the next release. Please use BranchCollection.Rename(string, string, bool) instead.")] + public static Branch Move(this BranchCollection branches, string currentName, string newName, bool allowOverwrite = false) + { + return Rename(branches, currentName, newName, allowOverwrite); } } }