From 1f9e41ee865ac3a9c60d39c7db212478c04bf86d Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Fri, 10 May 2013 07:50:53 -0700 Subject: Improve ignore handling in git_status_file The git_status_file API was doing a hack to deal with files that are inside ignored directories. The status scan was not reporting any file in this case, so git_status_file would attempt a final "stat()" call, and return IGNORED if the file actually existed. On case-insensitive filesystems where core.ignorecase is set incorrectly, this magic check can "succeed" and report a file as ignored when it should actually return ENOTFOUND. Now that we have the GIT_STATUS_OPT_RECURSE_IGNORED_DIRS, we can use that flag to make sure that git_status_file() will look into ignored directories and eliminate the hack completely, so we give the correct error. --- tests-clar/clar_libgit2.c | 12 ++++++++++++ tests-clar/clar_libgit2.h | 1 + tests-clar/status/worktree.c | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+) (limited to 'tests-clar') diff --git a/tests-clar/clar_libgit2.c b/tests-clar/clar_libgit2.c index 68d17162b..de0e41bf7 100644 --- a/tests-clar/clar_libgit2.c +++ b/tests-clar/clar_libgit2.c @@ -190,6 +190,18 @@ git_repository *cl_git_sandbox_init(const char *sandbox) return _cl_repo; } +git_repository *cl_git_sandbox_reopen(void) +{ + if (_cl_repo) { + git_repository_free(_cl_repo); + _cl_repo = NULL; + + cl_git_pass(git_repository_open(&_cl_repo, _cl_sandbox)); + } + + return _cl_repo; +} + void cl_git_sandbox_cleanup(void) { if (_cl_repo) { diff --git a/tests-clar/clar_libgit2.h b/tests-clar/clar_libgit2.h index 93909d8a5..3fcf45a37 100644 --- a/tests-clar/clar_libgit2.h +++ b/tests-clar/clar_libgit2.h @@ -60,6 +60,7 @@ int cl_rename(const char *source, const char *dest); git_repository *cl_git_sandbox_init(const char *sandbox); void cl_git_sandbox_cleanup(void); +git_repository *cl_git_sandbox_reopen(void); /* Local-repo url helpers */ const char* cl_git_fixture_url(const char *fixturename); diff --git a/tests-clar/status/worktree.c b/tests-clar/status/worktree.c index 0138b1712..062a09aeb 100644 --- a/tests-clar/status/worktree.c +++ b/tests-clar/status/worktree.c @@ -672,3 +672,26 @@ void test_status_worktree__file_status_honors_core_ignorecase_false(void) { assert_ignore_case(false, GIT_STATUS_WT_DELETED, GIT_STATUS_WT_NEW); } + +void test_status_worktree__file_status_honors_case_ignorecase_regarding_untracked_files(void) +{ + git_repository *repo = cl_git_sandbox_init("status"); + unsigned int status; + git_index *index; + + cl_repo_set_bool(repo, "core.ignorecase", false); + + repo = cl_git_sandbox_reopen(); + + /* Actually returns GIT_STATUS_IGNORED on Windows */ + cl_git_fail_with(git_status_file(&status, repo, "NEW_FILE"), GIT_ENOTFOUND); + + cl_git_pass(git_repository_index(&index, repo)); + + cl_git_pass(git_index_add_bypath(index, "new_file")); + cl_git_pass(git_index_write(index)); + git_index_free(index); + + /* Actually returns GIT_STATUS_IGNORED on Windows */ + cl_git_fail_with(git_status_file(&status, repo, "NEW_FILE"), GIT_ENOTFOUND); +} -- cgit v1.2.3