]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer: teach autostash apply to take optional conflict marker labels
authorHarald Nordgren <haraldnordgren@gmail.com>
Fri, 24 Apr 2026 21:10:10 +0000 (21:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sat, 25 Apr 2026 10:28:56 +0000 (19:28 +0900)
Add label_ours, label_theirs, label_base, and stash_msg parameters to
apply_autostash_ref() and the autostash apply machinery so callers can
pass custom conflict marker labels through to
"git stash apply --label-ours/--label-theirs/--label-base", as well as
a custom stash message for "git stash store -m".

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

index a3e52ac9ca66071fb73024c86358c3526d3627fa..28f617450345064db0cb0be233aa2773c0cba2ba 100644 (file)
@@ -1979,7 +1979,8 @@ int cmd_commit(int argc,
                                     &oid, flags);
        }
 
-       apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
+       apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
+                           NULL, NULL, NULL, NULL);
 
 cleanup:
        free_commit_extra_headers(extra);
index 3ebe190ef1e21924ad844db4c3523c362cc4078d..aacf8c524e1243cd56fd530b5d99d99f6f7ae69f 100644 (file)
@@ -537,7 +537,8 @@ static void finish(struct commit *head_commit,
        run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
 
        if (new_head)
-               apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
+               apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
+                                   NULL, NULL, NULL, NULL);
        strbuf_release(&reflog_message);
 }
 
@@ -1678,7 +1679,8 @@ int cmd_merge(int argc,
                                          &head_commit->object.oid,
                                          &commit->object.oid,
                                          overwrite_ignore)) {
-                       apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
+                       apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
+                                           NULL, NULL, NULL, NULL);
                        ret = 1;
                        goto done;
                }
@@ -1851,7 +1853,8 @@ int cmd_merge(int argc,
                else
                        fprintf(stderr, _("Merge with strategy %s failed.\n"),
                                use_strategies[0]->name);
-               apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
+               apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
+                                   NULL, NULL, NULL, NULL);
                ret = 2;
                goto done;
        } else if (best_strategy == wt_strategy)
index ff5258f48125e7d8f6624771706eb2d60b6c1c54..7c0376d9e41ec029b6314092910a2311f19299fd 100644 (file)
@@ -4727,7 +4727,10 @@ void create_autostash_ref(struct repository *r, const char *refname,
        create_autostash_internal(r, NULL, refname, message, silent);
 }
 
-static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
+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)
 {
        struct child_process child = CHILD_PROCESS_INIT;
        int ret = 0;
@@ -4738,6 +4741,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
                child.no_stderr = 1;
                strvec_push(&child.args, "stash");
                strvec_push(&child.args, "apply");
+               if (label_ours)
+                       strvec_pushf(&child.args, "--label-ours=%s", label_ours);
+               if (label_theirs)
+                       strvec_pushf(&child.args, "--label-theirs=%s", label_theirs);
+               if (label_base)
+                       strvec_pushf(&child.args, "--label-base=%s", label_base);
                strvec_push(&child.args, stash_oid);
                ret = run_command(&child);
        }
@@ -4751,7 +4760,7 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
                strvec_push(&store.args, "stash");
                strvec_push(&store.args, "store");
                strvec_push(&store.args, "-m");
-               strvec_push(&store.args, "autostash");
+               strvec_push(&store.args, stash_msg ? stash_msg : "autostash");
                strvec_push(&store.args, "-q");
                strvec_push(&store.args, stash_oid);
                if (run_command(&store))
@@ -4782,7 +4791,8 @@ 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);
+       ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
+                                     NULL, NULL, NULL, NULL);
 
        unlink(path);
        strbuf_release(&stash_oid);
@@ -4801,11 +4811,14 @@ int apply_autostash(const char *path)
 
 int apply_autostash_oid(const char *stash_oid)
 {
-       return apply_save_autostash_oid(stash_oid, 1);
+       return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL);
 }
 
 static int apply_save_autostash_ref(struct repository *r, const char *refname,
-                                   int attempt_apply)
+                                   int attempt_apply,
+                                   const char *label_ours, const char *label_theirs,
+                                   const char *label_base,
+                                   const char *stash_msg)
 {
        struct object_id stash_oid;
        char stash_oid_hex[GIT_MAX_HEXSZ + 1];
@@ -4821,7 +4834,9 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
                return error(_("autostash reference is a symref"));
 
        oid_to_hex_r(stash_oid_hex, &stash_oid);
-       ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply);
+       ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
+                                      label_ours, label_theirs, label_base,
+                                      stash_msg);
 
        refs_delete_ref(get_main_ref_store(r), "", refname,
                        &stash_oid, REF_NO_DEREF);
@@ -4831,12 +4846,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);
+       return apply_save_autostash_ref(r, refname, 0,
+                                       NULL, NULL, NULL, NULL);
 }
 
-int apply_autostash_ref(struct repository *r, const char *refname)
+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)
 {
-       return apply_save_autostash_ref(r, refname, 1);
+       return apply_save_autostash_ref(r, refname, 1,
+                                       label_ours, label_theirs, label_base,
+                                       stash_msg);
 }
 
 static int checkout_onto(struct repository *r, struct replay_opts *opts,
index 02d2d9db065dca83e37e7a0594a408aac95630e7..3164bd437d6a22b8a652746586ef90e7e7b31a0b 100644 (file)
@@ -235,7 +235,9 @@ int save_autostash(const char *path);
 int save_autostash_ref(struct repository *r, const char *refname);
 int apply_autostash(const char *path);
 int apply_autostash_oid(const char *stash_oid);
-int apply_autostash_ref(struct repository *r, const char *refname);
+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);
 
 #define SUMMARY_INITIAL_COMMIT   (1 << 0)
 #define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)