diff --git a/builtin-update-index.c b/builtin-update-index.c index a19e78603c..750db163b9 100644 --- a/builtin-update-index.c +++ b/builtin-update-index.c @@ -433,7 +433,18 @@ static int unresolve_one(const char *path) /* See if there is such entry in the index. */ pos = cache_name_pos(path, namelen); - if (pos < 0) { + if (0 <= pos) { + /* already merged */ + pos = unmerge_cache_entry_at(pos); + if (pos < active_nr) { + struct cache_entry *ce = active_cache[pos]; + if (ce_stage(ce) && + ce_namelen(ce) == namelen && + !memcmp(ce->name, path, namelen)) + return 0; + } + /* no resolve-undo information; fall back */ + } else { /* If there isn't, either it is unmerged, or * resolved as "removed" by mistake. We do not * want to do anything in the former case. diff --git a/cache.h b/cache.h index f479f09190..97b4a74d93 100644 --- a/cache.h +++ b/cache.h @@ -338,6 +338,7 @@ static inline void remove_name_hash(struct cache_entry *ce) #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) #define cache_name_is_other(name, namelen) index_name_is_other(&the_index, (name), (namelen)) #define resolve_undo_clear() resolve_undo_clear_index(&the_index) +#define unmerge_cache_entry_at(at) unmerge_index_entry_at(&the_index, at) #define unmerge_cache(pathspec) unmerge_index(&the_index, pathspec) #endif diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh index ea65f391c1..28e2eb1cec 100755 --- a/t/t2030-unresolve-info.sh +++ b/t/t2030-unresolve-info.sh @@ -108,4 +108,11 @@ test_expect_success 'add records checkout -m undoes' ' grep "^++<<<<<<<" actual ' +test_expect_success 'unmerge with plumbing' ' + prime_resolve_undo && + git update-index --unresolve file && + git ls-files -u >actual && + test $(wc -l