Skip to content

Commit bc65d84

Browse files
committed
diff-files --raw: show correct post-image of intent-to-add files
The documented behavior of `git diff-files --raw` is to display [...] 0{40} if creation, unmerged or "look at work tree". on the right hand (i.e. postimage) side. This happens for files that have unstaged modifications, and for files that are unmodified but stat-dirty. For intent-to-add files, we used to show the empty blob's hash instead. In c26022e (diff: convert diff_addremove to struct object_id, 2017-05-30), we made that worse by inadvertently changing that to the hash of the empty tree. Let's make the behavior consistent with files that have unstaged modifications (which applies to intent-to-add files, too) by showing all-zero values also for intent-to-add files. Accordingly, this patch adjusts the expectations set by the regression test introduced in feea694 (diff-files: treat "i-t-a" files as "not-in-index", 2020-06-20). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent fed6a08 commit bc65d84

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

diff-lib.c

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new
240240
241241
hash_e=$(git hash-object empty) &&
242242
hash_n=$(git hash-object not-empty) &&
243-
hash_t=$(git hash-object -t tree /dev/null) &&
244243
245244
cat >expect.diff_p <<-EOF &&
246245
diff --git a/empty b/empty
@@ -259,8 +258,8 @@ test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new
259258
create mode 100644 not-empty
260259
EOF
261260
cat >expect.diff_a <<-EOF &&
262-
:000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")empty
263-
:000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")not-empty
261+
:000000 100644 0000000 0000000 A$(printf "\t")empty
262+
:000000 100644 0000000 0000000 A$(printf "\t")not-empty
264263
EOF
265264
266265
git add -N empty not-empty &&

0 commit comments

Comments
 (0)