3707
strbuf_release(&buf);
3708
}
3709
3710
-int apply_autostash(const char *path)
3710
+static int apply_save_autostash(const char *path, int attempt_apply)
3711
{
3712
struct strbuf stash_oid = STRBUF_INIT;
3713
struct child_process child = CHILD_PROCESS_INIT;
3720
}
3721
strbuf_trim(&stash_oid);
3722
3723
- child.git_cmd = 1;
3724
- child.no_stdout = 1;
3725
- child.no_stderr = 1;
3726
- argv_array_push(&child.args, "stash");
3727
- argv_array_push(&child.args, "apply");
3728
- argv_array_push(&child.args, stash_oid.buf);
3729
- if (!run_command(&child))
3723
+ if (attempt_apply) {
3724
+ child.git_cmd = 1;
3725
+ child.no_stdout = 1;
3726
+ child.no_stderr = 1;
3727
+ argv_array_push(&child.args, "stash");
3728
+ argv_array_push(&child.args, "apply");
3729
+ argv_array_push(&child.args, stash_oid.buf);
3730
+ ret = run_command(&child);
3731
+ }
3732
+
3733
+ if (attempt_apply && !ret)
3734
fprintf(stderr, _("Applied autostash.\n"));
3735
else {
3736
struct child_process store = CHILD_PROCESS_INIT;
3746
ret = error(_("cannot store %s"), stash_oid.buf);
3747
else
3748
fprintf(stderr,
3745
- _("Applying autostash resulted in conflicts.\n"
3749
+ _("%s\n"
3750
"Your changes are safe in the stash.\n"
3751
"You can run \"git stash pop\" or"
3748
- " \"git stash drop\" at any time.\n"));
3752
+ " \"git stash drop\" at any time.\n"),
3753
+ attempt_apply ?
3754
+ _("Applying autostash resulted in conflicts.") :
3755
+ _("Autostash exists; creating a new stash entry."));
3756
}
3757
3758
unlink(path);
3760
return ret;
3761
}
3762
3763
+int save_autostash(const char *path)
3764
+{
3765
+ return apply_save_autostash(path, 0);
3766
+}
3767
+
3768
+int apply_autostash(const char *path)
3769
+{
3770
+ return apply_save_autostash(path, 1);
3771
+}
3772
+
3773
static const char *reflog_message(struct replay_opts *opts,
3774
const char *sub_action, const char *fmt, ...)
3775
{