sequencer: teach autostash apply to report conflicts
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>
Harald Nordgren committed
Jul 25, 2026 at 15:34 UTC
64ffd57fb53718894b289d6919ee930000ebb330
5 files changed
+27
-16
builtin/checkout.c
+2
-1
@@ -1239,7 +1239,8 @@ static int switch_branches(const struct checkout_opts *opts,
1239
new_branch_info->name,
1240
"local",
1241
stash_label_base,
1242
- autostash_msg.buf);
1242
+ autostash_msg.buf,
1243
+ NULL);
1244
}
1245
if (ret) {
1246
branch_info_release(&old_branch_info);
builtin/commit.c
+1
-1
@@ -1980,7 +1980,7 @@ int cmd_commit(int argc,
1980
}
1981
1982
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1983
- NULL, NULL, NULL, NULL);
1983
+ NULL, NULL, NULL, NULL, NULL);
1984
1985
cleanup:
1986
free_commit_extra_headers(extra);
builtin/merge.c
+3
-3
@@ -538,7 +538,7 @@ static void finish(struct commit *head_commit,
538
539
if (new_head)
540
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
541
- NULL, NULL, NULL, NULL);
541
+ NULL, NULL, NULL, NULL, NULL);
542
strbuf_release(&reflog_message);
543
}
544
@@ -1680,7 +1680,7 @@ int cmd_merge(int argc,
1680
&commit->object.oid,
1681
overwrite_ignore)) {
1682
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1683
- NULL, NULL, NULL, NULL);
1683
+ NULL, NULL, NULL, NULL, NULL);
1684
ret = 1;
1685
goto done;
1686
}
@@ -1844,7 +1844,7 @@ int cmd_merge(int argc,
1844
fprintf(stderr, _("Merge with strategy %s failed.\n"),
1845
use_strategies[0]->name);
1846
apply_autostash_ref(the_repository, "MERGE_AUTOSTASH",
1847
- NULL, NULL, NULL, NULL);
1847
+ NULL, NULL, NULL, NULL, NULL);
1848
ret = 2;
1849
goto done;
1850
} else if (best_strategy == wt_strategy)
sequencer.c
+19
-10
@@ -4730,7 +4730,8 @@ void create_autostash_ref(struct repository *r, const char *refname,
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)
4733
+ const char *stash_msg,
4734
+ bool *conflicted)
4735
{
4736
struct child_process child = CHILD_PROCESS_INIT;
4737
int ret = 0;
@@ -4765,14 +4766,16 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply,
4766
strvec_push(&store.args, stash_oid);
4767
if (run_command(&store))
4768
ret = error(_("cannot store %s"), stash_oid);
4768
- else if (attempt_apply)
4769
+ else if (attempt_apply) {
4770
+ if (conflicted)
4771
+ *conflicted = true;
4772
fprintf(stderr,
4773
_("Your local changes are stashed, however applying them\n"
4774
"resulted in conflicts. You can either resolve the conflicts\n"
4775
"and then discard the stash with \"git stash drop\", or, if you\n"
4776
"do not want to resolve them now, run \"git reset --hard\" and\n"
4777
"apply the local changes later by running \"git stash pop\".\n"));
4775
- else
4778
+ } else
4779
fprintf(stderr,
4780
_("Autostash exists; creating a new stash entry.\n"
4781
"Your changes are safe in the stash.\n"
@@ -4796,7 +4799,7 @@ static int apply_save_autostash(const char *path, int attempt_apply)
4799
strbuf_trim(&stash_oid);
4800
4801
ret = apply_save_autostash_oid(stash_oid.buf, attempt_apply,
4799
- NULL, NULL, NULL, NULL);
4802
+ NULL, NULL, NULL, NULL, NULL);
4803
4804
unlink(path);
4805
strbuf_release(&stash_oid);
@@ -4815,19 +4818,24 @@ int apply_autostash(const char *path)
4818
4819
int apply_autostash_oid(const char *stash_oid)
4820
{
4818
- return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL);
4821
+ return apply_save_autostash_oid(stash_oid, 1, NULL, NULL, NULL, NULL,
4822
+ NULL);
4823
}
4824
4825
static int apply_save_autostash_ref(struct repository *r, const char *refname,
4826
int attempt_apply,
4827
const char *label_ours, const char *label_theirs,
4828
const char *label_base,
4825
- const char *stash_msg)
4829
+ const char *stash_msg,
4830
+ bool *conflicted)
4831
{
4832
struct object_id stash_oid;
4833
char stash_oid_hex[GIT_MAX_HEXSZ + 1];
4834
int flag, ret;
4835
4836
+ if (conflicted)
4837
+ *conflicted = false;
4838
+
4839
if (!refs_ref_exists(get_main_ref_store(r), refname))
4840
return 0;
4841
@@ -4840,7 +4848,7 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
4848
oid_to_hex_r(stash_oid_hex, &stash_oid);
4849
ret = apply_save_autostash_oid(stash_oid_hex, attempt_apply,
4850
label_ours, label_theirs, label_base,
4843
- stash_msg);
4851
+ stash_msg, conflicted);
4852
4853
refs_delete_ref(get_main_ref_store(r), "", refname,
4854
&stash_oid, REF_NO_DEREF);
@@ -4851,16 +4859,17 @@ static int apply_save_autostash_ref(struct repository *r, const char *refname,
4859
int save_autostash_ref(struct repository *r, const char *refname)
4860
{
4861
return apply_save_autostash_ref(r, refname, 0,
4854
- NULL, NULL, NULL, NULL);
4862
+ NULL, NULL, NULL, NULL, NULL);
4863
}
4864
4865
int apply_autostash_ref(struct repository *r, const char *refname,
4866
const char *label_ours, const char *label_theirs,
4859
- const char *label_base, const char *stash_msg)
4867
+ const char *label_base, const char *stash_msg,
4868
+ bool *conflicted)
4869
{
4870
return apply_save_autostash_ref(r, refname, 1,
4871
label_ours, label_theirs, label_base,
4863
- stash_msg);
4872
+ stash_msg, conflicted);
4873
}
4874
4875
static int checkout_onto(struct repository *r, struct replay_opts *opts,
sequencer.h
+2
-1
@@ -237,7 +237,8 @@ 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,
239
const char *label_ours, const char *label_theirs,
240
- const char *label_base, const char *stash_msg);
240
+ const char *label_base, const char *stash_msg,
241
+ bool *conflicted);
242
243
#define SUMMARY_INITIAL_COMMIT (1 << 0)
244
#define SUMMARY_SHOW_AUTHOR_DATE (1 << 1)