summaryrefslogtreecommitdiff
path: root/builtin/merge.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2022-07-23 01:53:15 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-07-23 04:45:23 (GMT)
commit1369f1475b998b0022f9bdf3a084ef6e590800aa (patch)
tree5f3a52677ecca8fa030cf3c09a5c156b2da03717 /builtin/merge.c
parent8f240b8bbb63591f15c10e43debaf564e63a66bd (diff)
downloadgit-1369f1475b998b0022f9bdf3a084ef6e590800aa.zip
git-1369f1475b998b0022f9bdf3a084ef6e590800aa.tar.gz
git-1369f1475b998b0022f9bdf3a084ef6e590800aa.tar.bz2
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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge.c')
-rw-r--r--builtin/merge.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index c120ad6..780b4b9 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;