Skip to content

Commit 2c49f7f

Browse files
pcloudsgitster
authored andcommitted
commit: don't be fooled by ita entries when creating initial commit
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 018ec3c commit 2c49f7f

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

builtin/commit.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,14 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
894894
if (amend)
895895
parent = "HEAD^1";
896896

897-
if (get_sha1(parent, sha1))
898-
commitable = !!active_nr;
899-
else {
897+
if (get_sha1(parent, sha1)) {
898+
int i, ita_nr = 0;
899+
900+
for (i = 0; i < active_nr; i++)
901+
if (ce_intent_to_add(active_cache[i]))
902+
ita_nr++;
903+
commitable = active_nr - ita_nr > 0;
904+
} else {
900905
/*
901906
* Unless the user did explicitly request a submodule
902907
* ignore mode by passing a command line option we do

t/t2203-add-intent.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ test_expect_success 'cache-tree does skip dir that becomes empty' '
129129
)
130130
'
131131

132+
test_expect_success 'commit: ita entries ignored in empty intial commit check' '
133+
git init empty-intial-commit &&
134+
(
135+
cd empty-intial-commit &&
136+
: >one &&
137+
git add -N one &&
138+
test_must_fail git commit -m nothing-new-here
139+
)
140+
'
141+
132142
test_expect_success 'commit: ita entries ignored in empty commit check' '
133143
git init empty-subsequent-commit &&
134144
(

0 commit comments

Comments
 (0)