Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2sharp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornulltoken <emeric.fermas@gmail.com>2011-05-30 23:54:34 +0400
committernulltoken <emeric.fermas@gmail.com>2011-05-30 23:54:34 +0400
commit1fe52e15b56ff9997fd78cd4566f25886b83cc04 (patch)
tree090255742adaa51774de819923af2e80a1b42456
parentbcb1feb530dd8c6958445841395d0cdb4f38adbd (diff)
Add branch renaming feature
-rw-r--r--LibGit2Sharp.Tests/BranchFixture.cs50
-rw-r--r--LibGit2Sharp/BranchCollection.cs20
-rw-r--r--LibGit2Sharp/ReferenceCollection.cs8
-rw-r--r--backlog.md16
4 files changed, 79 insertions, 15 deletions
diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs
index 84e04999..4630f6fd 100644
--- a/LibGit2Sharp.Tests/BranchFixture.cs
+++ b/LibGit2Sharp.Tests/BranchFixture.cs
@@ -244,5 +244,55 @@ namespace LibGit2Sharp.Tests
newBranch.IsCurrentRepositoryHead.ShouldBeFalse();
}
}
+
+ [Test]
+ public void CanMoveABranch()
+ {
+ using (var path = new TemporaryCloneOfTestRepo())
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ repo.Branches["br3"].ShouldBeNull();
+
+ var newBranch = repo.Branches.Move("br2", "br3");
+ newBranch.Name.ShouldEqual("br3");
+
+ repo.Branches["br2"].ShouldBeNull();
+ repo.Branches["br3"].ShouldNotBeNull();
+ }
+ }
+ [Test]
+ public void BlindlyMovingABranchOverAnExistingOneThrows()
+ {
+ using (var path = new TemporaryCloneOfTestRepo())
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ Assert.Throws<ApplicationException>(() => repo.Branches.Move("br2", "test"));
+ }
+ }
+
+ [Test]
+ public void CanMoveABranchWhileOverwritingAnExistingOne()
+ {
+ using (var path = new TemporaryCloneOfTestRepo())
+ using (var repo = new Repository(path.RepositoryPath))
+ {
+ var test = repo.Branches["test"];
+ test.ShouldNotBeNull();
+
+ var br2 = repo.Branches["br2"];
+ br2.ShouldNotBeNull();
+
+ var newBranch = repo.Branches.Move("br2", "test", true);
+ newBranch.Name.ShouldEqual("test");
+
+ repo.Branches["br2"].ShouldBeNull();
+
+ var newTest = repo.Branches["test"];
+ newTest.ShouldNotBeNull();
+ newTest.ShouldEqual(newBranch);
+
+ newTest.Tip.ShouldEqual(br2.Tip);
+ }
+ }
}
} \ No newline at end of file
diff --git a/LibGit2Sharp/BranchCollection.cs b/LibGit2Sharp/BranchCollection.cs
index 351b24e9..ecf9b3a7 100644
--- a/LibGit2Sharp/BranchCollection.cs
+++ b/LibGit2Sharp/BranchCollection.cs
@@ -98,7 +98,25 @@ namespace LibGit2Sharp
{
Ensure.ArgumentNotNullOrEmptyString(name, "name");
- repo.Refs.Delete(this[name].CanonicalName); //TODO: To be replaced by native libgit2 git_branch_delete() when available.
+ repo.Refs.Delete(NormalizeToCanonicalName(name)); //TODO: To be replaced by native libgit2 git_branch_delete() when available.
+ }
+
+ ///<summary>
+ /// Rename an existing branch with a new name.
+ ///</summary>
+ ///<param name="currentName">The current branch name.</param>
+ ///<param name="newName">The new name of the existing branch should bear.</param>
+ ///<param name="allowOverwrite">True to allow silent overwriting a potentially existing branch, false otherwise.</param>
+ ///<returns></returns>
+ public Branch Move(string currentName, string newName, bool allowOverwrite = false)
+ {
+ Ensure.ArgumentNotNullOrEmptyString(currentName, "name");
+ Ensure.ArgumentNotNullOrEmptyString(newName, "name");
+
+ Reference reference = repo.Refs.Move(NormalizeToCanonicalName(currentName), NormalizeToCanonicalName(newName),
+ allowOverwrite);
+
+ return this[reference.CanonicalName];
}
private static bool LooksLikeABranchName(string referenceName)
diff --git a/LibGit2Sharp/ReferenceCollection.cs b/LibGit2Sharp/ReferenceCollection.cs
index ee39a967..0fadbc48 100644
--- a/LibGit2Sharp/ReferenceCollection.cs
+++ b/LibGit2Sharp/ReferenceCollection.cs
@@ -127,16 +127,16 @@ namespace LibGit2Sharp
/// <summary>
/// Rename an existing reference with a new name
/// </summary>
- /// <param name="oldName">The canonical name of the reference to rename.</param>
+ /// <param name="currentName">The canonical name of the reference to rename.</param>
/// <param name="newName">The new canonical name.</param>
/// <param name="allowOverwrite">True to allow silent overwriting a potentially existing reference, false otherwise.</param>
/// <returns></returns>
- public Reference Move(string oldName, string newName, bool allowOverwrite = false)
+ public Reference Move(string currentName, string newName, bool allowOverwrite = false)
{
- Ensure.ArgumentNotNullOrEmptyString(oldName, "oldName");
+ Ensure.ArgumentNotNullOrEmptyString(currentName, "currentName");
Ensure.ArgumentNotNullOrEmptyString(newName, "newName");
- IntPtr referencePtr = RetrieveReferencePtr(oldName);
+ IntPtr referencePtr = RetrieveReferencePtr(currentName);
int res;
if (allowOverwrite)
diff --git a/backlog.md b/backlog.md
index 40f9479d..c92b111c 100644
--- a/backlog.md
+++ b/backlog.md
@@ -4,8 +4,7 @@
- Build a LibGit2Sharp.Sample NuGet package
- Publish source and PDBs at symbolsource.org (cf. http://blog.davidebbo.com/2011/04/easy-way-to-publish-nuget-packages-with.html and http://nuget.codeplex.com/discussions/257709)
- - Add to Epoch a DateTimeOffset extension method ToRelativeFormat() in order to show dates relative to the current time, e.g. "2 hours ago". (cf. https://github.com/git/git/blob/master/date.c#L89)
- - Add branch renaming (public Branch Move(string oldName, string newName, bool allowOverwrite = false))
+ - Maybe : Add to Epoch a DateTimeOffset extension method ToRelativeFormat() in order to show dates relative to the current time, e.g. "2 hours ago". (cf. https://github.com/git/git/blob/master/date.c#L89)
- Turn duplicated strings "refs/xxx" into properties of a generic Constants helper type
- Refactor the error handling (OutputResult -> Exceptions)
- Launch Code Analysis (Issues related to interop and marshaling will be worked on once we're able to succesffully exchange non ascii encoded data with libgit2)
@@ -19,23 +18,20 @@
### Wiki
- - How to integrate LibGit2Sharp in an application?
- - How do I do 'git xxx' with LibGit2Sharp? (cf. https://github.com/libgit2/libgit2sharp/wiki/What's-the-equivalent-to-'git-xxx'%3F)
+ - How to integrate LibGit2Sharp in an application (console, web, 32/64 bits...)?
+ - Keep "LibGit2Sharp Hitchhiker's Guide to Git" up to date (cf. https://github.com/libgit2/libgit2sharp/wiki/LibGit2Sharp-Hitchhiker%27s-Guide-to-Git)
+ - Add a complete example (repo init, open repo, stage, commit, branch, ...)
### Tests
+ - Enforce test coverage of BranchCollection using canonical names, remotes, non existing branches.
- Add tests ensuring the behavior of indexers when being passed unknown sha and refs
- Add GitObject equality test suite
- Add Reference equality test suite
- - Ensure former API tests are ported and passing
- Remove Ignore attribute from ReferenceFixture.CanMoveAReferenceToADeeperReferenceHierarchy() once git_reference_rename() is fixed
- Remove Ignore attribute from ReferenceFixture.CanMoveAReferenceToAUpperReferenceHierarchy() once git_reference_rename() is fixed
-
-### Documentation
-
- - Write some sample API usage similar to http://libgit2.github.com/api.html (C# language pack definition available @ http://shjs.sourceforge.net/)
### Miscellaneous
- - Run the tests on a Mono platform
+ - Run the build on a Unix platform