Skip to content

Commit 2de8c00

Browse files
committed
Fix git_status_file binding (GIT_EAMBIGOUS is a valid return value)
1 parent 617b9b8 commit 2de8c00

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,5 +241,23 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
241241
Assert.Equal(new[] { relativePath, "new_untracked_file.txt" }, newStatus.Ignored);
242242
}
243243
}
244+
245+
[Fact(Skip = "This test needs libgit2/libgit2@ffbc689")]
246+
public void RetrievingTheStatusOfAnAmbiguousFileThrows()
247+
{
248+
TemporaryCloneOfTestRepo path = BuildTemporaryCloneOfTestRepo(StandardTestRepoWorkingDirPath);
249+
using (var repo = new Repository(path.RepositoryPath))
250+
{
251+
string relativePath = Path.Combine("1", "ambiguous1.txt");
252+
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
253+
File.WriteAllText(fullFilePath, "I don't like brackets.");
254+
255+
relativePath = Path.Combine("1", "ambiguous[1].txt");
256+
fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
257+
File.WriteAllText(fullFilePath, "Brackets all the way.");
258+
259+
repo.Index.RetrieveStatus(relativePath);
260+
}
261+
}
244262
}
245263
}

LibGit2Sharp/Core/Proxy.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,13 +1284,19 @@ public static FileStatus git_status_file(RepositorySafeHandle repo, FilePath pat
12841284
FileStatus status;
12851285
int res = NativeMethods.git_status_file(out status, repo, path);
12861286

1287-
if (res == (int)GitErrorCode.NotFound)
1287+
switch (res)
12881288
{
1289-
return FileStatus.Nonexistent;
1289+
case (int)GitErrorCode.NotFound:
1290+
return FileStatus.Nonexistent;
1291+
1292+
case (int)GitErrorCode.Ambiguous:
1293+
throw new AmbiguousException(string.Format(CultureInfo.InvariantCulture, "More than one file matches the pathspec '{0}'. You can either force a literal path evaluation (GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH), or use git_status_foreach().", path));
1294+
1295+
default:
1296+
Ensure.Success(res);
1297+
break;
12901298
}
12911299

1292-
Ensure.Success(res);
1293-
12941300
return status;
12951301
}
12961302
}

0 commit comments

Comments
 (0)