Skip to content

Commit 0231ae7

Browse files
pcloudsgitster
authored andcommitted
diff: turn --ita-invisible-in-index on by default
Due to the implementation detail of intent-to-add entries, the current "git diff" (i.e. no treeish or --cached argument) would show the changes in the i-t-a file, but it does not mark the file as new, while "diff --cached" would mark the file as new while showing its content as empty. $ git diff | $ diff --cached --------------------------------|------------------------------- diff --git a/new b/new | diff --git a/new b/new index e69de29..5ad28e2 100644 | new file mode 100644 --- a/new | index 0000000..e69de29 +++ b/new | @@ -0,0 +1 @@ | +haha | One evidence of the current output being wrong is that, the output from "git diff" (with ita entries) cannot be applied because it assumes empty files exist before applying. Turning on --ita-invisible-in-index [1] [2] would fix this. The result is "new file" line moving from "git diff --cached" to "git diff". $ git diff | $ diff --cached --------------------------------|------------------------------- diff --git a/new b/new | new file mode 100644 | index 0000000..5ad28e2 | --- /dev/null | +++ b/new | @@ -0,0 +1 @@ | +haha | This option is on by default in git-status [1] but we need more fixup in rename detection code [3]. Luckily we don't need to do anything else for the rename detection code in diff.c (wt-status.c uses a customized one). [1] 425a28e (diff-lib: allow ita entries treated as "not yet exist in index" - 2016-10-24) [2] b42b451 (diff: add --ita-[in]visible-in-index - 2016-10-24) [3] bc3dca0 (Merge branch 'nd/ita-wt-renames-in-status' - 2018-01-23) Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ba4e356 commit 0231ae7

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

builtin/diff.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
352352
rev.diffopt.flags.allow_external = 1;
353353
rev.diffopt.flags.allow_textconv = 1;
354354

355+
/*
356+
* Default to intent-to-add entries invisible in the
357+
* index. This makes them show up as new files in diff-files
358+
* and not at all in diff-cached.
359+
*/
360+
rev.diffopt.ita_invisible_in_index = 1;
361+
355362
if (nongit)
356363
die(_("Not a git repository"));
357364
argc = setup_revisions(argc, argv, &rev, NULL);

t/t2203-add-intent.sh

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ test_expect_success 'i-t-a entry is simply ignored' '
7070
git commit -m second &&
7171
test $(git ls-tree HEAD -- nitfol | wc -l) = 0 &&
7272
test $(git diff --name-only HEAD -- nitfol | wc -l) = 1 &&
73-
test $(git diff --name-only --ita-invisible-in-index HEAD -- nitfol | wc -l) = 1 &&
74-
test $(git diff --name-only --ita-invisible-in-index -- nitfol | wc -l) = 1
73+
test $(git diff --name-only -- nitfol | wc -l) = 1
7574
'
7675

7776
test_expect_success 'can commit with an unrelated i-t-a entry in index' '
@@ -99,13 +98,13 @@ test_expect_success 'cache-tree invalidates i-t-a paths' '
9998
10099
: >dir/bar &&
101100
git add -N dir/bar &&
102-
git diff --cached --name-only >actual &&
101+
git diff --name-only >actual &&
103102
echo dir/bar >expect &&
104103
test_cmp expect actual &&
105104
106105
git write-tree >/dev/null &&
107106
108-
git diff --cached --name-only >actual &&
107+
git diff --name-only >actual &&
109108
echo dir/bar >expect &&
110109
test_cmp expect actual
111110
'
@@ -186,7 +185,19 @@ test_expect_success 'rename detection finds the right names' '
186185
cat >expected.3 <<-EOF &&
187186
2 .R N... 100644 100644 100644 $hash $hash R100 third first
188187
EOF
189-
test_cmp expected.3 actual.3
188+
test_cmp expected.3 actual.3 &&
189+
190+
git diff --stat >actual.4 &&
191+
cat >expected.4 <<-EOF &&
192+
first => third | 0
193+
1 file changed, 0 insertions(+), 0 deletions(-)
194+
EOF
195+
test_cmp expected.4 actual.4 &&
196+
197+
git diff --cached --stat >actual.5 &&
198+
: >expected.5 &&
199+
test_cmp expected.5 actual.5
200+
190201
)
191202
'
192203

@@ -222,5 +233,16 @@ test_expect_success 'double rename detection in status' '
222233
)
223234
'
224235

225-
test_done
236+
test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '
237+
git reset --hard &&
238+
echo new >new-ita &&
239+
git add -N new-ita &&
240+
git diff --summary >actual &&
241+
echo " create mode 100644 new-ita" >expected &&
242+
test_cmp expected actual &&
243+
git diff --cached --summary >actual2 &&
244+
: >expected2 &&
245+
test_cmp expected2 actual2
246+
'
226247

248+
test_done

t/t4011-diff-symlink.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,13 @@ test_expect_success SYMLINKS 'setup symlinks with attributes' '
139139
test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' '
140140
cat >expect <<-\EOF &&
141141
diff --git a/file.bin b/file.bin
142-
index e69de29..d95f3ad 100644
143-
Binary files a/file.bin and b/file.bin differ
142+
new file mode 100644
143+
index 0000000..d95f3ad
144+
Binary files /dev/null and b/file.bin differ
144145
diff --git a/link.bin b/link.bin
145-
index e69de29..dce41ec 120000
146-
--- a/link.bin
146+
new file mode 120000
147+
index 0000000..dce41ec
148+
--- /dev/null
147149
+++ b/link.bin
148150
@@ -0,0 +1 @@
149151
+file.bin

0 commit comments

Comments
 (0)