mirror of
https://github.com/git/git.git
synced 2024-11-23 18:05:29 +08:00
git add --intent-to-add: do not let an empty blob be committed by accident
Writing a tree out of an index with an "intent to add" entry is blocked. This implies that you cannot "git commit" from such a state; however you can still do "git commit -a" or "git commit $that_path". Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
388b2acd6e
commit
331fcb598e
@ -639,7 +639,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix)
|
||||
active_cache_tree = cache_tree();
|
||||
if (cache_tree_update(active_cache_tree,
|
||||
active_cache, active_nr, 0, 0) < 0) {
|
||||
error("Error building trees; the index is unmerged?");
|
||||
error("Error building trees");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
|
||||
die("%s: error reading the index", me);
|
||||
break;
|
||||
case WRITE_TREE_UNMERGED_INDEX:
|
||||
die("%s: error building trees; the index is unmerged?", me);
|
||||
die("%s: error building trees", me);
|
||||
break;
|
||||
case WRITE_TREE_PREFIX_ERROR:
|
||||
die("%s: prefix %s not found", me, prefix);
|
||||
|
10
cache-tree.c
10
cache-tree.c
@ -155,13 +155,17 @@ static int verify_cache(struct cache_entry **cache,
|
||||
funny = 0;
|
||||
for (i = 0; i < entries; i++) {
|
||||
struct cache_entry *ce = cache[i];
|
||||
if (ce_stage(ce)) {
|
||||
if (ce_stage(ce) || (ce->ce_flags & CE_INTENT_TO_ADD)) {
|
||||
if (10 < ++funny) {
|
||||
fprintf(stderr, "...\n");
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "%s: unmerged (%s)\n",
|
||||
ce->name, sha1_to_hex(ce->sha1));
|
||||
if (ce_stage(ce))
|
||||
fprintf(stderr, "%s: unmerged (%s)\n",
|
||||
ce->name, sha1_to_hex(ce->sha1));
|
||||
else
|
||||
fprintf(stderr, "%s: not added yet\n",
|
||||
ce->name);
|
||||
}
|
||||
}
|
||||
if (funny)
|
||||
|
@ -257,6 +257,14 @@ int ie_match_stat(const struct index_state *istate,
|
||||
if (!ignore_valid && (ce->ce_flags & CE_VALID))
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* Intent-to-add entries have not been added, so the index entry
|
||||
* by definition never matches what is in the work tree until it
|
||||
* actually gets added.
|
||||
*/
|
||||
if (ce->ce_flags & CE_INTENT_TO_ADD)
|
||||
return DATA_CHANGED | TYPE_CHANGED | MODE_CHANGED;
|
||||
|
||||
changed = ce_match_stat_basic(ce, st);
|
||||
|
||||
/*
|
||||
|
@ -32,5 +32,33 @@ test_expect_success 'intent to add does not clobber existing paths' '
|
||||
! grep "$empty" actual
|
||||
'
|
||||
|
||||
test_expect_success 'cannot commit with i-t-a entry' '
|
||||
test_tick &&
|
||||
git commit -a -m initial &&
|
||||
git reset --hard &&
|
||||
|
||||
echo xyzzy >rezrov &&
|
||||
echo frotz >nitfol &&
|
||||
git add rezrov &&
|
||||
git add -N nitfol &&
|
||||
test_must_fail git commit
|
||||
'
|
||||
|
||||
test_expect_success 'can commit with an unrelated i-t-a entry in index' '
|
||||
git reset --hard &&
|
||||
echo xyzzy >rezrov &&
|
||||
echo frotz >nitfol &&
|
||||
git add rezrov &&
|
||||
git add -N nitfol &&
|
||||
git commit -m partial rezrov
|
||||
'
|
||||
|
||||
test_expect_success 'can "commit -a" with an i-t-a entry' '
|
||||
git reset --hard &&
|
||||
: >nitfol &&
|
||||
git add -N nitfol &&
|
||||
git commit -a -m all
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user