]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit: don't be fooled by ita entries when creating initial commit
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Mon, 24 Oct 2016 10:42:22 +0000 (17:42 +0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 24 Oct 2016 17:54:11 +0000 (10:54 -0700)
ita entries are dropped at tree generation phase. If the entire index
consists of just ita entries, the result would be a a commit with no
entries, which should be caught unless --allow-empty is specified. The
test "!!active_nr" is not sufficient to catch this.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/commit.c
t/t2203-add-intent.sh

index 400d2a54e627a7e43349738f8de68b101011fa71..1e74bc19f674dcfc64e76d7766874e2bcad71c90 100644 (file)
@@ -894,9 +894,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
                if (amend)
                        parent = "HEAD^1";
 
-               if (get_sha1(parent, sha1))
-                       commitable = !!active_nr;
-               else {
+               if (get_sha1(parent, sha1)) {
+                       int i, ita_nr = 0;
+
+                       for (i = 0; i < active_nr; i++)
+                               if (ce_intent_to_add(active_cache[i]))
+                                       ita_nr++;
+                       commitable = active_nr - ita_nr > 0;
+               } else {
                        /*
                         * Unless the user did explicitly request a submodule
                         * ignore mode by passing a command line option we do
index 8652a96d86b85f02d6c07a210ac60fa122dc1649..84a9028c433c02c72adcdf06222bcb409e2eb683 100755 (executable)
@@ -129,6 +129,16 @@ test_expect_success 'cache-tree does skip dir that becomes empty' '
        )
 '
 
+test_expect_success 'commit: ita entries ignored in empty intial commit check' '
+       git init empty-intial-commit &&
+       (
+               cd empty-intial-commit &&
+               : >one &&
+               git add -N one &&
+               test_must_fail git commit -m nothing-new-here
+       )
+'
+
 test_expect_success 'commit: ita entries ignored in empty commit check' '
        git init empty-subsequent-commit &&
        (