Skip to content

Commit 018ec3c

Browse files
pcloudsgitster
authored andcommitted
commit: fix empty commit creation when there's no changes but ita entries
If i-t-a entries are present and there is no change between the index and HEAD i-t-a entries, index_differs_from() still returns "dirty, new entries" (aka, the resulting commit is not empty), but cache-tree will skip i-t-a entries and produce the exact same tree of current commit. index_differs_from() is supposed to catch this so we can abort git-commit (unless --no-empty is specified). Update it to optionally ignore i-t-a entries when doing a diff between the index and HEAD so that it would return "no change" in this case and abort commit. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b42b451 commit 018ec3c

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
910910
if (ignore_submodule_arg &&
911911
!strcmp(ignore_submodule_arg, "all"))
912912
diff_flags |= DIFF_OPT_IGNORE_SUBMODULES;
913-
commitable = index_differs_from(parent, diff_flags);
913+
commitable = index_differs_from(parent, diff_flags, 1);
914914
}
915915
}
916916
strbuf_release(&committer_ident);

diff-lib.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ int do_diff_cache(const unsigned char *tree_sha1, struct diff_options *opt)
535535
return 0;
536536
}
537537

538-
int index_differs_from(const char *def, int diff_flags)
538+
int index_differs_from(const char *def, int diff_flags,
539+
int ita_invisible_in_index)
539540
{
540541
struct rev_info rev;
541542
struct setup_revision_opt opt;
@@ -547,6 +548,7 @@ int index_differs_from(const char *def, int diff_flags)
547548
DIFF_OPT_SET(&rev.diffopt, QUICK);
548549
DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS);
549550
rev.diffopt.flags |= diff_flags;
551+
rev.diffopt.ita_invisible_in_index = ita_invisible_in_index;
550552
run_diff_index(&rev, 1);
551553
if (rev.pending.alloc)
552554
free(rev.pending.objects);

diff.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ extern int diff_result_code(struct diff_options *, int);
357357

358358
extern void diff_no_index(struct rev_info *, int, const char **);
359359

360-
extern int index_differs_from(const char *def, int diff_flags);
360+
extern int index_differs_from(const char *def, int diff_flags, int ita_invisible_in_index);
361361

362362
/*
363363
* Fill the contents of the filespec "df", respecting any textconv defined by

sequencer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
469469
unborn = get_sha1("HEAD", head);
470470
if (unborn)
471471
hashcpy(head, EMPTY_TREE_SHA1_BIN);
472-
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0))
472+
if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0))
473473
return error_dirty_index(opts);
474474
}
475475
discard_cache();
@@ -1064,7 +1064,7 @@ static int sequencer_continue(struct replay_opts *opts)
10641064
if (ret)
10651065
return ret;
10661066
}
1067-
if (index_differs_from("HEAD", 0))
1067+
if (index_differs_from("HEAD", 0, 0))
10681068
return error_dirty_index(opts);
10691069
todo_list = todo_list->next;
10701070
return pick_commits(todo_list, opts);

t/t2203-add-intent.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +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 commit check' '
133+
git init empty-subsequent-commit &&
134+
(
135+
cd empty-subsequent-commit &&
136+
test_commit one &&
137+
: >two &&
138+
git add -N two &&
139+
test_must_fail git commit -m nothing-new-here
140+
)
141+
'
142+
132143
test_done
133144

0 commit comments

Comments
 (0)