git_status_file now takes an exact path

This function has one output but can match multiple files, which can be
unexpected for the user, which would usually path the exact path of the
file he wants the status of.
This commit is contained in:
Ungureanu Marius 2014-11-07 20:32:50 +02:00
parent 4e1b3b3b71
commit 6818208569
4 changed files with 8 additions and 5 deletions

View File

@ -112,3 +112,6 @@ v0.21 + 1
now uint32_t instead of uint16_t. This allows to set them to UINT_MAX,
in effect asking for "infinite" context e.g. to iterate over all the
unmodified lines of a diff.
* git_status_file now takes an exact path. Use git_status_list_new if
pathspec searching is needed.

View File

@ -281,7 +281,8 @@ GIT_EXTERN(int) git_status_foreach_ext(
*
* @param status_flags Output combination of git_status_t values for file
* @param repo A repository object
* @param path The file to retrieve status for relative to the repo workdir
* @param path The exact path to retrieve status for relative to the
* repository working directory
* @return 0 on success, GIT_ENOTFOUND if the file is not found in the HEAD,
* index, and work tree, GIT_EAMBIGUOUS if `path` matches multiple files
* or if it refers to a folder, and -1 on other errors.

View File

@ -494,7 +494,8 @@ int git_status_file(
GIT_STATUS_OPT_RECURSE_IGNORED_DIRS |
GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = 1;
opts.pathspec.strings = &sfi.expected;

View File

@ -195,9 +195,7 @@ void test_status_worktree_init__bracket_in_filename(void)
cl_git_pass(git_status_file(&status_flags, repo, "LICENSE\\[1\\].md"));
cl_assert(status_flags == GIT_STATUS_INDEX_NEW);
error = git_status_file(&status_flags, repo, FILE_WITH_BRACKET);
cl_git_fail(error);
cl_assert_equal_i(GIT_EAMBIGUOUS, error);
cl_git_pass(git_status_file(&status_flags, repo, FILE_WITH_BRACKET));
git_index_free(index);
git_repository_free(repo);