sequencer: teach autostash apply to take optional conflict marker labels
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>
Harald Nordgren committed
Apr 28, 2026 at 18:39 UTC
e1c8b2d4ece1ada17e818b8c1b0760a47c00cae9
4 files changed
+40
-14
builtin/commit.c
+2
-1
@@ -1979,7 +1979,8 @@ int cmd_commit(int argc,
1979
&oid, flags);
1980
}
1981
1982
- apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1982
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1983
+ NULL, NULL, NULL, NULL);
1984
1985
cleanup:
1986
free_commit_extra_headers(extra);
builtin/merge.c
+6
-3
@@ -537,7 +537,8 @@ static void finish(struct commit *head_commit,
537
run_hooks_l(the_repository, "post-merge", squash ? "1" : "0", NULL);
538
539
if (new_head)
540
- apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
540
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
541
+ NULL, NULL, NULL, NULL);
542
strbuf_release(&reflog_message);
543
}
544
@@ -1678,7 +1679,8 @@ int cmd_merge(int argc,
1679
&head_commit->object.oid,
1680
&commit->object.oid,
1681
overwrite_ignore)) {
1681
- apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1682
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1683
+ NULL, NULL, NULL, NULL);
1684
ret = 1;
1685
goto done;
1686
}
@@ -1851,7 +1853,8 @@ int cmd_merge(int argc,
1853
else
1854
fprintf(stderr, _("Merge with strategy %s failed.\n"),
1855
use_strategies[0]->name);
1854
- apply_autostash_ref(the_repository, "MERGE_AUTOSTASH");
1856
+ apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1857
+ NULL, NULL, NULL, NULL);
1858
ret = 2;
1859
goto done;
1860
} else if (best_strategy == wt_strategy)
sequencer.c
+29
-9
@@ -4727,7 +4727,10 @@ void create_autostash_ref(struct repository *r, const char *refname,
4727
create_autostash_internal(r, NULL, refname, message, silent);
4728
}
4729
4730
-static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4730
+static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
4731
+ const char *label_ours, const char *label_theirs,
4732
+ const char *label_base,
4733
+ const char *stash_msg)
4734
{
4735
struct child_process child = CHILD_PROCESS_INIT;
4736
int ret = 0;
@@ -4738,6 +4741,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4741
child.no_stderr = 1;
4742
strvec_push(&child.args, "stash");
4743
strvec_push(&child.args, "apply");
4744
+ if (label_ours)
4745
+ strvec_pushf(&child.args, "--label-ours=%s", label_ours);
4746
+ if (label_theirs)
4747
+ strvec_pushf(&child.args, "--label-theirs=%s", label_theirs);
4748
+ if (label_base)
4749
+ strvec_pushf(&child.args, "--label-base=%s", label_base);
4750
strvec_push(&child.args, stash_oid);
4751
ret = run_command(&child);
4752
}
@@ -4751,7 +4760,7 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply)
4760
strvec_push(&store.args, "stash");
4761
strvec_push(&store.args, "store");
4762
strvec_push(&store.args, "-m");
4754
- strvec_push(&store.args, "autostash");
4763
+ strvec_push(&store.args, stash_msg ? stash_msg : "autostash");
4764
strvec_push(&store.args, "-q");
4765
strvec_push(&store.args, stash_oid);
4766
if (run_command(&store))
@@ -4782,7 +4791,8 @@ static int apply_save_autostash(const char *path, int attempt_apply)
4791
}
4792
strbuf_trim(&stash_oid);
4793
4785
- ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply);
4794
+ ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
4795
+ NULL, NULL, NULL, NULL);
4796
4797
unlink(path);
4798
strbuf_release(&stash_oid);
@@ -4801,11 +4811,14 @@ int apply_autostash(const char *path)
4811
4812
int apply_autostash_oid(const char *stash_oid)
4813
{
4804
- return apply_save_autostash_oid(stash_oid, 1);
4814
+ return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL);
4815
}
4816
4817
static int apply_save_autostash_ref(struct repository *r, const char *refname,
4808
- int attempt_apply)
4818
+ int attempt_apply,
4819
+ const char *label_ours, const char *label_theirs,
4820
+ const char *label_base,
4821
+ const char *stash_msg)
4822
{
4823
struct object_id stash_oid;
4824
char stash_oid_hex[GIT_MAX_HEXSZ + 1];
@@ -4821,7 +4834,9 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
4834
return error(_("autostash reference is a symref"));
4835
4836
oid_to_hex_r(stash_oid_hex, &stash_oid);
4824
- ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply);
4837
+ ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
4838
+ label_ours, label_theirs, label_base,
4839
+ stash_msg);
4840
4841
refs_delete_ref(get_main_ref_store(r), "", refname,
4842
&stash_oid, REF_NO_DEREF);
@@ -4831,12 +4846,17 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
4846
4847
int save_autostash_ref(struct repository *r, const char *refname)
4848
{
4834
- return apply_save_autostash_ref(r, refname, 0);
4849
+ return apply_save_autostash_ref(r, refname, 0,
4850
+ NULL, NULL, NULL, NULL);
4851
}
4852
4837
-int apply_autostash_ref(struct repository *r, const char *refname)
4853
+int apply_autostash_ref(struct repository *r, const char *refname,
4854
+ const char *label_ours, const char *label_theirs,
4855
+ const char *label_base, const char *stash_msg)
4856
{
4839
- return apply_save_autostash_ref(r, refname, 1);
4857
+ return apply_save_autostash_ref(r, refname, 1,
4858
+ label_ours, label_theirs, label_base,
4859
+ stash_msg);
4860
}
4861
4862
static int checkout_onto(struct repository *r, struct replay_opts *opts,
sequencer.h
+3
-1
@@ -235,7 +235,9 @@ int save_autostash(const char *path);
235
int save_autostash_ref(struct repository *r, const char *refname);
236
int apply_autostash(const char *path);
237
int apply_autostash_oid(const char *stash_oid);
238
-int apply_autostash_ref(struct repository *r, const char *refname);
238
+int apply_autostash_ref(struct repository *r, const char *refname,
239
+ const char *label_ours, const char *label_theirs,
240
+ const char *label_base, const char *stash_msg);
241
242
#define SUMMARY_INITIAL_COMMIT (1 << 0)
243
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)