@ -58,6 +58,11 @@ static const char * const git_stash_helper_clear_usage[] = {
@@ -58,6 +58,11 @@ static const char * const git_stash_helper_clear_usage[] = {
NULL
};
static const char * const git_stash_helper_store_usage[] = {
N_("git stash--helper store [-m|--message <message>] [-q|--quiet] <commit>"),
NULL
};
static const char *ref_stash = "refs/stash";
static struct strbuf stash_index_path = STRBUF_INIT;
@ -729,6 +734,61 @@ static int show_stash(int argc, const char **argv, const char *prefix)
@@ -729,6 +734,61 @@ static int show_stash(int argc, const char **argv, const char *prefix)
return diff_result_code(&rev.diffopt, 0);
}
static int do_store_stash(const struct object_id *w_commit, const char *stash_msg,
int quiet)
{
if (!stash_msg)
stash_msg = "Created via \"git stash store\".";
if (update_ref(stash_msg, ref_stash, w_commit, NULL,
REF_FORCE_CREATE_REFLOG,
quiet ? UPDATE_REFS_QUIET_ON_ERR :
UPDATE_REFS_MSG_ON_ERR)) {
if (!quiet) {
fprintf_ln(stderr, _("Cannot update %s with %s"),
ref_stash, oid_to_hex(w_commit));
}
return -1;
}
return 0;
}
static int store_stash(int argc, const char **argv, const char *prefix)
{
int quiet = 0;
const char *stash_msg = NULL;
struct object_id obj;
struct object_context dummy;
struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet")),
OPT_STRING('m', "message", &stash_msg, "message",
N_("stash message")),
OPT_END()
};
argc = parse_options(argc, argv, prefix, options,
git_stash_helper_store_usage,
PARSE_OPT_KEEP_UNKNOWN);
if (argc != 1) {
if (!quiet)
fprintf_ln(stderr, _("\"git stash store\" requires one "
"<commit> argument"));
return -1;
}
if (get_oid_with_context(argv[0], quiet ? GET_OID_QUIETLY : 0, &obj,
&dummy)) {
if (!quiet)
fprintf_ln(stderr, _("Cannot update %s with %s"),
ref_stash, argv[0]);
return -1;
}
return do_store_stash(&obj, stash_msg, quiet);
}
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
{
pid_t pid = getpid();
@ -763,6 +823,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
@@ -763,6 +823,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
return !!list_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "show"))
return !!show_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "store"))
return !!store_stash(argc, argv, prefix);
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
git_stash_helper_usage, options);