update-index: use unmerge_index_entry() to support removal
"update-index --unresolve" uses the unmerge_index_entry_at() that assumes that the path to be unresolved must be in the index, which makes it impossible to unresolve a path that was resolved as removal. Rewrite unresolve_one() to use the unmerge_index_entry() to support unresolving such a path. Existing tests for "update-index --unresolve" forgot to check one thing that tests for "checkout --merge -- paths" tested, which is to make sure that resolve-undo record that has already been used to recreate higher-stage index entries is removed. Add new invocations of "ls-files --resolve-undo" after running "update-index --unresolve" to make sure that unresolving with update-index does remove the used resolve-undo records. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
fe83269e16
commit
35901f1c24
@ -660,25 +660,30 @@ static int unresolve_one(const char *path)
|
|||||||
int pos;
|
int pos;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
|
struct cache_entry *ce_2 = NULL, *ce_3 = NULL;
|
||||||
|
struct resolve_undo_info *ru = NULL;
|
||||||
|
|
||||||
|
if (the_index.resolve_undo) {
|
||||||
|
struct string_list_item *item;
|
||||||
|
item = string_list_lookup(the_index.resolve_undo, path);
|
||||||
|
if (item) {
|
||||||
|
ru = item->util;
|
||||||
|
item->util = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* resolve-undo record exists for the path */
|
||||||
|
if (ru) {
|
||||||
|
ret = unmerge_index_entry(&the_index, path, ru);
|
||||||
|
free(ru);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/* See if there is such entry in the index. */
|
/* See if there is such entry in the index. */
|
||||||
pos = index_name_pos(&the_index, path, namelen);
|
pos = index_name_pos(&the_index, path, namelen);
|
||||||
if (0 <= pos) {
|
if (0 <= pos) {
|
||||||
/* already merged */
|
; /* resolve-undo record was used already -- fall back */
|
||||||
pos = unmerge_index_entry_at(&the_index, pos);
|
|
||||||
if (pos < the_index.cache_nr) {
|
|
||||||
const struct cache_entry *ce = the_index.cache[pos];
|
|
||||||
if (ce_stage(ce) &&
|
|
||||||
ce_namelen(ce) == namelen &&
|
|
||||||
!memcmp(ce->name, path, namelen))
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
/* no resolve-undo information; fall back */
|
|
||||||
} else {
|
} else {
|
||||||
/* If there isn't, either it is unmerged, or
|
/* Is it unmerged? */
|
||||||
* resolved as "removed" by mistake. We do not
|
|
||||||
* want to do anything in the former case.
|
|
||||||
*/
|
|
||||||
pos = -pos - 1;
|
pos = -pos - 1;
|
||||||
if (pos < the_index.cache_nr) {
|
if (pos < the_index.cache_nr) {
|
||||||
const struct cache_entry *ce = the_index.cache[pos];
|
const struct cache_entry *ce = the_index.cache[pos];
|
||||||
@ -687,9 +692,10 @@ static int unresolve_one(const char *path)
|
|||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"%s: skipping still unmerged path.\n",
|
"%s: skipping still unmerged path.\n",
|
||||||
path);
|
path);
|
||||||
|
}
|
||||||
goto free_return;
|
goto free_return;
|
||||||
}
|
}
|
||||||
}
|
/* No, such a path does not exist -- removed */
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -37,11 +37,17 @@ prime_resolve_undo () {
|
|||||||
git checkout second^0 &&
|
git checkout second^0 &&
|
||||||
test_tick &&
|
test_tick &&
|
||||||
test_must_fail git merge third^0 &&
|
test_must_fail git merge third^0 &&
|
||||||
echo merge does not leave anything &&
|
|
||||||
check_resolve_undo empty &&
|
check_resolve_undo empty &&
|
||||||
echo different >fi/le &&
|
|
||||||
git add fi/le &&
|
# how should the conflict be resolved?
|
||||||
echo resolving records &&
|
case "$1" in
|
||||||
|
remove)
|
||||||
|
rm -f file/le && git rm fi/le
|
||||||
|
;;
|
||||||
|
*) # modify
|
||||||
|
echo different >fi/le && git add fi/le
|
||||||
|
;;
|
||||||
|
esac
|
||||||
check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
|
check_resolve_undo recorded fi/le initial:fi/le second:fi/le third:fi/le
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,6 +128,8 @@ test_expect_success 'add records checkout -m undoes' '
|
|||||||
test_expect_success 'unmerge with plumbing' '
|
test_expect_success 'unmerge with plumbing' '
|
||||||
prime_resolve_undo &&
|
prime_resolve_undo &&
|
||||||
git update-index --unresolve fi/le &&
|
git update-index --unresolve fi/le &&
|
||||||
|
git ls-files --resolve-undo fi/le >actual &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
git ls-files -u >actual &&
|
git ls-files -u >actual &&
|
||||||
test_line_count = 3 actual
|
test_line_count = 3 actual
|
||||||
'
|
'
|
||||||
@ -130,6 +138,27 @@ test_expect_success 'unmerge can be done even after committing' '
|
|||||||
prime_resolve_undo &&
|
prime_resolve_undo &&
|
||||||
git commit -m "record to nuke MERGE_HEAD" &&
|
git commit -m "record to nuke MERGE_HEAD" &&
|
||||||
git update-index --unresolve fi/le &&
|
git update-index --unresolve fi/le &&
|
||||||
|
git ls-files --resolve-undo fi/le >actual &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
|
git ls-files -u >actual &&
|
||||||
|
test_line_count = 3 actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'unmerge removal' '
|
||||||
|
prime_resolve_undo remove &&
|
||||||
|
git update-index --unresolve fi/le &&
|
||||||
|
git ls-files --resolve-undo fi/le >actual &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
|
git ls-files -u >actual &&
|
||||||
|
test_line_count = 3 actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'unmerge removal after committing' '
|
||||||
|
prime_resolve_undo remove &&
|
||||||
|
git commit -m "record to nuke MERGE_HEAD" &&
|
||||||
|
git update-index --unresolve fi/le &&
|
||||||
|
git ls-files --resolve-undo fi/le >actual &&
|
||||||
|
test_must_be_empty actual &&
|
||||||
git ls-files -u >actual &&
|
git ls-files -u >actual &&
|
||||||
test_line_count = 3 actual
|
test_line_count = 3 actual
|
||||||
'
|
'
|
||||||
|
Loading…
Reference in New Issue
Block a user