diff options
| author | Jason Penny <jasonpenny4@gmail.com> | 2011-07-09 00:08:52 -0400 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-07-09 13:49:50 +0200 |
| commit | 3b2a423c3fb9e434c427b819d3281ae9e277091d (patch) | |
| tree | 4c2a88c1f85a5c804cd2bce80ccd6f636aecaca8 | |
| parent | 2b90cc26de1c6b71059a7fc43be32a3be7fb35b9 (diff) | |
| download | libgit2-3b2a423c3fb9e434c427b819d3281ae9e277091d.tar.gz | |
status: nonexistent file with git_status_file()
Throws GIT_ENOTFOUND error if given a filename that is not in
HEAD, index, nor the work tree.
| -rw-r--r-- | src/status.c | 9 | ||||
| -rw-r--r-- | tests/t18-status.c | 21 |
2 files changed, 28 insertions, 2 deletions
diff --git a/src/status.c b/src/status.c index e42184292..9f826e0bc 100644 --- a/src/status.c +++ b/src/status.c @@ -258,6 +258,9 @@ static int set_status_flags(struct status_entry *e) index_zero = git_oid_cmp(&zero, &e->index_oid); wt_zero = git_oid_cmp(&zero, &e->wt_oid); + if (head_zero == 0 && index_zero == 0 && wt_zero == 0) + return GIT_ENOTFOUND; + if (head_zero == 0 && index_zero != 0) e->status_flags |= GIT_STATUS_INDEX_NEW; else if (index_zero == 0 && head_zero != 0) @@ -345,7 +348,7 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char git_index *index; git_index_entry *index_entry; char temp_path[GIT_PATH_MAX]; - int idx; + int idx, error; git_tree *tree; git_reference *head_ref, *resolved_head_ref; git_commit *head_commit; @@ -377,7 +380,9 @@ int git_status_file(unsigned int *status_flags, git_repository *repo, const char strcpy(temp_path, repo->path_workdir); git_futils_direach(temp_path, GIT_PATH_MAX, single_dirent_cb, &e); - set_status_flags(e); + if ((error = set_status_flags(e)) < GIT_SUCCESS) + return git__throw(error, "Nonexistent file"); + *status_flags = e->status_flags; free(e); diff --git a/tests/t18-status.c b/tests/t18-status.c index dfd87b3ab..a20d97b8f 100644 --- a/tests/t18-status.c +++ b/tests/t18-status.c @@ -184,9 +184,30 @@ BEGIN_TEST(singlestatus0, "test retrieving status for single file") git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1); END_TEST +BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file") + char path_statusfiles[GIT_PATH_MAX]; + char temp_path[GIT_PATH_MAX]; + git_repository *repo; + unsigned int status_flags; + int error; + + must_pass(copy_status_repo(path_statusfiles, temp_path)); + + must_pass(git_repository_open(&repo, temp_path)); + + // "nonexistent" does not exist in HEAD, Index or the worktree + error = git_status_file(&status_flags, repo, "nonexistent"); + must_be_true(error == GIT_ENOTFOUND); + + git_repository_free(repo); + + git_futils_rmdir_r(TEMP_STATUS_FOLDER, 1); +END_TEST + BEGIN_SUITE(status) ADD_TEST(file0); ADD_TEST(statuscb0); ADD_TEST(singlestatus0); + ADD_TEST(singlestatus1); END_SUITE |
