summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2013-10-11 09:47:05 -0700
committerVicent Martí <vicent@github.com>2013-10-11 09:47:05 -0700
commit2c2b0ebb4ab646a9f6a03d9bda176634e609b279 (patch)
treedbc51d7b573bd58530243ac775032e8a025e0191
parent4d43e6300ca40b8c00ca674288a29e1ca696d316 (diff)
parent7c9f5bec5182eb587fbc1094f2235d2babb70ad9 (diff)
downloadlibgit2-2c2b0ebb4ab646a9f6a03d9bda176634e609b279.tar.gz
Merge pull request #1562 from libgit2/cmn/refs-namespace-lookup
Provide the user with a more useful error code when a looking up a reference which name points to a namepace
-rw-r--r--src/fileops.c8
-rw-r--r--tests-clar/refs/lookup.c12
2 files changed, 19 insertions, 1 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 63aedc6d0..17007f823 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -147,7 +147,13 @@ int git_futils_readbuffer_updated(
if (p_stat(path, &st) < 0)
return git_path_set_error(errno, path, "stat");
- 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 0dbebc5c2..2e31cf0f6 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);
+}