git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/4] diff: add --ita-[in]visible-in-index

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Oct 24, 2016, 10:42 UTC
Message-ID
<20161024104222.31128-3-pclouds@gmail.com>
In-Reply-To
<20161024104222.31128-1-pclouds@gmail.com>

The option --ita-invisible-in-index exposes the "ita_invisible_in_index" diff flag to outside to allow easier experimentation with this new mode. The "plan" is to make --ita-invisible-in-index default to keep consistent behavior with 'status' and 'commit', but a bunch other commands like 'apply', 'merge', 'reset'.... need to be taken into consideration as well.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/diff-options.txt | 8 ++++++++
 diff.c                         | 4 ++++
 t/t2203-add-intent.sh          | 4 +++-
 3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt
index 7805a0c..0fdd53f 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -575,5 +575,13 @@ endif::git-format-patch[]
 --line-prefix=<prefix>::
 	Prepend an additional prefix to every line of output.
 
+--ita-invisible-in-index::
+	By default entries added by "git add -N" appear as an existing
+	empty file in "git diff" and a new file in "git diff --cached".
+	This option makes the entry appear as a new file in "git diff"
+	and non-existent in "git diff --cached". This option could be
+	reverted with `--ita-visible-in-index`. Both options are
+	experimental and could be removed in future.
+
 For more detailed explanation on these common options, see also
 linkgit:gitdiffcore[7].
diff --git a/diff.c b/diff.c
index c6da383..e8e73f8 100644
--- a/diff.c
+++ b/diff.c
@@ -3923,6 +3923,10 @@ int diff_opt_parse(struct diff_options *options,
 		return parse_submodule_opt(options, arg);
 	else if (skip_prefix(arg, "--ws-error-highlight=", &arg))
 		return parse_ws_error_highlight(options, arg);
+	else if (!strcmp(arg, "--ita-invisible-in-index"))
+		options->ita_invisible_in_index = 1;
+	else if (!strcmp(arg, "--ita-visible-in-index"))
+		options->ita_invisible_in_index = 0;
 
 	/* misc options */
 	else if (!strcmp(arg, "-z"))
diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh
index 2276e4e..0e54f63 100755
--- a/t/t2203-add-intent.sh
+++ b/t/t2203-add-intent.sh
@@ -57,7 +57,9 @@ test_expect_success 'i-t-a entry is simply ignored' '
 	git add -N nitfol &&
 	git commit -m second &&
 	test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
-	test $(git diff --name-only HEAD -- nitfol | wc -l) = 1
+	test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
+	test $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 0 &&
+	test $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1
 '
 
 test_expect_success 'can commit with an unrelated i-t-a entry in index' '
-- 
2.8.2.524.g6ff3d78
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 17 of 21 in “i-t-a entries in git-status, and git-commit”
  1. 0/3 i-t-a entries in git-status, and git-commitNguyễn Thái Ngọc Duy, Sep 28, 2016
  2. 1/3 Resurrect "diff-lib.c: adjust position of i-t-a entries in diff"Nguyễn Thái Ngọc Duy, Sep 28, 2016
  3. Junio C HamanoSep 28, 2016
  4. Junio C HamanoSep 28, 2016
  5. Duy NguyenOct 3, 2016
  6. Junio C HamanoOct 4, 2016
  7. Duy NguyenOct 5, 2016
  8. Junio C HamanoOct 6, 2016
  9. Duy NguyenOct 7, 2016
  10. Junio C HamanoOct 10, 2016
  11. 2/3 diff-lib.c: enable --shift-ita in index_differs_from()Nguyễn Thái Ngọc Duy, Sep 28, 2016
  12. Junio C HamanoSep 28, 2016
  13. 3/3 commit: don't be fooled by ita entries when creating initial commitNguyễn Thái Ngọc Duy, Sep 28, 2016
  14. Duy NguyenSep 28, 2016
  15. 0/4 nd/ita-empty-commit updateNguyễn Thái Ngọc Duy, Oct 24, 2016
  16. 1/4 diff-lib: allow ita entries treated as "not yet exist in index"Nguyễn Thái Ngọc Duy, Oct 24, 2016
  17. 2/4 diff: add --ita-[in]visible-in-indexNguyễn Thái Ngọc Duy, Oct 24, 2016
  18. 3/4 commit: fix empty commit creation when there's no changes but ita entriesNguyễn Thái Ngọc Duy, Oct 24, 2016
  19. 4/4 commit: don't be fooled by ita entries when creating initial commitNguyễn Thái Ngọc Duy, Oct 24, 2016
  20. Junio C HamanoOct 24, 2016
  21. Duy NguyenOct 25, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.