Skip to content

Commit 1369f14

Browse files
newrengitster
authored andcommitted
merge: fix save_state() to work when there are stat-dirty files
When there are stat-dirty files, but no files are modified, `git stash create` exits with unsuccessful status. This causes merge to fail. Copy some code from sequencer.c's create_autostash to refresh the index first to avoid this problem. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f240b8 commit 1369f14

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

builtin/merge.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,16 @@ static int save_state(struct object_id *stash)
313313
int len;
314314
struct child_process cp = CHILD_PROCESS_INIT;
315315
struct strbuf buffer = STRBUF_INIT;
316+
struct lock_file lock_file = LOCK_INIT;
317+
int fd;
316318
int rc = -1;
317319

320+
fd = repo_hold_locked_index(the_repository, &lock_file, 0);
321+
refresh_cache(REFRESH_QUIET);
322+
if (0 <= fd)
323+
repo_update_index_if_able(the_repository, &lock_file);
324+
rollback_lock_file(&lock_file);
325+
318326
strvec_pushl(&cp.args, "stash", "create", NULL);
319327
cp.out = -1;
320328
cp.git_cmd = 1;

t/t6424-merge-unrelated-index-changes.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,17 @@ test_expect_success 'subtree' '
275275
test_path_is_missing .git/MERGE_HEAD
276276
'
277277

278+
test_expect_success 'avoid failure due to stat-dirty files' '
279+
git reset --hard &&
280+
git checkout B^0 &&
281+
282+
# Make "a" be stat-dirty
283+
test-tool chmtime =+1 a &&
284+
285+
# stat-dirty file should not prevent stash creation in builtin/merge.c
286+
git merge -s resolve -s recursive D^0
287+
'
288+
278289
test_expect_success 'with multiple strategies, recursive or ort failure do not early abort' '
279290
git reset --hard &&
280291
git checkout B^0 &&

0 commit comments

Comments
 (0)