]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: teach autostash apply to report conflicts
authorHarald Nordgren <haraldnordgren@gmail.com>
Sat, 25 Jul 2026 15:34:28 +0000 (15:34 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Jul 2026 22:08:18 +0000 (15:08 -0700)
Add a conflicted parameter to apply_save_autostash_oid() and
apply_save_autostash_ref() so callers can learn whether applying the
stash resulted in conflicts.  Thread the parameter through
apply_autostash_ref() and update existing callers to pass NULL.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/checkout.c
builtin/commit.c
builtin/merge.c
sequencer.c
sequencer.h

index b78b3a1d16def48852204be587c9131d5fb5363d..5858d1fc309dd0e34c8954abfcd51aae9ac65339 100644 (file)
@@ -1239,7 +1239,8 @@ static int switch_branches(const struct checkout_opts *opts,
                                            new_branch_info->name,
                                            "local",
                                            stash_label_base,
-                                           autostash_msg.buf);
+                                           autostash_msg.buf,
+                                           NULL);
                }
                if (ret) {
                        branch_info_release(&old_branch_info);
index 28f617450345064db0cb0be233aa2773c0cba2ba..d678a81865a6e0e32812c1f395adc91ec661ce49 100644 (file)
@@ -1980,7 +1980,7 @@ int cmd_commit(int argc,
        }
 
        apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
-                           NULL, NULL, NULL, NULL);
+                           NULL, NULL, NULL, NULL, NULL);
 
 cleanup:
        free_commit_extra_headers(extra);
index 5b46a596f0bdf462270e0027edaf3c318dff9bac..cecb8fb716eb8f9c61df0dc8e2642ce3cdff4ddf 100644 (file)
@@ -538,7 +538,7 @@ static void finish(struct commit *head_commit,
 
        if (new_head)
                apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
-                                   NULL, NULL, NULL, NULL);
+                                   NULL, NULL, NULL, NULL, NULL);
        strbuf_release(&reflog_message);
 }
 
@@ -1680,7 +1680,7 @@ int cmd_merge(int argc,
                                          &commit->object.oid,
                                          overwrite_ignore)) {
                        apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
-                                           NULL, NULL, NULL, NULL);
+                                           NULL, NULL, NULL, NULL, NULL);
                        ret = 1;
                        goto done;
                }
@@ -1844,7 +1844,7 @@ int cmd_merge(int argc,
                        fprintf(stderr, _("Merge with strategy %s failed.\n"),
                                use_strategies[0]->name);
                apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
-                                   NULL, NULL, NULL, NULL);
+                                   NULL, NULL, NULL, NULL, NULL);
                ret = 2;
                goto done;
        } else if (best_strategy == wt_strategy)
index 57855b0066ac98646facc3b3a610248b5d80a28f..1f4a9705c27a19be7fc7ef104b5c598fc2d5e434 100644 (file)
@@ -4730,7 +4730,8 @@ void create_autostash_ref(struct repository *r, const char *refname,
 static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
                                    const char *label_ours, const char *label_theirs,
                                    const char *label_base,
-                                   const char *stash_msg)
+                                   const char *stash_msg,
+                                   bool *conflicted)
 {
        struct child_process child = CHILD_PROCESS_INIT;
        int ret = 0;
@@ -4765,14 +4766,16 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
                strvec_push(&store.args, stash_oid);
                if (run_command(&store))
                        ret = error(_("cannot store %s"), stash_oid);
-               else if (attempt_apply)
+               else if (attempt_apply) {
+                       if (conflicted)
+                               *conflicted = true;
                        fprintf(stderr,
                                _("Your local changes are stashed, however applying them\n"
                                  "resulted in conflicts.  You can either resolve the conflicts\n"
                                  "and then discard the stash with \"git stash drop\", or, if you\n"
                                  "do not want to resolve them now, run \"git reset --hard\" and\n"
                                  "apply the local changes later by running \"git stash pop\".\n"));
-               else
+               else
                        fprintf(stderr,
                                _("Autostash exists; creating a new stash entry.\n"
                                  "Your changes are safe in the stash.\n"
@@ -4796,7 +4799,7 @@ static int apply_save_autostash(const char *path, int attempt_apply)
        strbuf_trim(&stash_oid);
 
        ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
-                                     NULL, NULL, NULL, NULL);
+                                     NULL, NULL, NULL, NULL, NULL);
 
        unlink(path);
        strbuf_release(&stash_oid);
@@ -4815,19 +4818,24 @@ int apply_autostash(const char *path)
 
 int apply_autostash_oid(const char *stash_oid)
 {
-       return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL);
+       return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL,
+                                      NULL);
 }
 
 static int apply_save_autostash_ref(struct repository *r, const char *refname,
                                    int attempt_apply,
                                    const char *label_ours, const char *label_theirs,
                                    const char *label_base,
-                                   const char *stash_msg)
+                                   const char *stash_msg,
+                                   bool *conflicted)
 {
        struct object_id stash_oid;
        char stash_oid_hex[GIT_MAX_HEXSZ + 1];
        int flag, ret;
 
+       if (conflicted)
+               *conflicted = false;
+
        if (!refs_ref_exists(get_main_ref_store(r), refname))
                return 0;
 
@@ -4840,7 +4848,7 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
        oid_to_hex_r(stash_oid_hex, &stash_oid);
        ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
                                       label_ours, label_theirs, label_base,
-                                      stash_msg);
+                                      stash_msg, conflicted);
 
        refs_delete_ref(get_main_ref_store(r), "", refname,
                        &stash_oid, REF_NO_DEREF);
@@ -4851,16 +4859,17 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
 int save_autostash_ref(struct repository *r, const char *refname)
 {
        return apply_save_autostash_ref(r, refname, 0,
-                                       NULL, NULL, NULL, NULL);
+                                       NULL, NULL, NULL, NULL, NULL);
 }
 
 int apply_autostash_ref(struct repository *r, const char *refname,
                        const char *label_ours, const char *label_theirs,
-                       const char *label_base, const char *stash_msg)
+                       const char *label_base, const char *stash_msg,
+                       bool *conflicted)
 {
        return apply_save_autostash_ref(r, refname, 1,
                                        label_ours, label_theirs, label_base,
-                                       stash_msg);
+                                       stash_msg, conflicted);
 }
 
 static int checkout_onto(struct repository *r, struct replay_opts *opts,
index 3164bd437d6a22b8a652746586ef90e7e7b31a0b..3e9ff093b2d1dd282504f0a917bb0be33d1a4729 100644 (file)
@@ -237,7 +237,8 @@ int apply_autostash(const char *path);
 int apply_autostash_oid(const char *stash_oid);
 int apply_autostash_ref(struct repository *r, const char *refname,
                        const char *label_ours, const char *label_theirs,
-                       const char *label_base, const char *stash_msg);
+                       const char *label_base, const char *stash_msg,
+                       bool *conflicted);
 
 #define SUMMARY_INITIAL_COMMIT   (1 << 0)
 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)