git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>]
git stash drop [-q | --quiet] [<stash>]
git stash pop [--index] [-q | --quiet] [<stash>]
-git stash apply [--index] [-q | --quiet] [<stash>]
+git stash apply [--index] [-q | --quiet] [--label-ours=<label>] [--label-theirs=<label>] [--label-base=<label>] [<stash>]
git stash branch <branchname> [<stash>]
git stash [push] [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
[-u | --include-untracked] [-a | --all] [(-m | --message) <message>]
(which are stored in the index, where you therefore can no longer
apply the changes as they were originally).
+`--label-ours=<label>`::
+`--label-theirs=<label>`::
+`--label-base=<label>`::
+ These options are only valid for the `apply` command.
++
+Use the given labels in conflict markers instead of the default
+"Updated upstream", "Stashed changes", and "Stash base".
+`--label-base` only has an effect with merge.conflictStyle=diff3.
+
`-k`::
`--keep-index`::
`--no-keep-index`::
#define BUILTIN_STASH_POP_USAGE \
N_("git stash pop [--index] [-q | --quiet] [<stash>]")
#define BUILTIN_STASH_APPLY_USAGE \
- N_("git stash apply [--index] [-q | --quiet] [<stash>]")
+ N_("git stash apply [--index] [-q | --quiet] [--label-ours=<label>] [--label-theirs=<label>] [--label-base=<label>] [<stash>]")
#define BUILTIN_STASH_BRANCH_USAGE \
N_("git stash branch <branchname> [<stash>]")
#define BUILTIN_STASH_STORE_USAGE \
}
static int do_apply_stash(const char *prefix, struct stash_info *info,
- int index, int quiet)
+ int index, int quiet,
+ const char *label_ours, const char *label_theirs,
+ const char *label_base)
{
int clean, ret;
int has_index = index;
init_ui_merge_options(&o, the_repository);
- o.branch1 = "Updated upstream";
- o.branch2 = "Stashed changes";
- o.ancestor = "Stash base";
+ o.branch1 = label_ours ? label_ours : "Updated upstream";
+ o.branch2 = label_theirs ? label_theirs : "Stashed changes";
+ o.ancestor = label_base ? label_base : "Stash base";
if (oideq(&info->b_tree, &c_tree))
o.branch1 = "Version stash was based on";
int ret = -1;
int quiet = 0;
int index = use_index;
+ const char *label_ours = NULL, *label_theirs = NULL, *label_base = NULL;
struct stash_info info = STASH_INFO_INIT;
struct option options[] = {
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
OPT_BOOL(0, "index", &index,
N_("attempt to recreate the index")),
+ OPT_STRING(0, "label-ours", &label_ours, N_("label"),
+ N_("label for the upstream side in conflict markers")),
+ OPT_STRING(0, "label-theirs", &label_theirs, N_("label"),
+ N_("label for the stashed side in conflict markers")),
+ OPT_STRING(0, "label-base", &label_base, N_("label"),
+ N_("label for the base in diff3 conflict markers")),
OPT_END()
};
if (get_stash_info(&info, argc, argv))
goto cleanup;
- ret = do_apply_stash(prefix, &info, index, quiet);
+ ret = do_apply_stash(prefix, &info, index, quiet,
+ label_ours, label_theirs, label_base);
cleanup:
free_stash_info(&info);
return ret;
if (get_stash_info_assert(&info, argc, argv))
goto cleanup;
- if ((ret = do_apply_stash(prefix, &info, index, quiet)))
+ if ((ret = do_apply_stash(prefix, &info, index, quiet,
+ NULL, NULL, NULL)))
printf_ln(_("The stash entry is kept in case "
"you need it again."));
else
strvec_push(&cp.args, oid_to_hex(&info.b_commit));
ret = run_command(&cp);
if (!ret)
- ret = do_apply_stash(prefix, &info, 1, 0);
+ ret = do_apply_stash(prefix, &info, 1, 0,
+ NULL, NULL, NULL);
if (!ret && info.is_stash_ref)
ret = do_drop_stash(&info, 0);
git add other-file &&
test_tick &&
git commit -m initial &&
+ git tag initial &&
echo 2 >file &&
git add file &&
echo 3 >file &&
test_cmp expect file
'
+test_expect_success 'apply with custom conflict labels' '
+ git reset --hard initial &&
+ test_commit label-base conflict-file base-content &&
+ echo stashed >conflict-file &&
+ git stash push -m "stashed" &&
+ test_commit label-upstream conflict-file upstream-content &&
+ test_must_fail git -c merge.conflictStyle=diff3 stash apply --label-ours=UP --label-theirs=STASH &&
+ test_grep "^<<<<<<< UP" conflict-file &&
+ test_grep "^||||||| Stash base" conflict-file &&
+ test_grep "^>>>>>>> STASH" conflict-file
+'
+
+test_expect_success 'apply with empty conflict labels' '
+ git reset --hard initial &&
+ test_commit empty-label-base conflict-file base-content &&
+ echo stashed >conflict-file &&
+ git stash push -m "stashed" &&
+ test_commit empty-label-upstream conflict-file upstream-content &&
+ test_must_fail git stash apply --label-ours= --label-theirs= &&
+ test_grep "^<<<<<<<$" conflict-file &&
+ test_grep "^>>>>>>>$" conflict-file
+'
+
test_done