]> git.ipfire.org Git - thirdparty/git.git/commitdiff
diff-files --raw: show correct post-image of intent-to-add files
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 1 Jul 2020 21:19:06 +0000 (21:19 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 Jul 2020 23:15:43 +0000 (16:15 -0700)
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 c26022ea8f5 (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 feea6946a5b (diff-files: treat "i-t-a" files as
"not-in-index", 2020-06-20).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
diff-lib.c
t/t2203-add-intent.sh

index 61812f48c2737a4702e604962e97f5c00d394b16..25fd2dee19c4a8f6408d768d44d8dc92aeaf0ed3 100644 (file)
@@ -220,8 +220,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
                        } else if (revs->diffopt.ita_invisible_in_index &&
                                   ce_intent_to_add(ce)) {
                                diff_addremove(&revs->diffopt, '+', ce->ce_mode,
-                                              the_hash_algo->empty_tree, 0,
-                                              ce->name, 0);
+                                              &null_oid, 0, ce->name, 0);
                                continue;
                        }
 
index 8a5d55054f2b7be55ee7eaefd6d9cfac5c344de0..cf0175ad6e414e3a126a205d56a9d910ec173641 100755 (executable)
@@ -240,7 +240,6 @@ test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new
 
        hash_e=$(git hash-object empty) &&
        hash_n=$(git hash-object not-empty) &&
-       hash_t=$(git hash-object -t tree /dev/null) &&
 
        cat >expect.diff_p <<-EOF &&
        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
         create mode 100644 not-empty
        EOF
        cat >expect.diff_a <<-EOF &&
-       :000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")empty
-       :000000 100644 0000000 $(git rev-parse --short $hash_t) A$(printf "\t")not-empty
+       :000000 100644 0000000 0000000 A$(printf "\t")empty
+       :000000 100644 0000000 0000000 A$(printf "\t")not-empty
        EOF
 
        git add -N empty not-empty &&