futils: return GIT_ENOTFOUND when trying to read a directory This lets the reference code return not-found when the user asks to look up a reference when in fact they pass a namespace.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/fileops.c b/src/fileops.c
index 3a5a530..210f45f 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -165,7 +165,13 @@ int git_futils_readbuffer_updated(
return -1;
}
- if (S_ISDIR(st.st_mode) || !git__is_sizet(st.st_size+1)) {
+
+ if (S_ISDIR(st.st_mode)) {
+ giterr_set(GITERR_INVALID, "requested file is a directory");
+ return GIT_ENOTFOUND;
+ }
+
+ if (!git__is_sizet(st.st_size+1)) {
giterr_set(GITERR_OS, "Invalid regular file stat for '%s'", path);
return -1;
}
diff --git a/tests-clar/refs/lookup.c b/tests-clar/refs/lookup.c
index 0dbebc5..2e31cf0 100644
--- a/tests-clar/refs/lookup.c
+++ b/tests-clar/refs/lookup.c
@@ -46,3 +46,15 @@ void test_refs_lookup__oid(void)
cl_git_pass(git_oid_fromstr(&expected, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_assert(git_oid_cmp(&tag, &expected) == 0);
}
+
+void test_refs_lookup__namespace(void)
+{
+ int error;
+ git_reference *ref;
+
+ error = git_reference_lookup(&ref, g_repo, "refs/heads");
+ cl_assert_equal_i(error, GIT_ENOTFOUND);
+
+ error = git_reference_lookup(&ref, g_repo, "refs/heads/");
+ cl_assert_equal_i(error, GIT_EINVALIDSPEC);
+}