Skip to content

Commit 51f9af3

Browse files
authored
Merge pull request #2733 from dscho/difftool-ita-g4w
Fix `git difftool` with intent-to-add files
2 parents 53ca6a2 + 0c87084 commit 51f9af3

File tree

4 files changed

+60
-10
lines changed

4 files changed

+60
-10
lines changed

builtin/diff-files.c

+7
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);

diff-lib.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
220220
} else if (revs->diffopt.ita_invisible_in_index &&
221221
ce_intent_to_add(ce)) {
222222
diff_addremove(&revs->diffopt, '+', ce->ce_mode,
223-
the_hash_algo->empty_tree, 0,
224-
ce->name, 0);
223+
&null_oid, 0, ce->name, 0);
225224
continue;
226225
}
227226

t/t2203-add-intent.sh

+44-8
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,53 @@ 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 'i-t-a files shown as new for "diff", "diff-files"; not-new for "diff --cached"' '
236236
git reset --hard &&
237-
echo new >new-ita &&
238-
git add -N new-ita &&
237+
: >empty &&
238+
content="foo" &&
239+
echo "$content" >not-empty &&
240+
241+
hash_e=$(git hash-object empty) &&
242+
hash_n=$(git hash-object not-empty) &&
243+
244+
cat >expect.diff_p <<-EOF &&
245+
diff --git a/empty b/empty
246+
new file mode 100644
247+
index 0000000..$(git rev-parse --short $hash_e)
248+
diff --git a/not-empty b/not-empty
249+
new file mode 100644
250+
index 0000000..$(git rev-parse --short $hash_n)
251+
--- /dev/null
252+
+++ b/not-empty
253+
@@ -0,0 +1 @@
254+
+$content
255+
EOF
256+
cat >expect.diff_s <<-EOF &&
257+
create mode 100644 empty
258+
create mode 100644 not-empty
259+
EOF
260+
cat >expect.diff_a <<-EOF &&
261+
:000000 100644 0000000 0000000 A$(printf "\t")empty
262+
:000000 100644 0000000 0000000 A$(printf "\t")not-empty
263+
EOF
264+
265+
git add -N empty not-empty &&
266+
267+
git diff >actual &&
268+
test_cmp expect.diff_p actual &&
269+
239270
git diff --summary >actual &&
240-
echo " create mode 100644 new-ita" >expected &&
241-
test_cmp expected actual &&
242-
git diff --cached --summary >actual2 &&
243-
test_must_be_empty actual2
244-
'
271+
test_cmp expect.diff_s actual &&
272+
273+
git diff-files -p >actual &&
274+
test_cmp expect.diff_p actual &&
245275
276+
git diff-files --abbrev >actual &&
277+
test_cmp expect.diff_a actual &&
278+
279+
git diff --cached >actual &&
280+
test_must_be_empty actual
281+
'
246282

247283
test_expect_success '"diff HEAD" includes ita as new files' '
248284
git reset --hard &&

t/t7800-difftool.sh

+8
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
720720
test_cmp expect actual
721721
'
722722

723+
test_expect_success 'add -N and difftool -d' '
724+
test_when_finished git reset --hard &&
725+
726+
test_write_lines A B C >intent-to-add &&
727+
git add -N intent-to-add &&
728+
git difftool --dir-diff --extcmd ls
729+
'
730+
723731
test_expect_success 'outside worktree' '
724732
echo 1 >1 &&
725733
echo 2 >2 &&

0 commit comments

Comments
 (0)