Skip to content

Commit c9e4248

Browse files
committed
Merge branch 'sk/diff-files-show-i-t-a-as-new' into pu
* sk/diff-files-show-i-t-a-as-new: diff-files: treat "i-t-a" files as "not-in-index"
2 parents db453c4 + 4c856b2 commit c9e4248

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

builtin/diff-files.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix)
2828
git_config(git_diff_basic_config, NULL); /* no "diff" UI options */
2929
repo_init_revisions(the_repository, &rev, prefix);
3030
rev.abbrev = 0;
31+
32+
/*
33+
* Consider "intent-to-add" files as new by default, unless
34+
* explicitly specified in the command line or anywhere else.
35+
*/
36+
rev.diffopt.ita_invisible_in_index = 1;
37+
3138
precompose_argv(argc, argv);
3239

3340
argc = setup_revisions(argc, argv, &rev, NULL);

t/t2203-add-intent.sh

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ test_expect_success 'double rename detection in status' '
232232
)
233233
'
234234

235-
test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '
235+
test_expect_success 'diff/diff-cached shows ita as new/not-new files' '
236236
git reset --hard &&
237237
echo new >new-ita &&
238238
git add -N new-ita &&
@@ -243,6 +243,29 @@ test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' '
243243
test_must_be_empty actual2
244244
'
245245

246+
test_expect_success 'diff-files shows i-t-a files as new files' '
247+
git reset --hard &&
248+
touch empty &&
249+
content="foo" &&
250+
echo $content >not-empty &&
251+
git add -N empty not-empty &&
252+
git diff-files -p >actual &&
253+
hash_e=$(git hash-object empty) &&
254+
hash_n=$(git hash-object not-empty) &&
255+
cat >expect <<-EOF &&
256+
diff --git a/empty b/empty
257+
new file mode 100644
258+
index 0000000..$(git rev-parse --short $hash_e)
259+
diff --git a/not-empty b/not-empty
260+
new file mode 100644
261+
index 0000000..$(git rev-parse --short $hash_n)
262+
--- /dev/null
263+
+++ b/not-empty
264+
@@ -0,0 +1 @@
265+
+$content
266+
EOF
267+
test_cmp expect actual
268+
'
246269

247270
test_expect_success '"diff HEAD" includes ita as new files' '
248271
git reset --hard &&

0 commit comments

Comments
 (0)