]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add: don't write objects with --dry-run
authorRené Scharfe <l.s.r@web.de>
Tue, 12 Oct 2021 19:15:50 +0000 (21:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Oct 2021 20:15:49 +0000 (13:15 -0700)
When the option --dry-run/-n is given, "git add" doesn't change the
index, but still writes out new object files.  Only hash the latter
without writing instead to make the run as dry as possible.

Use this opportunity to also make the hash_flags variable unsigned,
to match the index_path() parameter it is used as.

Reported-by: git.mexon@spamgourmet.com
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
read-cache.c
t/t2200-add-update.sh

index 9048ef9e905251bacb516be6afdb474b4e59648f..316ea43678bb78e89f1a366ca646d1d10d9b7262 100644 (file)
@@ -738,7 +738,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
        int intent_only = flags & ADD_CACHE_INTENT;
        int add_option = (ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE|
                          (intent_only ? ADD_CACHE_NEW_ONLY : 0));
-       int hash_flags = HASH_WRITE_OBJECT;
+       unsigned hash_flags = pretend ? 0 : HASH_WRITE_OBJECT;
        struct object_id oid;
 
        if (flags & ADD_CACHE_RENORMALIZE)
index 45ca35d60ac5b750a635ef42f96275c4bb197692..94c4cb0672126c6ae0440598a68e99182a4cffbf 100755 (executable)
@@ -129,12 +129,15 @@ test_expect_success 'add -n -u should not add but just report' '
                echo "remove '\''top'\''"
        ) >expect &&
        before=$(git ls-files -s check top) &&
+       git count-objects -v >objects_before &&
        echo changed >>check &&
        rm -f top &&
        git add -n -u >actual &&
        after=$(git ls-files -s check top) &&
+       git count-objects -v >objects_after &&
 
        test "$before" = "$after" &&
+       test_cmp objects_before objects_after &&
        test_cmp expect actual
 
 '