status: Prevent git_status_file() from returning ENOTFOUND when not applicable
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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
diff --git a/src/status.c b/src/status.c
index ff8535c..546dc86 100644
--- a/src/status.c
+++ b/src/status.c
@@ -340,17 +340,17 @@ int git_status_file(
assert(status_flags && repo && path);
if ((workdir = git_repository_workdir(repo)) == NULL) {
- giterr_set(GITERR_OS, "Cannot get file status from bare repo");
- return GIT_ENOTFOUND;
+ giterr_set(GITERR_INVALID, "Cannot get file status from bare repo");
+ return -1;
}
if (git_buf_joinpath(&temp_path, workdir, path) < 0)
return -1;
if (git_path_isdir(temp_path.ptr)) {
- giterr_set(GITERR_OS, "Cannot get file status for directory '%s'", temp_path.ptr);
+ giterr_set(GITERR_INVALID, "Cannot get file status for directory '%s'", temp_path.ptr);
git_buf_free(&temp_path);
- return GIT_ENOTFOUND;
+ return -1;
}
e = status_entry_new(NULL, path);
diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c
index 8f48cf1..2a647ff 100644
--- a/tests-clar/status/worktree.c
+++ b/tests-clar/status/worktree.c
@@ -275,6 +275,7 @@ void test_status_worktree__single_folder(void)
error = git_status_file(&status_flags, repo, "subdir");
cl_git_fail(error);
+ cl_assert(error != GIT_ENOTFOUND);
}
@@ -384,3 +385,18 @@ void test_status_worktree__issue_592_5(void)
git_buf_free(&path);
}
+
+void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void)
+{
+ git_repository *repo;
+ int error, status = 0;
+
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ error = git_status_file(&status, repo, "dummy");
+
+ cl_git_fail(error);
+ cl_assert(error != GIT_ENOTFOUND);
+
+ git_repository_free(repo);
+}
\ No newline at end of file