[PATCH v2 3/6] merge: fix save_state() to work when there are racy-dirty files
- From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Jun 19, 2022, 06:50 UTC
- Message-ID
- <89e5e633241e45a0c4b18289ab2fafdaabc8191e.1655621424.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.1231.v2.git.1655621424.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
When there are racy-dirty files, but no files are modified, `git stash create` exits with unsuccessful status. This causes merge to fail. Refresh the index first to avoid this problem.
Signed-off-by: Elijah Newren <newren@gmail.com> --- builtin/merge.c | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/builtin/merge.c b/builtin/merge.c index 00de224a2da..8ce4336dd3f 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -313,8 +313,16 @@ static int save_state(struct object_id *stash) int len; struct child_process cp = CHILD_PROCESS_INIT; struct strbuf buffer = STRBUF_INIT; + struct lock_file lock_file = LOCK_INIT; + int fd; int rc = -1; + fd = repo_hold_locked_index(the_repository, &lock_file, 0); + refresh_cache(REFRESH_QUIET); + if (0 <= fd) + repo_update_index_if_able(the_repository, &lock_file); + rollback_lock_file(&lock_file); + strvec_pushl(&cp.args, "stash", "create", NULL); cp.out = -1; cp.git_cmd = 1;
-- gitgitgadget