[PATCH] stash: allow custom conflict labels for pop
flat view
COOLING9d
From: Harald Nordgren via GitGitGadget <hidden>
Date: 2026-09-30 20:58:51
Subsystem:
documentation, the rest · Maintainers:
Jonathan Corbet, Linus Torvalds
From: Harald Nordgren <redacted>
Since 13817db274 (stash: add --label-ours, --label-theirs, --label-base
for apply, 2026-04-28), "git stash apply" accepts custom labels for
conflict markers, but "git stash pop" does not, although it applies the
entry the same way and only differs by dropping it afterward. A caller
that wants its own labels has to use apply and drop the entry itself.
Teach "git stash pop" the same three options.
Signed-off-by: Harald Nordgren <redacted>
---
stash: allow custom conflict labels for pop
git stash pop now accepts the conflict label options that git stash
apply gained in 2.55.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2430%2FHaraldNordgren%2Fstash-pop-labels-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2430/HaraldNordgren/stash-pop-labels-v1
Pull-Request: https://github.com/git/git/pull/2430
Documentation/git-stash.adoc | 4 ++--
builtin/stash.c | 11 +++++++++--
t/t3903-stash.sh | 23 +++++++++++++++++++++++
3 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-stash.adoc b/Documentation/git-stash.adoc
index fc6a9a008c..187b1a50d3 100644
--- a/Documentation/git-stash.adoc
+++ b/Documentation/git-stash.adoc@@ -11,7 +11,7 @@ SYNOPSIS git stash list [<log-options>] 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 pop [--index] [-q | --quiet] [--label-ours=<label>] [--label-theirs=<label>] [--label-base=<label>] [<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]
@@ -198,7 +198,7 @@ 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. + These options are only valid for `pop` and `apply` commands. + Use the given labels in conflict markers instead of the default "Updated upstream", "Stashed changes", and "Stash base".
diff --git a/builtin/stash.c b/builtin/stash.c
index 7a9843413b..3a3c46d6cf 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c@@ -43,7 +43,7 @@ #define BUILTIN_STASH_DROP_USAGE \ N_("git stash drop [-q | --quiet] [<stash>]") #define BUILTIN_STASH_POP_USAGE \ - N_("git stash pop [--index] [-q | --quiet] [<stash>]") + N_("git stash pop [--index] [-q | --quiet] [--label-ours=<label>] [--label-theirs=<label>] [--label-base=<label>] [<stash>]") #define BUILTIN_STASH_APPLY_USAGE \ N_("git stash apply [--index] [-q | --quiet] [--label-ours=<label>] [--label-theirs=<label>] [--label-base=<label>] [<stash>]") #define BUILTIN_STASH_BRANCH_USAGE \
@@ -885,11 +885,18 @@ static int pop_stash(int argc, const char **argv, const char *prefix, int ret = -1; int index = use_index; int quiet = 0; + 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() };
@@ -900,7 +907,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix, goto cleanup; if ((ret = do_apply_stash(prefix, &info, index, quiet, - NULL, NULL, NULL))) + label_ours, label_theirs, label_base))) printf_ln(_("The stash entry is kept in case " "you need it again.")); else
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 721158606f..58a41f4c65 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh@@ -1841,6 +1841,29 @@ test_expect_success 'pop exits 1 on conflicts and keeps the stash entry' ' test_grep pop-stashed list ' +test_expect_success 'pop with custom conflict labels' ' + git reset --hard initial && + test_commit pop-label-base conflict-file base-content && + echo stashed >conflict-file && + git stash push -m "stashed" && + test_commit pop-label-upstream conflict-file upstream-content && + test_expect_code 1 git -c merge.conflictStyle=diff3 stash pop --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 'pop with empty conflict labels' ' + git reset --hard initial && + test_commit pop-empty-label-base conflict-file base-content && + echo stashed >conflict-file && + git stash push -m "stashed" && + test_commit pop-empty-label-upstream conflict-file upstream-content && + test_expect_code 1 git stash pop --label-ours= --label-theirs= && + test_grep "^<<<<<<<$" conflict-file && + test_grep "^>>>>>>>$" conflict-file +' + test_expect_success 'stash branch exits with a non-1 status on errors' ' git reset --hard initial && echo stashed >file &&
base-commit: a018953688f1b10bddf91bff8747068f5f4746a4 -- gitgitgadget