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:
authorJameson Miller <jamill@microsoft.com>2014-09-25 00:47:01 +0400
committerJameson Miller <jamill@microsoft.com>2014-09-25 01:20:10 +0400
commit1b820a5b5f2228beb6bb1abd2e082c261360145f (patch)
treeb54a7cdc26255c43f185bb3af8707dd925a4e415 /LibGit2Sharp.Tests/BranchFixture.cs
parentbf93cba905a1b9b479e2474a579aa168745c2ff6 (diff)
Branch.Remote property should not throw
The Branch.Remote property can throw when it attempts to resolve a remote for a remote-tracking branch, and the remote cannot be found or is ambiguous. In those situations, Branch.Remote should return null. If there is a need for the specific exception to be returned, we can look at transitioning to a method for this functionality.
Diffstat (limited to 'LibGit2Sharp.Tests/BranchFixture.cs')
-rw-r--r--LibGit2Sharp.Tests/BranchFixture.cs58
1 files changed, 58 insertions, 0 deletions
diff --git a/LibGit2Sharp.Tests/BranchFixture.cs b/LibGit2Sharp.Tests/BranchFixture.cs
index 0aef1a27..642b1a8a 100644
--- a/LibGit2Sharp.Tests/BranchFixture.cs
+++ b/LibGit2Sharp.Tests/BranchFixture.cs
@@ -392,6 +392,64 @@ namespace LibGit2Sharp.Tests
}
[Fact]
+ public void QueryRemoteForRemoteBranch()
+ {
+ using (var repo = new Repository(StandardTestRepoPath))
+ {
+ var master = repo.Branches["origin/master"];
+ Assert.Equal(repo.Network.Remotes["origin"], master.Remote);
+ }
+ }
+
+ [Fact]
+ public void QueryUnresolvableRemoteForRemoteBranch()
+ {
+ var path = CloneStandardTestRepo();
+
+ var fetchRefSpecs = new string[] { "+refs/heads/notfound/*:refs/remotes/origin/notfound/*" };
+
+ using (var repo = InitIsolatedRepository(path))
+ {
+ // Update the remote config such that the remote for a
+ // remote branch cannot be resolved
+ Remote remote = repo.Network.Remotes["origin"];
+ Assert.NotNull(remote);
+
+ repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs = fetchRefSpecs);
+
+ Branch branch = repo.Branches["refs/remotes/origin/master"];
+
+ Assert.NotNull(branch);
+ Assert.True(branch.IsRemote);
+
+ Assert.Null(branch.Remote);
+ }
+ }
+
+ [Fact]
+ public void QueryAmbigousRemoteForRemoteBranch()
+ {
+ var path = CloneStandardTestRepo();
+
+ var fetchRefSpec = "+refs/heads/*:refs/remotes/origin/*";
+ var url = "http://github.com/libgit2/TestGitRepository";
+
+ using (var repo = InitIsolatedRepository(path))
+ {
+ // Add a second remote so that it is ambiguous which remote
+ // the remote-tracking branch tracks.
+ repo.Network.Remotes.Add("ambiguous", url, fetchRefSpec);
+
+ Branch branch = repo.Branches["refs/remotes/origin/master"];
+
+ Assert.NotNull(branch);
+ Assert.True(branch.IsRemote);
+
+ Assert.Null(branch.Remote);
+ }
+ }
+
+ [Fact]
public void CanLookupABranchByItsCanonicalName()
{
using (var repo = new Repository(BareTestRepoPath))