Skip to content

Commit 0e5bfbc

Browse files
committed
Verify that resolving a remote-tracking branch's remote can throw
1 parent 1b820a5 commit 0e5bfbc

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,33 @@ public void CanSetTrackedBranch()
685685
}
686686
}
687687

688+
[Fact]
689+
public void SetTrackedBranchForUnreasolvableRemoteThrows()
690+
{
691+
const string testBranchName = "branchToSetUpstreamInfoFor";
692+
const string trackedBranchName = "refs/remotes/origin/master";
693+
var fetchRefSpecs = new string[] { "+refs/heads/notfound/*:refs/remotes/origin/notfound/*" };
694+
695+
string path = CloneStandardTestRepo();
696+
using (var repo = new Repository(path))
697+
{
698+
// Modify the fetch spec so that the remote for the remote-tracking branch
699+
// cannot be resolved.
700+
Remote remote = repo.Network.Remotes["origin"];
701+
Assert.NotNull(remote);
702+
repo.Network.Remotes.Update(remote, r => r.FetchRefSpecs = fetchRefSpecs);
703+
704+
// Now attempt to update the tracked branch
705+
Branch branch = repo.CreateBranch(testBranchName);
706+
Assert.False(branch.IsTracking);
707+
708+
Branch trackedBranch = repo.Branches[trackedBranchName];
709+
710+
Assert.Throws<LibGit2SharpException>(() => repo.Branches.Update(branch,
711+
b => b.TrackedBranch = trackedBranch.CanonicalName));
712+
}
713+
}
714+
688715
[Fact]
689716
public void CanSetUpstreamBranch()
690717
{

0 commit comments

Comments
 (0)