Commit d0a920a6fd70aaad9a3cee10ba6465f3b04a7bc5

nulltoken 2012-07-07T10:36:35

refs: deep unfound ref returns ENOTFOUND

diff --git a/src/fileops.c b/src/fileops.c
index 95a6589..5849b79 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -94,7 +94,7 @@ int git_futils_open_ro(const char *path)
 {
 	int fd = p_open(path, O_RDONLY);
 	if (fd < 0) {
-		if (errno == ENOENT)
+		if (errno == ENOENT || errno == ENOTDIR)
 			fd = GIT_ENOTFOUND;
 		giterr_set(GITERR_OS, "Failed to open '%s'", path);
 	}
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index d7111b2..6838ead 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -192,3 +192,13 @@ void test_refs_read__loose_first(void)
 
 	git_reference_free(reference);
 }
+
+void test_refs_read__unfound_return_ENOTFOUND(void)
+{
+	git_reference *reference;
+
+	cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "test/master"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/test/master"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/master"));
+	cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/farther/master"));
+}