Skip to content

Commit 4206860

Browse files
committed
Add unit test for #1782
This unit test demonstrates the exception that was reported in #1782.
1 parent 4de700f commit 4206860

17 files changed

+61
-0
lines changed

LibGit2Sharp.Tests/BranchFixture.cs

+33
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,39 @@ public void CanUnsetTrackedBranch()
879879
}
880880
}
881881

882+
[Fact]
883+
public void CanSetTrackedBranch_MultipleFetchSpecs()
884+
{
885+
const string testBranchName = "master";
886+
const string trackedBranchName = "refs/remotes/origin/master";
887+
888+
string path = SandboxMultiFetchSpecTestRepo();
889+
using (var repo = new Repository(path))
890+
{
891+
Branch trackedBranch = repo.Branches[trackedBranchName];
892+
Assert.True(trackedBranch.IsRemote);
893+
894+
Branch branch = repo.CreateBranch(testBranchName, trackedBranch.Tip);
895+
Assert.False(branch.IsTracking);
896+
897+
repo.Branches.Update(branch,
898+
b => b.TrackedBranch = trackedBranch.CanonicalName);
899+
900+
// Verify the immutability of the branch.
901+
Assert.False(branch.IsTracking);
902+
903+
// Get the updated branch information.
904+
branch = repo.Branches[testBranchName];
905+
906+
Remote upstreamRemote = repo.Network.Remotes["origin"];
907+
Assert.NotNull(upstreamRemote);
908+
909+
Assert.True(branch.IsTracking);
910+
Assert.Equal(trackedBranch, branch.TrackedBranch);
911+
Assert.Equal("origin", branch.RemoteName);
912+
}
913+
}
914+
882915
[Fact]
883916
public void CanWalkCommitsFromBranch()
884917
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This is another file

LibGit2Sharp.Tests/Resources/multifetchspec_testrepo_wd/dot_git/FETCH_HEAD

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/PR-28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = false
4+
bare = false
5+
logallrefupdates = true
6+
ignorecase = true
7+
[remote "origin"]
8+
url = ../multifetchspec_testrepo.git/
9+
fetch = +refs/pull/28/head:refs/remotes/origin/PR-28
10+
fetch = +refs/heads/master:refs/remotes/origin/master
11+
fetch = +refs/heads/*:refs/remotes/origin/*
12+
[branch "PR-28"]
13+
remote = origin
14+
merge = refs/pull/28/head
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x+)JMU�0f040031Qp��/�H-r��I�+�(a(�X�y��ޟ��k֟8iS��6Ti^jy|L�+W���'����xg�f���m;|I %�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b9767f840d2eda4faeafe47712eb3bdf506f8a0a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
b9767f840d2eda4faeafe47712eb3bdf506f8a0a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
651df87831579c12dab081797720d9973edf477a
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
New file

LibGit2Sharp.Tests/TestHelpers/BaseFixture.cs

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ static BaseFixture()
3333

3434
public static string BareTestRepoPath { get; private set; }
3535
public static string StandardTestRepoWorkingDirPath { get; private set; }
36+
public static string StandardMultiFetchSpecWorkingDirPath { get; private set; }
3637
public static string StandardTestRepoPath { get; private set; }
3738
public static string ShallowTestRepoPath { get; private set; }
3839
public static string MergedTestRepoWorkingDirPath { get; private set; }
@@ -74,6 +75,7 @@ private static void SetUpTestEnvironment()
7475
BareTestRepoPath = Path.Combine(ResourcesDirectory.FullName, "testrepo.git");
7576
StandardTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "testrepo_wd");
7677
StandardTestRepoPath = Path.Combine(StandardTestRepoWorkingDirPath, "dot_git");
78+
StandardMultiFetchSpecWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "multifetchspec_testrepo_wd");
7779
ShallowTestRepoPath = Path.Combine(ResourcesDirectory.FullName, "shallow.git");
7880
MergedTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "mergedrepo_wd");
7981
MergeRenamesTestRepoWorkingDirPath = Path.Combine(ResourcesDirectory.FullName, "mergerenames_wd");
@@ -183,6 +185,11 @@ protected string SandboxStandardTestRepo()
183185
return Sandbox(StandardTestRepoWorkingDirPath);
184186
}
185187

188+
protected string SandboxMultiFetchSpecTestRepo()
189+
{
190+
return Sandbox(StandardMultiFetchSpecWorkingDirPath);
191+
}
192+
186193
protected string SandboxMergedTestRepo()
187194
{
188195
return Sandbox(MergedTestRepoWorkingDirPath);

0 commit comments

Comments
 (0)