Skip to content

Commit cd9c64b

Browse files
stash: add --ours-label, --theirs-label, --base-label for apply
Allow callers of "git stash apply" to pass custom labels for conflict markers instead of the default "Updated upstream" and "Stashed changes". Document the new options and add a test. Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
1 parent ca1db8a commit cd9c64b

3 files changed

Lines changed: 29 additions & 2 deletions

File tree

Documentation/git-stash.adoc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ git stash list [<log-options>]
1212
git stash show [-u | --include-untracked | --only-untracked] [<diff-options>] [<stash>]
1313
git stash drop [-q | --quiet] [<stash>]
1414
git stash pop [--index] [-q | --quiet] [<stash>]
15-
git stash apply [--index] [-q | --quiet] [<stash>]
15+
git stash apply [--index] [-q | --quiet] [--ours-label=<label>] [--theirs-label=<label>] [--base-label=<label>] [<stash>]
1616
git stash branch <branchname> [<stash>]
1717
git stash [push [-p | --patch] [-S | --staged] [-k | --[no-]keep-index] [-q | --quiet]
1818
[-u | --include-untracked] [-a | --all] [(-m | --message) <message>]
@@ -197,6 +197,15 @@ the index's ones. However, this can fail, when you have conflicts
197197
(which are stored in the index, where you therefore can no longer
198198
apply the changes as they were originally).
199199
200+
`--ours-label=<label>`::
201+
`--theirs-label=<label>`::
202+
`--base-label=<label>`::
203+
These options are only valid for the `apply` command.
204+
+
205+
Use the given labels in conflict markers instead of the default
206+
"Updated upstream", "Stashed changes", and "Stash base".
207+
`--base-label` only has an effect with merge.conflictStyle=diff3.
208+
200209
`-k`::
201210
`--keep-index`::
202211
`--no-keep-index`::

builtin/stash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#define BUILTIN_STASH_POP_USAGE \
4545
N_("git stash pop [--index] [-q | --quiet] [<stash>]")
4646
#define BUILTIN_STASH_APPLY_USAGE \
47-
N_("git stash apply [--index] [-q | --quiet] [<stash>]")
47+
N_("git stash apply [--index] [-q | --quiet] [--ours-label=<label>] [--theirs-label=<label>] [--base-label=<label>] [<stash>]")
4848
#define BUILTIN_STASH_BRANCH_USAGE \
4949
N_("git stash branch <branchname> [<stash>]")
5050
#define BUILTIN_STASH_STORE_USAGE \

t/t3903-stash.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,6 +1666,24 @@ test_expect_success 'restore untracked files even when we hit conflicts' '
16661666
)
16671667
'
16681668

1669+
test_expect_success 'apply with custom conflict labels' '
1670+
git init conflict_labels &&
1671+
(
1672+
cd conflict_labels &&
1673+
echo base >file &&
1674+
git add file &&
1675+
git commit -m base &&
1676+
echo stashed >file &&
1677+
git stash push -m "stashed" &&
1678+
echo upstream >file &&
1679+
git add file &&
1680+
git commit -m upstream &&
1681+
test_must_fail git stash apply --ours-label=UP --theirs-label=STASH &&
1682+
grep "^<<<<<<< UP" file &&
1683+
grep "^>>>>>>> STASH" file
1684+
)
1685+
'
1686+
16691687
test_expect_success 'stash create reports a locked index' '
16701688
test_when_finished "rm -rf repo" &&
16711689
git init repo &&

0 commit comments

Comments
 (0)