{"thread":{"id":"48482","subject":"[PATCH 1/2] diff: turn --ita-invisible-in-index on by default","startedAt":"2018-05-13T17:55:01Z","lastAt":"2018-05-27T07:18:47Z","messageCount":15,"participants":["Nguyễn Thái Ngọc Duy","Junio C Hamano","Duy Nguyen","Jonathan Nieder","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"347549","messageId":"20180513175438.32152-1-pclouds@gmail.com","threadId":"48482","inReplyTo":null,"subject":"[PATCH 1/2] diff: turn --ita-invisible-in-index on by default","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-13T17:54:37Z","receivedAt":"2018-05-13T17:55:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Due to the implementation detail of intent-to-add entries. The current\n\"git diff\" (i.e. no treeish or --cached argument) would show the\nchanges in the i-t-a file, but it does not mark the file as new, while\n\"diff --cached\" would mark the file as new while showing its content\nas empty.\n\nOne evidence of the current output being wrong is that, the output\nfrom \"git diff\" (with ita entries) cannot be applied because it\nassumes empty files exist before applying.\n\nTurning on --ita-invisible-in-index [1] [2] would fix this.\n\nThis option is on by default in git-status [1] but we need more fixup\nin rename detection code [3]. Luckily we don't need to do anything\nelse for the rename detection code in diff.c (wt-status.c uses a\ncustomized one).\n\n[1] 425a28e0a4 (diff-lib: allow ita entries treated as \"not yet exist\n    in index\" - 2016-10-24)\n[2] b42b451919 (diff: add --ita-[in]visible-in-index - 2016-10-24)\n[3] bc3dca07f4 (Merge branch 'nd/ita-wt-renames-in-status' - 2018-01-23)\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/diff.c          |  7 +++++++\n t/t2203-add-intent.sh   | 37 ++++++++++++++++++++++++++++++-------\n t/t4011-diff-symlink.sh | 10 ++++++----\n 3 files changed, 43 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 16bfb22f73..00424c296d 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -352,6 +352,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \trev.diffopt.flags.allow_external = 1;\n \trev.diffopt.flags.allow_textconv = 1;\n \n+\t/*\n+\t * Default to intent-to-add entries invisible in the\n+\t * index. This makes them show up as new files in diff-files\n+\t * and not at all in diff-cached.\n+\t */\n+\trev.diffopt.ita_invisible_in_index = 1;\n+\n \tif (nongit)\n \t\tdie(_(\"Not a git repository\"));\n \targc = setup_revisions(argc, argv, &rev, NULL);\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 78236dc7d8..31bf50082f 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -69,9 +69,9 @@ test_expect_success 'i-t-a entry is simply ignored' '\n \tgit add -N nitfol &&\n \tgit commit -m second &&\n \ttest $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&\n-\ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&\n-\ttest $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&\n-\ttest $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1\n+\ttest $(git diff --name-only --ita-visible-in-index HEAD -- nitfol | wc -l) = 1 &&\n+\ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 0 &&\n+\ttest $(git diff --name-only -- nitfol | wc -l) = 1\n '\n \n test_expect_success 'can commit with an unrelated i-t-a entry in index' '\n@@ -99,13 +99,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '\n \n \t: >dir/bar &&\n \tgit add -N dir/bar &&\n-\tgit diff --cached --name-only >actual &&\n+\tgit diff --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual &&\n \n \tgit write-tree >/dev/null &&\n \n-\tgit diff --cached --name-only >actual &&\n+\tgit diff --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual\n '\n@@ -186,7 +186,19 @@ test_expect_success 'rename detection finds the right names' '\n \t\tcat >expected.3 <<-EOF &&\n \t\t2 .R N... 100644 100644 100644 $hash $hash R100 third\tfirst\n \t\tEOF\n-\t\ttest_cmp expected.3 actual.3\n+\t\ttest_cmp expected.3 actual.3 &&\n+\n+\t\tgit diff --stat >actual.4 &&\n+\t\tcat >expected.4 <<-EOF &&\n+\t\t first => third | 0\n+\t\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\t\tEOF\n+\t\ttest_cmp expected.4 actual.4 &&\n+\n+\t\tgit diff --cached --stat >actual.5 &&\n+\t\t: >expected.5 &&\n+\t\ttest_cmp expected.5 actual.5\n+\n \t)\n '\n \n@@ -222,5 +234,16 @@ test_expect_success 'double rename detection in status' '\n \t)\n '\n \n-test_done\n+test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n+\tgit reset --hard &&\n+\techo new >new-ita &&\n+\tgit add -N new-ita &&\n+\tgit diff --summary >actual &&\n+\techo \" create mode 100644 new-ita\" >expected &&\n+\ttest_cmp expected actual &&\n+\tgit diff --cached --summary >actual2 &&\n+\t: >expected2 &&\n+\ttest_cmp expected2 actual2\n+'\n \n+test_done\ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nindex cf0f3a1ee7..108c012a3a 100755\n--- a/t/t4011-diff-symlink.sh\n+++ b/t/t4011-diff-symlink.sh\n@@ -139,11 +139,13 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '\n test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '\n \tcat >expect <<-\\EOF &&\n \tdiff --git a/file.bin b/file.bin\n-\tindex e69de29..d95f3ad 100644\n-\tBinary files a/file.bin and b/file.bin differ\n+\tnew file mode 100644\n+\tindex 0000000..d95f3ad\n+\tBinary files /dev/null and b/file.bin differ\n \tdiff --git a/link.bin b/link.bin\n-\tindex e69de29..dce41ec 120000\n-\t--- a/link.bin\n+\tnew file mode 120000\n+\tindex 0000000..dce41ec\n+\t--- /dev/null\n \t+++ b/link.bin\n \t@@ -0,0 +1 @@\n \t+file.bin\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"347550","messageId":"20180513175438.32152-2-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180513175438.32152-1-pclouds@gmail.com","subject":"[PATCH 2/2] apply: add --intent-to-add","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-13T17:54:38Z","receivedAt":"2018-05-13T17:55:04Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Similar to 'git reset -N', this option makes 'git apply' automatically\nmark new files as intent-to-add so they are visible in the following\n'git diff' command and could also be committed with 'git commit -a'.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/git-apply.txt |  9 ++++++++-\n apply.c                     | 38 +++++++++++++++++++++++++++++++------\n apply.h                     |  1 +\n t/t2203-add-intent.sh       | 12 ++++++++++++\n 4 files changed, 53 insertions(+), 7 deletions(-)\n\ndiff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt\nindex 4ebc3d3271..2374f64b51 100644\n--- a/Documentation/git-apply.txt\n+++ b/Documentation/git-apply.txt\n@@ -9,7 +9,7 @@ git-apply - Apply a patch to files and/or to the index\n SYNOPSIS\n --------\n [verse]\n-'git apply' [--stat] [--numstat] [--summary] [--check] [--index] [--3way]\n+'git apply' [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]\n \t  [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]\n \t  [--allow-binary-replacement | --binary] [--reject] [-z]\n \t  [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]\n@@ -74,6 +74,13 @@ OPTIONS\n \tcached data, apply the patch, and store the result in the index\n \twithout using the working tree. This implies `--index`.\n \n+--intent-to-add::\n+\tWhen applying the patch only to the working tree, mark new\n+\tfiles to be added to the index later (see `--intent-to-add`\n+\toption in linkgit:git-add[1]). This option is ignored if\n+\t`--index` is present or the command is not run in a Git\n+\trepository.\n+\n -3::\n --3way::\n \tWhen the patch does not apply cleanly, fall back on 3-way merge if\ndiff --git a/apply.c b/apply.c\nindex 7e5792c996..31d3e50401 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -136,6 +136,8 @@ int check_apply_state(struct apply_state *state, int force_apply)\n \t\tstate->apply = 0;\n \tif (state->check_index && is_not_gitdir)\n \t\treturn error(_(\"--index outside a repository\"));\n+\tif (state->set_ita && is_not_gitdir)\n+\t\tstate->set_ita = 0;\n \tif (state->cached) {\n \t\tif (is_not_gitdir)\n \t\t\treturn error(_(\"--cached outside a repository\"));\n@@ -4265,9 +4267,6 @@ static int add_index_file(struct apply_state *state,\n \tint namelen = strlen(path);\n \tunsigned ce_size = cache_entry_size(namelen);\n \n-\tif (!state->update_index)\n-\t\treturn 0;\n-\n \tce = xcalloc(1, ce_size);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_mode = create_ce_mode(mode);\n@@ -4305,6 +4304,27 @@ static int add_index_file(struct apply_state *state,\n \treturn 0;\n }\n \n+static int add_ita_file(struct apply_state *state,\n+\t\t\tconst char *path, unsigned mode)\n+{\n+\tstruct cache_entry *ce;\n+\tint namelen = strlen(path);\n+\tunsigned ce_size = cache_entry_size(namelen);\n+\n+\tce = xcalloc(1, ce_size);\n+\tmemcpy(ce->name, path, namelen);\n+\tce->ce_mode = create_ce_mode(mode);\n+\tce->ce_flags = create_ce_flags(0) | CE_INTENT_TO_ADD;\n+\tce->ce_namelen = namelen;\n+\tset_object_name_for_intent_to_add_entry(ce);\n+\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {\n+\t\tfree(ce);\n+\t\treturn error(_(\"unable to add cache entry for %s\"), path);\n+\t}\n+\n+\treturn 0;\n+}\n+\n /*\n  * Returns:\n  *  -1 if an unrecoverable error happened\n@@ -4465,8 +4485,11 @@ static int create_file(struct apply_state *state, struct patch *patch)\n \n \tif (patch->conflicted_threeway)\n \t\treturn add_conflicted_stages_file(state, patch);\n-\telse\n+\telse if (state->update_index)\n \t\treturn add_index_file(state, path, mode, buf, size);\n+\telse if (state->set_ita)\n+\t\treturn add_ita_file(state, path, mode);\n+\treturn 0;\n }\n \n /* phase zero is to remove, phase one is to create */\n@@ -4687,7 +4710,8 @@ static int apply_patch(struct apply_state *state,\n \t\tstate->apply = 0;\n \n \tstate->update_index = state->check_index && state->apply;\n-\tif (state->update_index && !is_lock_file_locked(&state->lock_file)) {\n+\tif ((state->update_index || state->set_ita) &&\n+\t    !is_lock_file_locked(&state->lock_file)) {\n \t\tif (state->index_file)\n \t\t\thold_lock_file_for_update(&state->lock_file,\n \t\t\t\t\t\t  state->index_file,\n@@ -4888,7 +4912,7 @@ int apply_all_patches(struct apply_state *state,\n \t\t\t\tstate->whitespace_error);\n \t}\n \n-\tif (state->update_index) {\n+\tif (state->update_index || state->set_ita) {\n \t\tres = write_locked_index(&the_index, &state->lock_file, COMMIT_LOCK);\n \t\tif (res) {\n \t\t\terror(_(\"Unable to write new index file\"));\n@@ -4941,6 +4965,8 @@ int apply_parse_options(int argc, const char **argv,\n \t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n \t\tOPT_BOOL(0, \"index\", &state->check_index,\n \t\t\tN_(\"make sure the patch is applicable to the current index\")),\n+\t\tOPT_BOOL('N', \"intent-to-add\", &state->set_ita,\n+\t\t\tN_(\"mark new files with `git add --intent-to-add`\")),\n \t\tOPT_BOOL(0, \"cached\", &state->cached,\n \t\t\tN_(\"apply a patch without touching the working tree\")),\n \t\tOPT_BOOL_F(0, \"unsafe-paths\", &state->unsafe_paths,\ndiff --git a/apply.h b/apply.h\nindex dc4a019057..94b38533a2 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -45,6 +45,7 @@ struct apply_state {\n \tint check; /* preimage must match working tree, don't actually apply */\n \tint check_index; /* preimage must match the indexed version */\n \tint update_index; /* check_index && apply */\n+\tint set_ita;\t  /* add intent-to-add entries to the index */\n \n \t/* These control cosmetic aspect of the output */\n \tint diffstat; /* just show a diffstat, and don't actually apply */\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 31bf50082f..1d640a33f0 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -246,4 +246,16 @@ test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n \ttest_cmp expected2 actual2\n '\n \n+test_expect_success 'apply --intent-to-add' '\n+\tgit reset --hard &&\n+\techo new >new-ita &&\n+\tgit add -N new-ita &&\n+\tgit diff >expected &&\n+\tgrep \"new file\" expected &&\n+\tgit reset --hard &&\n+\tgit apply --intent-to-add expected &&\n+\tgit diff >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"347564","messageId":"xmqqo9hjc6er.fsf@gitster-ct.c.googlers.com","threadId":"48482","inReplyTo":"20180513175438.32152-2-pclouds@gmail.com","subject":"Re: [PATCH 2/2] apply: add --intent-to-add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-14T02:33:48Z","receivedAt":"2018-05-14T02:33:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:\n\n> Similar to 'git reset -N', this option makes 'git apply' automatically\n> mark new files as intent-to-add so they are visible in the following\n> 'git diff' command and could also be committed with 'git commit -a'.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  Documentation/git-apply.txt |  9 ++++++++-\n>  apply.c                     | 38 +++++++++++++++++++++++++++++++------\n>  apply.h                     |  1 +\n>  t/t2203-add-intent.sh       | 12 ++++++++++++\n>  4 files changed, 53 insertions(+), 7 deletions(-)\n>\n> diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt\n> index 4ebc3d3271..2374f64b51 100644\n> --- a/Documentation/git-apply.txt\n> +++ b/Documentation/git-apply.txt\n> @@ -9,7 +9,7 @@ git-apply - Apply a patch to files and/or to the index\n>  SYNOPSIS\n>  --------\n>  [verse]\n> -'git apply' [--stat] [--numstat] [--summary] [--check] [--index] [--3way]\n> +'git apply' [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]\n>  \t  [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]\n>  \t  [--allow-binary-replacement | --binary] [--reject] [-z]\n>  \t  [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]\n> @@ -74,6 +74,13 @@ OPTIONS\n>  \tcached data, apply the patch, and store the result in the index\n>  \twithout using the working tree. This implies `--index`.\n>  \n> +--intent-to-add::\n> +\tWhen applying the patch only to the working tree, mark new\n> +\tfiles to be added to the index later (see `--intent-to-add`\n> +\toption in linkgit:git-add[1]). This option is ignored if\n> +\t`--index` is present or the command is not run in a Git\n> +\trepository.\n\nIt may make sense to make it incompatible with \"--index\" like you\ndid, but how does this interact with \"--cached\" or \"--3way\"?  It is\nunclear from the above documentation.\n\n> diff --git a/apply.c b/apply.c\n> index 7e5792c996..31d3e50401 100644\n> --- a/apply.c\n> +++ b/apply.c\n> @@ -136,6 +136,8 @@ int check_apply_state(struct apply_state *state, int force_apply)\n>  \t\tstate->apply = 0;\n>  \tif (state->check_index && is_not_gitdir)\n>  \t\treturn error(_(\"--index outside a repository\"));\n> +\tif (state->set_ita && is_not_gitdir)\n> +\t\tstate->set_ita = 0;\n\nI think this should error out, just like one line above does.\n\"I-t-a\" is impossible without having the index, just like \"--index\"\nis impossible without having the index.\n\n> @@ -4265,9 +4267,6 @@ static int add_index_file(struct apply_state *state,\n>  \tint namelen = strlen(path);\n>  \tunsigned ce_size = cache_entry_size(namelen);\n>  \n> -\tif (!state->update_index)\n> -\t\treturn 0;\n> -\n\nOK, with this change, only \"index-affecting\" mode will call into the\nfunction, in the first place.  The current code was wasteful in that\nthe caller always called and forced this function to do a few useless\ncomputation before it realized that it is not going to touch the index\nat all.\n\n> @@ -4305,6 +4304,27 @@ static int add_index_file(struct apply_state *state,\n>  \treturn 0;\n>  }\n>  \n> +static int add_ita_file(struct apply_state *state,\n> +\t\t\tconst char *path, unsigned mode)\n> +{\n> +\tstruct cache_entry *ce;\n> +\tint namelen = strlen(path);\n> +\tunsigned ce_size = cache_entry_size(namelen);\n> +\n> +\tce = xcalloc(1, ce_size);\n> +\tmemcpy(ce->name, path, namelen);\n> +\tce->ce_mode = create_ce_mode(mode);\n> +\tce->ce_flags = create_ce_flags(0) | CE_INTENT_TO_ADD;\n> +\tce->ce_namelen = namelen;\n> +\tset_object_name_for_intent_to_add_entry(ce);\n> +\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0) {\n> +\t\tfree(ce);\n> +\t\treturn error(_(\"unable to add cache entry for %s\"), path);\n> +\t}\n> +\n> +\treturn 0;\n> +}\n\nIt is somewhat unsatisfactory that we need a whole new function to\nrecord a new path in the index.  IOW, I have a feeling that a bit of\nrefactoring of add_index_file() should allow us to share more code\nbetween it and this new function.\n\n> @@ -4465,8 +4485,11 @@ static int create_file(struct apply_state *state, struct patch *patch)\n>  \n>  \tif (patch->conflicted_threeway)\n>  \t\treturn add_conflicted_stages_file(state, patch);\n> -\telse\n> +\telse if (state->update_index)\n>  \t\treturn add_index_file(state, path, mode, buf, size);\n> +\telse if (state->set_ita)\n> +\t\treturn add_ita_file(state, path, mode);\n> +\treturn 0;\n\nIt is very unfortunate that you need to do (update_index||set_ita)\neverywhere else only bevause you want to do this else/if cascade.\nI'd rather redefine the bits to mean\n\n    - update-index: we will do something that touches the index\n      (hence we need to have the repository, we need to lock the\n      index, etc.).\n\n    - ita-only: changes to the existing paths are only reflected to\n      the working tree, but new paths are added to the index as\n      i-t-a entries.\n\nand make add_index_file() more intelligent, without having to add a\nnew add_ita_file().\n\nOf course, setting only ita-only without setting update-index is an\ninconsistent state.  \"--index\" would set only update-index, \"--ita\"\nwould set both, \"--ita --index\" would either be an error, or set\nonly update-index and clear ita-only if we adopt \"last one wins\"\nsemantics.\n\n"},{"id":"348081","messageId":"20180520063424.GA3062@duynguyen.home","threadId":"48482","inReplyTo":"xmqqo9hjc6er.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH 2/2] apply: add --intent-to-add","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-20T06:34:24Z","receivedAt":"2018-05-20T06:34:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, May 14, 2018 at 11:33:48AM +0900, Junio C Hamano wrote:\n> > diff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt\n> > index 4ebc3d3271..2374f64b51 100644\n> > --- a/Documentation/git-apply.txt\n> > +++ b/Documentation/git-apply.txt\n> > @@ -9,7 +9,7 @@ git-apply - Apply a patch to files and/or to the index\n> >  SYNOPSIS\n> >  --------\n> >  [verse]\n> > -'git apply' [--stat] [--numstat] [--summary] [--check] [--index] [--3way]\n> > +'git apply' [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]\n> >  \t  [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]\n> >  \t  [--allow-binary-replacement | --binary] [--reject] [-z]\n> >  \t  [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]\n> > @@ -74,6 +74,13 @@ OPTIONS\n> >  \tcached data, apply the patch, and store the result in the index\n> >  \twithout using the working tree. This implies `--index`.\n> >  \n> > +--intent-to-add::\n> > +\tWhen applying the patch only to the working tree, mark new\n> > +\tfiles to be added to the index later (see `--intent-to-add`\n> > +\toption in linkgit:git-add[1]). This option is ignored if\n> > +\t`--index` is present or the command is not run in a Git\n> > +\trepository.\n> \n> It may make sense to make it incompatible with \"--index\" like you\n> did, but how does this interact with \"--cached\" or \"--3way\"?  It is\n> unclear from the above documentation.\n\nI did check --cached and it mentioned about implying --index so I\nthought that was enough. Will elaborate a bit more.\n\n> > diff --git a/apply.c b/apply.c\n> > index 7e5792c996..31d3e50401 100644\n> > --- a/apply.c\n> > +++ b/apply.c\n> > @@ -136,6 +136,8 @@ int check_apply_state(struct apply_state *state, int force_apply)\n> >  \t\tstate->apply = 0;\n> >  \tif (state->check_index && is_not_gitdir)\n> >  \t\treturn error(_(\"--index outside a repository\"));\n> > +\tif (state->set_ita && is_not_gitdir)\n> > +\t\tstate->set_ita = 0;\n> \n> I think this should error out, just like one line above does.\n> \"I-t-a\" is impossible without having the index, just like \"--index\"\n> is impossible without having the index.\n\nI was hoping to put this in an alias that works both with or without a\nrepository. Do you feel strongly about this? I may need to find\nanother way to achieve that instead.\n--\nDuy\n"},{"id":"348176","messageId":"xmqqa7st3dk4.fsf@gitster-ct.c.googlers.com","threadId":"48482","inReplyTo":"20180520063424.GA3062@duynguyen.home","subject":"Re: [PATCH 2/2] apply: add --intent-to-add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-05-21T03:14:35Z","receivedAt":"2018-05-21T03:14:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Duy Nguyen <pclouds@gmail.com> writes:\n\n>> >  \tif (state->check_index && is_not_gitdir)\n>> >  \t\treturn error(_(\"--index outside a repository\"));\n>> > +\tif (state->set_ita && is_not_gitdir)\n>> > +\t\tstate->set_ita = 0;\n>> \n>> I think this should error out, just like one line above does.\n>> \"I-t-a\" is impossible without having the index, just like \"--index\"\n>> is impossible without having the index.\n>\n> I was hoping to put this in an alias that works both with or without a\n> repository. Do you feel strongly about this? \n\n\"git apply --index\" that silently applied only to the filesystem\nfiles without telling me that I am in a wrong directory by mistake\nis a UI disaster, and that is what the existing error we see in the\npre context is about.  I do not think of a good reason why \"git\napply --i-t-a\" should behave any differently.\n\n"},{"id":"348512","messageId":"20180525033942.GA234191@aiede.svl.corp.google.com","threadId":"48482","inReplyTo":"20180513175438.32152-1-pclouds@gmail.com","subject":"Re: [PATCH 1/2] diff: turn --ita-invisible-in-index on by default","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2018-05-25T03:39:42Z","receivedAt":"2018-05-25T03:39:57Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Duy,\n\nNguyễn Thái Ngọc Duy wrote:\n\n> Due to the implementation detail of intent-to-add entries. The current\n> \"git diff\" (i.e. no treeish or --cached argument) would show the\n> changes in the i-t-a file, but it does not mark the file as new, while\n> \"diff --cached\" would mark the file as new while showing its content\n> as empty.\n>\n> One evidence of the current output being wrong is that, the output\n> from \"git diff\" (with ita entries) cannot be applied because it\n> assumes empty files exist before applying.\n>\n> Turning on --ita-invisible-in-index [1] [2] would fix this.\n\nI'm having a lot of trouble understanding the above.  Part of my\nconfusion may be grammatical: for example, the first sentence is a\nsentence fragment.  Another part is that the commit message doesn't tell\nme a story: what does the user try to do and fail that is not possible\nwithout this?  What is the intention or effect behind the commits\nmentioned that leads to them being cited?\n\nTo put it another way, the basic aspects I look for in a commit message\nare:\n\n - the motivation behind the change (a wrong behavior, a task that isn't\n   possible, some excessive complexity, or whatever).  The reader\n   doesn't know your motivation so their default attitude will be to\n   assume that nothing should change\n\n - a little more detail about the why and how behind the current\n   behavior, to put the proposed in context.  This makes it easier for\n   the reader to understand how the change will affect users of that\n   behavior that don't necessarily have the same motivation.\n\n   An example illustrating the behavior can work well here.\n\n - any interesting details of implementation or alternatives considered\n   that can make the patch easier to read now that the motivation is out\n   of the way.\n\n - a word or two on what this makes possible\n\nI'm having trouble pulling apart these pieces in this commit message.\nCan you give an example of a command's output before and after this change\nso I can understand better why it's a good one?\n\n> This option is on by default in git-status [1] but we need more fixup\n> in rename detection code [3]. Luckily we don't need to do anything\n> else for the rename detection code in diff.c (wt-status.c uses a\n> customized one).\n>\n> [1] 425a28e0a4 (diff-lib: allow ita entries treated as \"not yet exist\n>     in index\" - 2016-10-24)\n> [2] b42b451919 (diff: add --ita-[in]visible-in-index - 2016-10-24)\n> [3] bc3dca07f4 (Merge branch 'nd/ita-wt-renames-in-status' - 2018-01-23)\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  builtin/diff.c          |  7 +++++++\n>  t/t2203-add-intent.sh   | 37 ++++++++++++++++++++++++++++++-------\n>  t/t4011-diff-symlink.sh | 10 ++++++----\n>  3 files changed, 43 insertions(+), 11 deletions(-)\n\nThis flips the default as announced but I'm not sure yet whether it's\na good thing.  After all, an intent-to-add entry is a real entry in\nthe index; why wouldn't it show up in \"git diff --cached\"?\n\nIs the idea that it shouldn't show up there because \"git commit\" would\nnot include the intent-to-add entry?  That makes some sense to me.\n\nWhat does the endgame look like?  Would we flip the default to\n--ita-invisible and then remove the option?\n\nContext is that an internal script does something like\n\n\techo 'This file is added!' >added\n\tgit add --intent-to-add added\n\tgit diff --name-only --no-renames --diff-filter=A master\n\nto list added files and started failing with this patch (in \"next\").\nArguably the script should use diff-index for a stronger stability\nguarantee.  Should the script use --ita-visible as a futureproofing\nmeasure as well?\n\nActually, why is this \"git diff\" output changing at all, given that\nthe script doesn't pass --cached?  I would expect \"git diff\" to show\nthe ITA entry because it affects the result of \"git commit -a\".\n\nThanks,\nJonathan\n"},{"id":"348542","messageId":"20180525143042.GA10607@duynguyen.home","threadId":"48482","inReplyTo":"20180525033942.GA234191@aiede.svl.corp.google.com","subject":"Re: [PATCH 1/2] diff: turn --ita-invisible-in-index on by default","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-25T14:30:42Z","receivedAt":"2018-05-25T14:30:50Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, May 24, 2018 at 08:39:42PM -0700, Jonathan Nieder wrote:\n> Hi Duy,\n> \n> Nguyễn Thái Ngọc Duy wrote:\n> \n> > Due to the implementation detail of intent-to-add entries. The current\n> > \"git diff\" (i.e. no treeish or --cached argument) would show the\n> > changes in the i-t-a file, but it does not mark the file as new, while\n> > \"diff --cached\" would mark the file as new while showing its content\n> > as empty.\n> >\n> > One evidence of the current output being wrong is that, the output\n> > from \"git diff\" (with ita entries) cannot be applied because it\n> > assumes empty files exist before applying.\n> >\n> > Turning on --ita-invisible-in-index [1] [2] would fix this.\n> \n> I'm having a lot of trouble understanding the above.  Part of my\n> confusion may be grammatical: for example, the first sentence is a\n> sentence fragment.  Another part is that the commit message doesn't tell\n> me a story: what does the user try to do and fail that is not possible\n> without this?  What is the intention or effect behind the commits\n> mentioned that leads to them being cited?\n>\n> ...\n\nSorry, this i-t-a thing had been on my mind for too long I mistakenly\nthought this problem was common knowledge. Reference [1] in that\ncommit points to a previous attempt d95d728aba (diff-lib.c: adjust\nposition of i-t-a entries in diff - 2015-03-16) that was reverted,\nwhich gives more info.\n\nAnyway this is the diff we see today\n\n    $ echo haha > new; git add -N\n    $ git diff\n    diff --git a/new b/new\n    index e69de29..5ad28e2 100644\n    --- a/new\n    +++ b/new\n    @@ -0,0 +1 @@\n    +haha\n\nNotice that the diff does not tell you that 'new' is a new file. The\ndiff with this patch gives you this\n\n    $ git diff\n    diff --git a/new b/new\n    new file mode 100644\n    index 0000000..5ad28e2\n    --- /dev/null\n    +++ b/new\n    @@ -0,0 +1 @@\n    +haha\n\nYou may argue that an intent-to-add entry is a real entry in the index\nand showing \"new file mode 100644\" here is wrong. I beg to differ.\nThat just happens to be how you mark an ita entry. If Junio chose to\nrecord ita entries as an index extension, then they would not be\n\"real\" and could still be used to remind users about things to add.\n\nFrom the user perspective, as a user I do not care if it's a \"real\nentry\". I want git to _remind_ myself that I need to add that\nfile. That file should not truly exist in the index because I have not\nactually added it. I did not tell git to add anything to the index.\n\nOne consequence of this is you can't apply the diff generated with ita\nentries because the diff expects empty files to be already in the\nworktree. This to me does not make sense.\n\nOf course there's other things that also go along this line. Like if\n\"git commit\" does not add an ita entry, why should it appear in 'git\ndiff --cached', which should show you what's to be committed. Right\nknow it shows\n\n\n    $ git diff --cached\n    diff --git a/new b/new\n    new file mode 100644\n    index 0000000..e69de29\n\nwhich to me is ridiculous. Why would it show me a diff of a new file\nwith empty content? I as a user have not mentioned \"empty content\"\nanywhere through the commands I have used.\n\nSince this commit is already in 'next', it's too late to update the\ncommit message now. Maybe I can elaborate about this more in\ngit-add.txt if needed (and then I can add more explanation in the\ncommit message that updates that file).\n--\nDuy\n"},{"id":"348545","messageId":"20180525164351.GA192362@aiede.svl.corp.google.com","threadId":"48482","inReplyTo":"20180525143042.GA10607@duynguyen.home","subject":"Re: [PATCH 1/2] diff: turn --ita-invisible-in-index on by default","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2018-05-25T16:43:51Z","receivedAt":"2018-05-25T16:44:03Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nDuy Nguyen wrote:\n\n>     $ echo haha > new; git add -N\n>     $ git diff\n>     diff --git a/new b/new\n>     index e69de29..5ad28e2 100644\n>     --- a/new\n>     +++ b/new\n>     @@ -0,0 +1 @@\n>     +haha\n>\n> Notice that the diff does not tell you that 'new' is a new file. The\n> diff with this patch gives you this\n>\n>     $ git diff\n>     diff --git a/new b/new\n>     new file mode 100644\n>     index 0000000..5ad28e2\n>     --- /dev/null\n>     +++ b/new\n>     @@ -0,0 +1 @@\n>     +haha\n[...]\n> One consequence of this is you can't apply the diff generated with ita\n> entries because the diff expects empty files to be already in the\n> worktree. This to me does not make sense.\n>\n> Of course there's other things that also go along this line. Like if\n> \"git commit\" does not add an ita entry, why should it appear in 'git\n> diff --cached', which should show you what's to be committed.\n\nThankds for this context.  That helps a lot.\n\n[...]\n> Since this commit is already in 'next', it's too late to update the\n> commit message now.\n\nI think it should be reverted from 'next' because of the unintended\nchange to the behavior of \"git diff HEAD\".  Here is what I have\napplied internally.\n\n-- >8 -- \nSubject: Revert \"diff: turn --ita-invisible-in-index on by default\"\n\nThis reverts commit 992118dd95b052bc82a795fd3a8978bea0fe5c0e.  That\nchange is promising, since it improves the behavior of \"git diff\" and\n\"git diff --cached\" by correctly showing an intent-to-add entry as no\nfile.  Unfortunately, though, it breaks \"git diff HEAD\" in the\nprocess:\n\n\techo hi >new-file\n\tgit add -N new-file\n\tgit diff HEAD\n\nBefore: shows addition of the new file\nAfter: shows no change\n\nNoticed because the new --ita-invisible-in-index default broke a\nscript using \"git diff --name-only --diff-filter=A master\" to get a\nlist of added files.  Arguably that script should use diff-index\ninstead, which would have sidestepped the issue, but the new behavior\nis unexpected in interactive use as well.\n\nSigned-off-by: Jonathan Nieder <jrnieder@gmail.com>\n---\n builtin/diff.c          |  7 -------\n t/t2203-add-intent.sh   | 40 ++++++++--------------------------------\n t/t4011-diff-symlink.sh | 10 ++++------\n 3 files changed, 12 insertions(+), 45 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex b709b6e984..bfefff3a84 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -352,13 +352,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \trev.diffopt.flags.allow_external = 1;\n \trev.diffopt.flags.allow_textconv = 1;\n \n-\t/*\n-\t * Default to intent-to-add entries invisible in the\n-\t * index. This makes them show up as new files in diff-files\n-\t * and not at all in diff-cached.\n-\t */\n-\trev.diffopt.ita_invisible_in_index = 1;\n-\n \tif (nongit)\n \t\tdie(_(\"Not a git repository\"));\n \targc = setup_revisions(argc, argv, &rev, NULL);\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 1d640a33f0..d9fb151d52 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -69,9 +69,9 @@ test_expect_success 'i-t-a entry is simply ignored' '\n \tgit add -N nitfol &&\n \tgit commit -m second &&\n \ttest $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&\n-\ttest $(git diff --name-only --ita-visible-in-index HEAD -- nitfol | wc -l) = 1 &&\n-\ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 0 &&\n-\ttest $(git diff --name-only -- nitfol | wc -l) = 1\n+\ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&\n+\ttest $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&\n+\ttest $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1\n '\n \n test_expect_success 'can commit with an unrelated i-t-a entry in index' '\n@@ -99,13 +99,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '\n \n \t: >dir/bar &&\n \tgit add -N dir/bar &&\n-\tgit diff --name-only >actual &&\n+\tgit diff --cached --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual &&\n \n \tgit write-tree >/dev/null &&\n \n-\tgit diff --name-only >actual &&\n+\tgit diff --cached --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual\n '\n@@ -186,19 +186,7 @@ test_expect_success 'rename detection finds the right names' '\n \t\tcat >expected.3 <<-EOF &&\n \t\t2 .R N... 100644 100644 100644 $hash $hash R100 third\tfirst\n \t\tEOF\n-\t\ttest_cmp expected.3 actual.3 &&\n-\n-\t\tgit diff --stat >actual.4 &&\n-\t\tcat >expected.4 <<-EOF &&\n-\t\t first => third | 0\n-\t\t 1 file changed, 0 insertions(+), 0 deletions(-)\n-\t\tEOF\n-\t\ttest_cmp expected.4 actual.4 &&\n-\n-\t\tgit diff --cached --stat >actual.5 &&\n-\t\t: >expected.5 &&\n-\t\ttest_cmp expected.5 actual.5\n-\n+\t\ttest_cmp expected.3 actual.3\n \t)\n '\n \n@@ -234,27 +222,15 @@ test_expect_success 'double rename detection in status' '\n \t)\n '\n \n-test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n-\tgit reset --hard &&\n-\techo new >new-ita &&\n-\tgit add -N new-ita &&\n-\tgit diff --summary >actual &&\n-\techo \" create mode 100644 new-ita\" >expected &&\n-\ttest_cmp expected actual &&\n-\tgit diff --cached --summary >actual2 &&\n-\t: >expected2 &&\n-\ttest_cmp expected2 actual2\n-'\n-\n test_expect_success 'apply --intent-to-add' '\n \tgit reset --hard &&\n \techo new >new-ita &&\n \tgit add -N new-ita &&\n-\tgit diff >expected &&\n+\tgit diff --ita-invisible-in-index >expected &&\n \tgrep \"new file\" expected &&\n \tgit reset --hard &&\n \tgit apply --intent-to-add expected &&\n-\tgit diff >actual &&\n+\tgit diff --ita-invisible-in-index >actual &&\n \ttest_cmp expected actual\n '\n \ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nindex 108c012a3a..cf0f3a1ee7 100755\n--- a/t/t4011-diff-symlink.sh\n+++ b/t/t4011-diff-symlink.sh\n@@ -139,13 +139,11 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '\n test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '\n \tcat >expect <<-\\EOF &&\n \tdiff --git a/file.bin b/file.bin\n-\tnew file mode 100644\n-\tindex 0000000..d95f3ad\n-\tBinary files /dev/null and b/file.bin differ\n+\tindex e69de29..d95f3ad 100644\n+\tBinary files a/file.bin and b/file.bin differ\n \tdiff --git a/link.bin b/link.bin\n-\tnew file mode 120000\n-\tindex 0000000..dce41ec\n-\t--- /dev/null\n+\tindex e69de29..dce41ec 120000\n+\t--- a/link.bin\n \t+++ b/link.bin\n \t@@ -0,0 +1 @@\n \t+file.bin\n-- \n2.17.0.921.gf22659ad46\n\n"},{"id":"348546","messageId":"CACsJy8Bit2QcVMTnKfSuUjXbxnjHMLLd5LjV36zbnQyc=7c8Wg@mail.gmail.com","threadId":"48482","inReplyTo":"20180525164351.GA192362@aiede.svl.corp.google.com","subject":"Re: [PATCH 1/2] diff: turn --ita-invisible-in-index on by default","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-25T16:59:01Z","receivedAt":"2018-05-25T16:59:35Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Fri, May 25, 2018 at 6:43 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> I think it should be reverted from 'next' because of the unintended\n> change to the behavior of \"git diff HEAD\".\n\nAh. That is indeed unintended. I still don't know how this change\naffects that (but that's probably why it slipped through in the first\nplace). While there, perhaps you could add a test in t2203 just to\nmake sure I will not break it again in the next attempt?\n\nI agree that it should be reverted. Or if it's possible to eject it\nfrom next, then it's even better since I will need to fix up the\nsecond patch in that series anyway. Junio?\n\n> Here is what I have applied internally.\n>\n> -- >8 --\n> Subject: Revert \"diff: turn --ita-invisible-in-index on by default\"\n>\n> This reverts commit 992118dd95b052bc82a795fd3a8978bea0fe5c0e.  That\n> change is promising, since it improves the behavior of \"git diff\" and\n> \"git diff --cached\" by correctly showing an intent-to-add entry as no\n> file.  Unfortunately, though, it breaks \"git diff HEAD\" in the\n> process:\n>\n>         echo hi >new-file\n>         git add -N new-file\n>         git diff HEAD\n>\n> Before: shows addition of the new file\n> After: shows no change\n>\n> Noticed because the new --ita-invisible-in-index default broke a\n> script using \"git diff --name-only --diff-filter=A master\" to get a\n> list of added files.  Arguably that script should use diff-index\n> instead, which would have sidestepped the issue, but the new behavior\n> is unexpected in interactive use as well.\n>\n> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>\n> ---\n>  builtin/diff.c          |  7 -------\n>  t/t2203-add-intent.sh   | 40 ++++++++--------------------------------\n>  t/t4011-diff-symlink.sh | 10 ++++------\n>  3 files changed, 12 insertions(+), 45 deletions(-)\n>\n> diff --git a/builtin/diff.c b/builtin/diff.c\n> index b709b6e984..bfefff3a84 100644\n> --- a/builtin/diff.c\n> +++ b/builtin/diff.c\n> @@ -352,13 +352,6 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n>         rev.diffopt.flags.allow_external = 1;\n>         rev.diffopt.flags.allow_textconv = 1;\n>\n> -       /*\n> -        * Default to intent-to-add entries invisible in the\n> -        * index. This makes them show up as new files in diff-files\n> -        * and not at all in diff-cached.\n> -        */\n> -       rev.diffopt.ita_invisible_in_index = 1;\n> -\n>         if (nongit)\n>                 die(_(\"Not a git repository\"));\n>         argc = setup_revisions(argc, argv, &rev, NULL);\n> diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\n> index 1d640a33f0..d9fb151d52 100755\n> --- a/t/t2203-add-intent.sh\n> +++ b/t/t2203-add-intent.sh\n> @@ -69,9 +69,9 @@ test_expect_success 'i-t-a entry is simply ignored' '\n>         git add -N nitfol &&\n>         git commit -m second &&\n>         test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&\n> -       test $(git diff --name-only --ita-visible-in-index HEAD -- nitfol | wc -l) = 1 &&\n> -       test $(git diff --name-only HEAD -- nitfol | wc -l) = 0 &&\n> -       test $(git diff --name-only -- nitfol | wc -l) = 1\n> +       test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&\n> +       test $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&\n> +       test $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1\n>  '\n>\n>  test_expect_success 'can commit with an unrelated i-t-a entry in index' '\n> @@ -99,13 +99,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '\n>\n>         : >dir/bar &&\n>         git add -N dir/bar &&\n> -       git diff --name-only >actual &&\n> +       git diff --cached --name-only >actual &&\n>         echo dir/bar >expect &&\n>         test_cmp expect actual &&\n>\n>         git write-tree >/dev/null &&\n>\n> -       git diff --name-only >actual &&\n> +       git diff --cached --name-only >actual &&\n>         echo dir/bar >expect &&\n>         test_cmp expect actual\n>  '\n> @@ -186,19 +186,7 @@ test_expect_success 'rename detection finds the right names' '\n>                 cat >expected.3 <<-EOF &&\n>                 2 .R N... 100644 100644 100644 $hash $hash R100 third   first\n>                 EOF\n> -               test_cmp expected.3 actual.3 &&\n> -\n> -               git diff --stat >actual.4 &&\n> -               cat >expected.4 <<-EOF &&\n> -                first => third | 0\n> -                1 file changed, 0 insertions(+), 0 deletions(-)\n> -               EOF\n> -               test_cmp expected.4 actual.4 &&\n> -\n> -               git diff --cached --stat >actual.5 &&\n> -               : >expected.5 &&\n> -               test_cmp expected.5 actual.5\n> -\n> +               test_cmp expected.3 actual.3\n>         )\n>  '\n>\n> @@ -234,27 +222,15 @@ test_expect_success 'double rename detection in status' '\n>         )\n>  '\n>\n> -test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n> -       git reset --hard &&\n> -       echo new >new-ita &&\n> -       git add -N new-ita &&\n> -       git diff --summary >actual &&\n> -       echo \" create mode 100644 new-ita\" >expected &&\n> -       test_cmp expected actual &&\n> -       git diff --cached --summary >actual2 &&\n> -       : >expected2 &&\n> -       test_cmp expected2 actual2\n> -'\n> -\n>  test_expect_success 'apply --intent-to-add' '\n>         git reset --hard &&\n>         echo new >new-ita &&\n>         git add -N new-ita &&\n> -       git diff >expected &&\n> +       git diff --ita-invisible-in-index >expected &&\n>         grep \"new file\" expected &&\n>         git reset --hard &&\n>         git apply --intent-to-add expected &&\n> -       git diff >actual &&\n> +       git diff --ita-invisible-in-index >actual &&\n>         test_cmp expected actual\n>  '\n>\n> diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\n> index 108c012a3a..cf0f3a1ee7 100755\n> --- a/t/t4011-diff-symlink.sh\n> +++ b/t/t4011-diff-symlink.sh\n> @@ -139,13 +139,11 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '\n>  test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '\n>         cat >expect <<-\\EOF &&\n>         diff --git a/file.bin b/file.bin\n> -       new file mode 100644\n> -       index 0000000..d95f3ad\n> -       Binary files /dev/null and b/file.bin differ\n> +       index e69de29..d95f3ad 100644\n> +       Binary files a/file.bin and b/file.bin differ\n>         diff --git a/link.bin b/link.bin\n> -       new file mode 120000\n> -       index 0000000..dce41ec\n> -       --- /dev/null\n> +       index e69de29..dce41ec 120000\n> +       --- a/link.bin\n>         +++ b/link.bin\n>         @@ -0,0 +1 @@\n>         +file.bin\n> --\n> 2.17.0.921.gf22659ad46\n-- \nDuy\n"},{"id":"348584","messageId":"20180526120846.23663-1-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180513175438.32152-1-pclouds@gmail.com","subject":"[PATCH v2 0/4] Fix i-t-a entries in git-diff and git-apply","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-26T12:08:42Z","receivedAt":"2018-05-26T12:08:56Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"v2 first fixes a bug in --ita-invisible-in-index that accidentally\naffects diffing a worktree and a tree. This caused a regression when\nv1's 1/2 turned this option on by default.\n\nOther than that, 4/4 should address Junio's comments on v1's 2/2.\n\nNguyễn Thái Ngọc Duy (4):\n  diff: ignore --ita-[in]visible-in-index when diffing worktree-to-tree\n  diff: turn --ita-invisible-in-index on by default\n  t2203: add a test about \"diff HEAD\" case\n  apply: add --intent-to-add\n\n Documentation/git-apply.txt | 10 +++++-\n apply.c                     | 19 +++++++----\n apply.h                     |  1 +\n builtin/diff.c              |  7 ++++\n diff-lib.c                  |  8 +++--\n t/t2203-add-intent.sh       | 64 +++++++++++++++++++++++++++++++++----\n t/t4011-diff-symlink.sh     | 10 +++---\n 7 files changed, 99 insertions(+), 20 deletions(-)\n\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348585","messageId":"20180526120846.23663-3-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180526120846.23663-1-pclouds@gmail.com","subject":"[PATCH v2 2/4] diff: turn --ita-invisible-in-index on by default","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-26T12:08:44Z","receivedAt":"2018-05-26T12:08:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Due to the implementation detail of intent-to-add entries, the current\n\"git diff\" (i.e. no treeish or --cached argument) would show the\nchanges in the i-t-a file, but it does not mark the file as new, while\n\"diff --cached\" would mark the file as new while showing its content\nas empty.\n\n     $ git diff                     | $ diff --cached\n    --------------------------------|-------------------------------\n     diff --git a/new b/new         | diff --git a/new b/new\n     index e69de29..5ad28e2 100644  | new file mode 100644\n     --- a/new                      | index 0000000..e69de29\n     +++ b/new                      |\n     @@ -0,0 +1 @@                  |\n     +haha                          |\n\nOne evidence of the current output being wrong is that, the output\nfrom \"git diff\" (with ita entries) cannot be applied because it\nassumes empty files exist before applying.\n\nTurning on --ita-invisible-in-index [1] [2] would fix this. The result\nis \"new file\" line moving from \"git diff --cached\" to \"git diff\".\n\n     $ git diff                     | $ diff --cached\n    --------------------------------|-------------------------------\n     diff --git a/new b/new         |\n     new file mode 100644           |\n     index 0000000..5ad28e2         |\n     --- /dev/null                  |\n     +++ b/new                      |\n     @@ -0,0 +1 @@                  |\n     +haha                          |\n\nThis option is on by default in git-status [1] but we need more fixup\nin rename detection code [3]. Luckily we don't need to do anything\nelse for the rename detection code in diff.c (wt-status.c uses a\ncustomized one).\n\n[1] 425a28e0a4 (diff-lib: allow ita entries treated as \"not yet exist\n    in index\" - 2016-10-24)\n[2] b42b451919 (diff: add --ita-[in]visible-in-index - 2016-10-24)\n[3] bc3dca07f4 (Merge branch 'nd/ita-wt-renames-in-status' - 2018-01-23)\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin/diff.c          |  7 +++++++\n t/t2203-add-intent.sh   | 34 ++++++++++++++++++++++++++++------\n t/t4011-diff-symlink.sh | 10 ++++++----\n 3 files changed, 41 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/diff.c b/builtin/diff.c\nindex 16bfb22f73..00424c296d 100644\n--- a/builtin/diff.c\n+++ b/builtin/diff.c\n@@ -352,6 +352,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)\n \trev.diffopt.flags.allow_external = 1;\n \trev.diffopt.flags.allow_textconv = 1;\n \n+\t/*\n+\t * Default to intent-to-add entries invisible in the\n+\t * index. This makes them show up as new files in diff-files\n+\t * and not at all in diff-cached.\n+\t */\n+\trev.diffopt.ita_invisible_in_index = 1;\n+\n \tif (nongit)\n \t\tdie(_(\"Not a git repository\"));\n \targc = setup_revisions(argc, argv, &rev, NULL);\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 3ab07cb404..1115347712 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -70,8 +70,7 @@ test_expect_success 'i-t-a entry is simply ignored' '\n \tgit commit -m second &&\n \ttest $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&\n \ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&\n-\ttest $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 1 &&\n-\ttest $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1\n+\ttest $(git diff --name-only -- nitfol | wc -l) = 1\n '\n \n test_expect_success 'can commit with an unrelated i-t-a entry in index' '\n@@ -99,13 +98,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '\n \n \t: >dir/bar &&\n \tgit add -N dir/bar &&\n-\tgit diff --cached --name-only >actual &&\n+\tgit diff --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual &&\n \n \tgit write-tree >/dev/null &&\n \n-\tgit diff --cached --name-only >actual &&\n+\tgit diff --name-only >actual &&\n \techo dir/bar >expect &&\n \ttest_cmp expect actual\n '\n@@ -186,7 +185,19 @@ test_expect_success 'rename detection finds the right names' '\n \t\tcat >expected.3 <<-EOF &&\n \t\t2 .R N... 100644 100644 100644 $hash $hash R100 third\tfirst\n \t\tEOF\n-\t\ttest_cmp expected.3 actual.3\n+\t\ttest_cmp expected.3 actual.3 &&\n+\n+\t\tgit diff --stat >actual.4 &&\n+\t\tcat >expected.4 <<-EOF &&\n+\t\t first => third | 0\n+\t\t 1 file changed, 0 insertions(+), 0 deletions(-)\n+\t\tEOF\n+\t\ttest_cmp expected.4 actual.4 &&\n+\n+\t\tgit diff --cached --stat >actual.5 &&\n+\t\t: >expected.5 &&\n+\t\ttest_cmp expected.5 actual.5\n+\n \t)\n '\n \n@@ -222,5 +233,16 @@ test_expect_success 'double rename detection in status' '\n \t)\n '\n \n-test_done\n+test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n+\tgit reset --hard &&\n+\techo new >new-ita &&\n+\tgit add -N new-ita &&\n+\tgit diff --summary >actual &&\n+\techo \" create mode 100644 new-ita\" >expected &&\n+\ttest_cmp expected actual &&\n+\tgit diff --cached --summary >actual2 &&\n+\t: >expected2 &&\n+\ttest_cmp expected2 actual2\n+'\n \n+test_done\ndiff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh\nindex cf0f3a1ee7..108c012a3a 100755\n--- a/t/t4011-diff-symlink.sh\n+++ b/t/t4011-diff-symlink.sh\n@@ -139,11 +139,13 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '\n test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '\n \tcat >expect <<-\\EOF &&\n \tdiff --git a/file.bin b/file.bin\n-\tindex e69de29..d95f3ad 100644\n-\tBinary files a/file.bin and b/file.bin differ\n+\tnew file mode 100644\n+\tindex 0000000..d95f3ad\n+\tBinary files /dev/null and b/file.bin differ\n \tdiff --git a/link.bin b/link.bin\n-\tindex e69de29..dce41ec 120000\n-\t--- a/link.bin\n+\tnew file mode 120000\n+\tindex 0000000..dce41ec\n+\t--- /dev/null\n \t+++ b/link.bin\n \t@@ -0,0 +1 @@\n \t+file.bin\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348586","messageId":"20180526120846.23663-2-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180526120846.23663-1-pclouds@gmail.com","subject":"[PATCH v2 1/4] diff: ignore --ita-[in]visible-in-index when diffing worktree-to-tree","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-26T12:08:43Z","receivedAt":"2018-05-26T12:08:59Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This option is supposed to fix the diff of \"diff-files\" (not reporting\nita entries as new files) and \"diff-index --cached <tree>\" ( showing\nita entries as present in the index with empty content) but not\n\"diff-index <tree>\".\n\nWhen --ita-invisible-in-index is set on \"git diff-index <tree>\",\nunpack_trees() will eventually call oneway_diff() on the ita entry\nwith the same code flow as \"diff-index --cached <tree>\". We want to\nignore the ita entry for \"diff-index --cached <tree>\" but not\n\"diff-index <tree>\" since the latter will examine and produce a diff\nbased on worktree entry's (real) content, not ita index entry's\n(empty) content.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n diff-lib.c            | 8 ++++++--\n t/t2203-add-intent.sh | 2 +-\n 2 files changed, 7 insertions(+), 3 deletions(-)\n\ndiff --git a/diff-lib.c b/diff-lib.c\nindex 104f954a25..a9f38eb5a3 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -389,8 +389,12 @@ static void do_oneway_diff(struct unpack_trees_options *o,\n \tstruct rev_info *revs = o->unpack_data;\n \tint match_missing, cached;\n \n-\t/* i-t-a entries do not actually exist in the index */\n-\tif (revs->diffopt.ita_invisible_in_index &&\n+\t/*\n+\t * i-t-a entries do not actually exist in the index (if we're\n+\t * looking at its content)\n+\t */\n+\tif (o->index_only &&\n+\t    revs->diffopt.ita_invisible_in_index &&\n \t    idx && ce_intent_to_add(idx)) {\n \t\tidx = NULL;\n \t\tif (!tree)\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 78236dc7d8..3ab07cb404 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -70,7 +70,7 @@ test_expect_success 'i-t-a entry is simply ignored' '\n \tgit commit -m second &&\n \ttest $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&\n \ttest $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&\n-\ttest $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&\n+\ttest $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 1 &&\n \ttest $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1\n '\n \n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348587","messageId":"20180526120846.23663-4-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180526120846.23663-1-pclouds@gmail.com","subject":"[PATCH v2 3/4] t2203: add a test about \"diff HEAD\" case","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-26T12:08:45Z","receivedAt":"2018-05-26T12:09:03Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Previous attempts to fix ita-related diffs breaks this case. To make\nsure that does not happen again, add a test to verify the behavior\nwrt. ita entries when we diff a worktree and a tree.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n t/t2203-add-intent.sh | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)\n\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 1115347712..546fead6ad 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -245,4 +245,21 @@ test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n \ttest_cmp expected2 actual2\n '\n \n+test_expect_success '\"diff HEAD\" includes ita as new files' '\n+\tgit reset --hard &&\n+\techo new >new-ita &&\n+\tgit add -N new-ita &&\n+\tgit diff HEAD >actual &&\n+\tcat >expected <<-\\EOF &&\n+\tdiff --git a/new-ita b/new-ita\n+\tnew file mode 100644\n+\tindex 0000000..3e75765\n+\t--- /dev/null\n+\t+++ b/new-ita\n+\t@@ -0,0 +1 @@\n+\t+new\n+\tEOF\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348588","messageId":"20180526120846.23663-5-pclouds@gmail.com","threadId":"48482","inReplyTo":"20180526120846.23663-1-pclouds@gmail.com","subject":"[PATCH v2 4/4] apply: add --intent-to-add","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2018-05-26T12:08:46Z","receivedAt":"2018-05-26T12:09:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Similar to 'git reset -N', this option makes 'git apply' automatically\nmark new files as intent-to-add so they are visible in the following\n'git diff' command and could also be committed with 'git commit -a'.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Documentation/git-apply.txt | 10 +++++++++-\n apply.c                     | 19 ++++++++++++-------\n apply.h                     |  1 +\n t/t2203-add-intent.sh       | 13 +++++++++++++\n 4 files changed, 35 insertions(+), 8 deletions(-)\n\ndiff --git a/Documentation/git-apply.txt b/Documentation/git-apply.txt\nindex 4ebc3d3271..e3b966c656 100644\n--- a/Documentation/git-apply.txt\n+++ b/Documentation/git-apply.txt\n@@ -9,7 +9,7 @@ git-apply - Apply a patch to files and/or to the index\n SYNOPSIS\n --------\n [verse]\n-'git apply' [--stat] [--numstat] [--summary] [--check] [--index] [--3way]\n+'git apply' [--stat] [--numstat] [--summary] [--check] [--index | --intent-to-add] [--3way]\n \t  [--apply] [--no-add] [--build-fake-ancestor=<file>] [-R | --reverse]\n \t  [--allow-binary-replacement | --binary] [--reject] [-z]\n \t  [-p<n>] [-C<n>] [--inaccurate-eof] [--recount] [--cached]\n@@ -74,6 +74,14 @@ OPTIONS\n \tcached data, apply the patch, and store the result in the index\n \twithout using the working tree. This implies `--index`.\n \n+--intent-to-add::\n+\tWhen applying the patch only to the working tree, mark new\n+\tfiles to be added to the index later (see `--intent-to-add`\n+\toption in linkgit:git-add[1]). This option is ignored unless\n+\trunning in a Git repository and `--index` is not specified.\n+\tNote that `--index` could be implied by other options such\n+\tas `--cached` or `--3way`.\n+\n -3::\n --3way::\n \tWhen the patch does not apply cleanly, fall back on 3-way merge if\ndiff --git a/apply.c b/apply.c\nindex 7e5792c996..899c5cc0ac 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -141,6 +141,8 @@ int check_apply_state(struct apply_state *state, int force_apply)\n \t\t\treturn error(_(\"--cached outside a repository\"));\n \t\tstate->check_index = 1;\n \t}\n+\tif (state->ita_only && (state->check_index || is_not_gitdir))\n+\t\tstate->ita_only = 0;\n \tif (state->check_index)\n \t\tstate->unsafe_paths = 0;\n \n@@ -4242,7 +4244,7 @@ static void patch_stats(struct apply_state *state, struct patch *patch)\n \n static int remove_file(struct apply_state *state, struct patch *patch, int rmdir_empty)\n {\n-\tif (state->update_index) {\n+\tif (state->update_index && !state->ita_only) {\n \t\tif (remove_file_from_cache(patch->old_name) < 0)\n \t\t\treturn error(_(\"unable to remove %s from index\"), patch->old_name);\n \t}\n@@ -4265,15 +4267,15 @@ static int add_index_file(struct apply_state *state,\n \tint namelen = strlen(path);\n \tunsigned ce_size = cache_entry_size(namelen);\n \n-\tif (!state->update_index)\n-\t\treturn 0;\n-\n \tce = xcalloc(1, ce_size);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_mode = create_ce_mode(mode);\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = namelen;\n-\tif (S_ISGITLINK(mode)) {\n+\tif (state->ita_only) {\n+\t\tce->ce_flags |= CE_INTENT_TO_ADD;\n+\t\tset_object_name_for_intent_to_add_entry(ce);\n+\t} else if (S_ISGITLINK(mode)) {\n \t\tconst char *s;\n \n \t\tif (!skip_prefix(buf, \"Subproject commit \", &s) ||\n@@ -4465,8 +4467,9 @@ static int create_file(struct apply_state *state, struct patch *patch)\n \n \tif (patch->conflicted_threeway)\n \t\treturn add_conflicted_stages_file(state, patch);\n-\telse\n+\telse if (state->update_index)\n \t\treturn add_index_file(state, path, mode, buf, size);\n+\treturn 0;\n }\n \n /* phase zero is to remove, phase one is to create */\n@@ -4686,7 +4689,7 @@ static int apply_patch(struct apply_state *state,\n \tif (state->whitespace_error && (state->ws_error_action == die_on_ws_error))\n \t\tstate->apply = 0;\n \n-\tstate->update_index = state->check_index && state->apply;\n+\tstate->update_index = (state->check_index || state->ita_only) && state->apply;\n \tif (state->update_index && !is_lock_file_locked(&state->lock_file)) {\n \t\tif (state->index_file)\n \t\t\thold_lock_file_for_update(&state->lock_file,\n@@ -4941,6 +4944,8 @@ int apply_parse_options(int argc, const char **argv,\n \t\t\tN_(\"instead of applying the patch, see if the patch is applicable\")),\n \t\tOPT_BOOL(0, \"index\", &state->check_index,\n \t\t\tN_(\"make sure the patch is applicable to the current index\")),\n+\t\tOPT_BOOL('N', \"intent-to-add\", &state->ita_only,\n+\t\t\tN_(\"mark new files with `git add --intent-to-add`\")),\n \t\tOPT_BOOL(0, \"cached\", &state->cached,\n \t\t\tN_(\"apply a patch without touching the working tree\")),\n \t\tOPT_BOOL_F(0, \"unsafe-paths\", &state->unsafe_paths,\ndiff --git a/apply.h b/apply.h\nindex dc4a019057..b80d8ba736 100644\n--- a/apply.h\n+++ b/apply.h\n@@ -45,6 +45,7 @@ struct apply_state {\n \tint check; /* preimage must match working tree, don't actually apply */\n \tint check_index; /* preimage must match the indexed version */\n \tint update_index; /* check_index && apply */\n+\tint ita_only;\t  /* add intent-to-add entries to the index */\n \n \t/* These control cosmetic aspect of the output */\n \tint diffstat; /* just show a diffstat, and don't actually apply */\ndiff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh\nindex 546fead6ad..0891827863 100755\n--- a/t/t2203-add-intent.sh\n+++ b/t/t2203-add-intent.sh\n@@ -245,6 +245,7 @@ test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '\n \ttest_cmp expected2 actual2\n '\n \n+\n test_expect_success '\"diff HEAD\" includes ita as new files' '\n \tgit reset --hard &&\n \techo new >new-ita &&\n@@ -262,4 +263,16 @@ test_expect_success '\"diff HEAD\" includes ita as new files' '\n \ttest_cmp expected actual\n '\n \n+test_expect_success 'apply --intent-to-add' '\n+\tgit reset --hard &&\n+\techo new >new-ita &&\n+\tgit add -N new-ita &&\n+\tgit diff >expected &&\n+\tgrep \"new file\" expected &&\n+\tgit reset --hard &&\n+\tgit apply --intent-to-add expected &&\n+\tgit diff >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \n2.17.0.705.g3525833791\n\n"},{"id":"348619","messageId":"CAPig+cTrsS6_f9jMx_EnJU9QY4qD12Lc=aM5XnQkheBsPW5zPQ@mail.gmail.com","threadId":"48482","inReplyTo":"20180526120846.23663-2-pclouds@gmail.com","subject":"Re: [PATCH v2 1/4] diff: ignore --ita-[in]visible-in-index when diffing worktree-to-tree","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-05-27T07:18:42Z","receivedAt":"2018-05-27T07:18:47Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sat, May 26, 2018 at 8:08 AM, Nguyễn Thái Ngọc Duy <pclouds@gmail.com> wrote:\n> This option is supposed to fix the diff of \"diff-files\" (not reporting\n> ita entries as new files) and \"diff-index --cached <tree>\" ( showing\n\ns/(\\s/(/\n\n> ita entries as present in the index with empty content) but not\n> \"diff-index <tree>\".\n>\n> When --ita-invisible-in-index is set on \"git diff-index <tree>\",\n> unpack_trees() will eventually call oneway_diff() on the ita entry\n> with the same code flow as \"diff-index --cached <tree>\". We want to\n> ignore the ita entry for \"diff-index --cached <tree>\" but not\n> \"diff-index <tree>\" since the latter will examine and produce a diff\n> based on worktree entry's (real) content, not ita index entry's\n> (empty) content.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n"}]}