Skip to content

Commit 1328d29

Browse files
committed
Merge branch 'sd/stash-wo-user-name'
A properly configured username/email is required under user.useConfigOnly in order to create commits; now "git stash" (even though it creates commit objects to represent stash entries) command is exempt from the requirement. * sd/stash-wo-user-name: stash: tolerate missing user identity
2 parents 84d1783 + 3bc2111 commit 1328d29

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

git-stash.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,20 @@ untracked_files () {
5555
git ls-files -o $z $excl_opt -- "$@"
5656
}
5757

58+
prepare_fallback_ident () {
59+
if ! git -c user.useconfigonly=yes var GIT_COMMITTER_IDENT >/dev/null 2>&1
60+
then
61+
GIT_AUTHOR_NAME="git stash"
62+
GIT_AUTHOR_EMAIL=git@stash
63+
GIT_COMMITTER_NAME="git stash"
64+
GIT_COMMITTER_EMAIL=git@stash
65+
export GIT_AUTHOR_NAME
66+
export GIT_AUTHOR_EMAIL
67+
export GIT_COMMITTER_NAME
68+
export GIT_COMMITTER_EMAIL
69+
fi
70+
}
71+
5872
clear_stash () {
5973
if test $# != 0
6074
then
@@ -67,6 +81,9 @@ clear_stash () {
6781
}
6882

6983
create_stash () {
84+
85+
prepare_fallback_ident
86+
7087
stash_msg=
7188
untracked=
7289
while test $# != 0

t/t3903-stash.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,4 +1096,32 @@ test_expect_success 'stash -- <subdir> works with binary files' '
10961096
test_path_is_file subdir/untracked
10971097
'
10981098

1099+
test_expect_success 'stash works when user.name and user.email are not set' '
1100+
git reset &&
1101+
>1 &&
1102+
git add 1 &&
1103+
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
1104+
git stash &&
1105+
git show -s --format="%an <%ae>" refs/stash >actual &&
1106+
test_cmp expect actual &&
1107+
>2 &&
1108+
git add 2 &&
1109+
test_config user.useconfigonly true &&
1110+
test_config stash.usebuiltin true &&
1111+
(
1112+
sane_unset GIT_AUTHOR_NAME &&
1113+
sane_unset GIT_AUTHOR_EMAIL &&
1114+
sane_unset GIT_COMMITTER_NAME &&
1115+
sane_unset GIT_COMMITTER_EMAIL &&
1116+
test_unconfig user.email &&
1117+
test_unconfig user.name &&
1118+
test_must_fail git commit -m "should fail" &&
1119+
echo "git stash <git@stash>" >expect &&
1120+
>2 &&
1121+
git stash &&
1122+
git show -s --format="%an <%ae>" refs/stash >actual &&
1123+
test_cmp expect actual
1124+
)
1125+
'
1126+
10991127
test_done

0 commit comments

Comments
 (0)