Skip to content

Commit

Permalink
commit: don't be fooled by ita entries when creating initial commit
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
pclouds authored and gitster committed Oct 24, 2016
1 parent 018ec3c commit 2c49f7f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 8 additions & 3 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions t/t2203-add-intent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
(
Expand Down

0 comments on commit 2c49f7f

Please sign in to comment.