Skip to content

Commit e263898

Browse files
committed
Update exception message when Pull cannot find ref to merge
1 parent c8e7be6 commit e263898

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

LibGit2Sharp.Tests/NetworkFixture.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,38 @@ public void CanPullIntoEmptyRepo()
196196
}
197197
}
198198

199+
[Fact]
200+
public void PullWithoutMergeBranchThrows()
201+
{
202+
var scd = BuildSelfCleaningDirectory();
203+
string clonedRepoPath = Repository.Clone(StandardTestRepoPath, scd.DirectoryPath);
204+
205+
using (var repo = new Repository(clonedRepoPath))
206+
{
207+
Branch branch = repo.Branches["master"];
208+
209+
// Update the Upstream merge branch
210+
repo.Branches.Update(branch,
211+
b => b.UpstreamBranch = "refs/heads/another_master");
212+
213+
bool didPullThrow = false;
214+
MergeFetchHeadNotFoundException thrownException = null;
215+
216+
try
217+
{
218+
repo.Network.Pull(Constants.Signature, new PullOptions());
219+
}
220+
catch(MergeFetchHeadNotFoundException ex)
221+
{
222+
didPullThrow = true;
223+
thrownException = ex;
224+
}
225+
226+
Assert.True(didPullThrow, "Pull did not throw.");
227+
Assert.True(thrownException.Message.Contains("refs/heads/another_master"), "Exception message did not contain expected reference.");
228+
}
229+
}
230+
199231
/*
200232
* git ls-remote http://github.com/libgit2/TestGitRepository
201233
* 49322bb17d3acc9146f98c97d078513228bbf3c0 HEAD

LibGit2Sharp/Repository.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,9 @@ internal MergeResult MergeFetchHeads(Signature merger, MergeOptions options)
10321032

10331033
if (fetchHeads.Length == 0)
10341034
{
1035-
throw new MergeFetchHeadNotFoundException("The configured reference to merge with was not fetched from the remote.");
1035+
var expectedRef = this.Head.UpstreamBranchCanonicalName;
1036+
throw new MergeFetchHeadNotFoundException(string.Format(CultureInfo.InvariantCulture,
1037+
"The current branch is configured to merge with the reference '{0}' from the remote, but this reference was not fetched.", expectedRef));
10361038
}
10371039

10381040
GitMergeHeadHandle[] mergeHeadHandles = fetchHeads.Select(fetchHead =>

0 commit comments

Comments
 (0)