{"thread":{"id":"29655","subject":"[PATCH] refresh_index: do not show unmerged path that is outside pathspec","startedAt":"2012-02-17T18:27:55Z","lastAt":"2012-02-17T18:27:55Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"184893","messageId":"7vsji9tivo.fsf@alter.siamese.dyndns.org","threadId":"29655","inReplyTo":null,"subject":"[PATCH] refresh_index: do not show unmerged path that is outside pathspec","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-02-17T18:27:55Z","receivedAt":"2012-02-17T18:27:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When running \"git add --refresh <pathspec>\", we incorrectly showed the\npath that is unmerged even if it is outside the specified pathspec, even\nthough we did honor pathspec and refreshed only the paths that matched.\n\nNote that this cange does not affect \"git update-index --refresh\"; for\nhysterical raisins, it does not take a pathspec (it takes real paths) and\nmore importantly itss command line options are parsed and executed one by\none as they are encountered, so \"git update-index --refresh foo\" means\n\"first refresh the index, and then update the entry 'foo' by hashing the\ncontents in file 'foo'\", not \"refresh only entry 'foo'\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * I wondered if the \"has_errors\" that the caller can use to detect if\n   there are not-yet-added paths should be covered by the if (!filtered)\n   test as well.  No caller that passes pathpec seems to use the return\n   value, so we probably should for the sake of consistency, but I didn't.\n\n read-cache.c   |   11 +++++++++--\n t/t3700-add.sh |   15 +++++++++++++++\n 2 files changed, 24 insertions(+), 2 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex a51bba1..274e54b 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1120,11 +1120,16 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p\n \t\tstruct cache_entry *ce, *new;\n \t\tint cache_errno = 0;\n \t\tint changed = 0;\n+\t\tint filtered = 0;\n \n \t\tce = istate->cache[i];\n \t\tif (ignore_submodules && S_ISGITLINK(ce->ce_mode))\n \t\t\tcontinue;\n \n+\t\tif (pathspec &&\n+\t\t    !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))\n+\t\t\tfiltered = 1;\n+\n \t\tif (ce_stage(ce)) {\n \t\t\twhile ((i < istate->cache_nr) &&\n \t\t\t       ! strcmp(istate->cache[i]->name, ce->name))\n@@ -1132,12 +1137,14 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p\n \t\t\ti--;\n \t\t\tif (allow_unmerged)\n \t\t\t\tcontinue;\n-\t\t\tshow_file(unmerged_fmt, ce->name, in_porcelain, &first, header_msg);\n+\t\t\tif (!filtered)\n+\t\t\t\tshow_file(unmerged_fmt, ce->name, in_porcelain,\n+\t\t\t\t\t  &first, header_msg);\n \t\t\thas_errors = 1;\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (pathspec && !match_pathspec(pathspec, ce->name, strlen(ce->name), 0, seen))\n+\t\tif (filtered)\n \t\t\tcontinue;\n \n \t\tnew = refresh_cache_ent(istate, ce, options, &cache_errno, &changed);\ndiff --git a/t/t3700-add.sh b/t/t3700-add.sh\nindex 575d950..874b3a6 100755\n--- a/t/t3700-add.sh\n+++ b/t/t3700-add.sh\n@@ -179,6 +179,21 @@ test_expect_success 'git add --refresh' '\n \ttest -z \"`git diff-index HEAD -- foo`\"\n '\n \n+test_expect_success 'git add --refresh with pathspec' '\n+\tgit reset --hard &&\n+\techo >foo && echo >bar && echo >baz &&\n+\tgit add foo bar baz && H=$(git rev-parse :foo) && git rm -f foo &&\n+\techo \"100644 $H 3\tfoo\" | git update-index --index-info &&\n+\ttest-chmtime -60 bar baz &&\n+\t>expect &&\n+\tgit add --refresh bar >actual &&\n+\ttest_cmp expect actual &&\n+\n+\tgit diff-files --name-only >actual &&\n+\t! grep bar actual&&\n+\tgrep baz actual\n+'\n+\n test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' '\n \tgit reset --hard &&\n \tdate >foo1 &&\n-- \n1.7.9.1.265.g25f75\n"}]}