Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BranchCollection: Obsolete Move and introduce Rename. #738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions LibGit2Sharp.Tests/BranchFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<LibGit2SharpException>(() => repo.Branches.Move(master, "new_name", true));
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Rename(master, "new_name", true));
}
}

Expand Down Expand Up @@ -821,7 +821,7 @@ public void TwoBranchesPointingAtTheSameCommitAreNotBothCurrent()
}

[Fact]
public void CanMoveABranch()
public void CanRenameABranch()
{
string path = CloneBareTestRepo();
using (var repo = new Repository(path))
Expand All @@ -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);

Expand All @@ -846,16 +846,16 @@ public void CanMoveABranch()
}

[Fact]
public void BlindlyMovingABranchOverAnExistingOneThrows()
public void BlindlyRenamingABranchOverAnExistingOneThrows()
{
using (var repo = new Repository(BareTestRepoPath))
{
Assert.Throws<NameConflictException>(() => repo.Branches.Move("br2", "test"));
Assert.Throws<NameConflictException>(() => repo.Branches.Rename("br2", "test"));
}
}

[Fact]
public void CanMoveABranchWhileOverwritingAnExistingOne()
public void CanRenameABranchWhileOverwritingAnExistingOne()
{
string path = CloneBareTestRepo();
using (var repo = new Repository(path))
Expand All @@ -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"]);
Expand Down Expand Up @@ -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");
}
}
Expand Down
32 changes: 30 additions & 2 deletions LibGit2Sharp/BranchCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public virtual void Remove(Branch branch)
/// <param name="logMessage">Message added to the reflog. If null, the default is "branch: renamed [old] to [new]".</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 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");
Expand Down Expand Up @@ -195,16 +195,44 @@ public virtual Branch Move(Branch branch, string newName, Signature signature, s
return newBranch;
}

/// <summary>
/// Rename an existing local branch
/// </summary>
/// <param name="branch">The current local branch.</param>
/// <param name="newName">The new name the existing branch should bear.</param>
/// <param name="signature">Identity used for updating the reflog</param>
/// <param name="logMessage">Message added to the reflog. If null, the default is "branch: renamed [old] to [new]".</param>
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns>A new <see cref="Branch"/>.</returns>
[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);
}

/// <summary>
/// Rename an existing local branch, using the default reflog message
/// </summary>
/// <param name="branch">The current local branch.</param>
/// <param name="newName">The new name the existing branch should bear.</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 Rename(Branch branch, string newName, bool allowOverwrite = false)
{
return Rename(branch, newName, null, null, allowOverwrite);
}

/// <summary>
/// Rename an existing local branch, using the default reflog message
/// </summary>
/// <param name="branch">The current local branch.</param>
/// <param name="newName">The new name the existing branch should bear.</param>
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <returns>A new <see cref="Branch"/>.</returns>
[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);
}

/// <summary>
Expand Down
19 changes: 17 additions & 2 deletions LibGit2Sharp/BranchCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LibGit2Sharp.Core;
using System;

namespace LibGit2Sharp
{
Expand Down Expand Up @@ -82,7 +83,7 @@ public static void Remove(this BranchCollection branches, string name, bool isRe
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param>
/// <returns>A new <see cref="Branch"/>.</returns>
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");
Expand All @@ -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);
}

/// <summary>
/// Rename an existing local branch, using the default reflog message
/// </summary>
/// <param name="currentName">The current branch name.</param>
/// <param name="newName">The new name the existing branch should bear.</param>
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
/// <param name="branches">The <see cref="BranchCollection"/> being worked with.</param>
/// <returns>A new <see cref="Branch"/>.</returns>
[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);
}
}
}