1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-18 10:06:10 +02:00

stash: tolerate missing user identity

The "git stash" command insists on having a usable user identity to
the same degree as the "git commit-tree" and "git commit" commands
do, because it uses the same codepath that creates commit objects
as these commands.

It is not strictly necesary to do so. Check if we will barf before
creating commit objects and then supply fake identity to please the
machinery that creates commits.
Add test to document that stash executes correctly both with and
without valid ident.

This is not that much of usability improvement, as the users who run
"git stash" would eventually want to record their changes that are
temporarily stored in the stashes in a more permanent history by
committing, and they must do "git config user.{name,email}" at that
point anyway, so arguably this change is only delaying a step that
is necessary to work in the repository.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Slavica Djukic <slawica92@hotmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Slavica Djukic 2018-11-18 14:44:07 +01:00 committed by Junio C Hamano
parent d166e6afe5
commit 3bc2111fc2
2 changed files with 45 additions and 0 deletions

View File

@ -55,6 +55,20 @@ untracked_files () {
git ls-files -o $z $excl_opt -- "$@"
}
prepare_fallback_ident () {
if ! git -c user.useconfigonly=yes var GIT_COMMITTER_IDENT >/dev/null 2>&1
then
GIT_AUTHOR_NAME="git stash"
GIT_AUTHOR_EMAIL=git@stash
GIT_COMMITTER_NAME="git stash"
GIT_COMMITTER_EMAIL=git@stash
export GIT_AUTHOR_NAME
export GIT_AUTHOR_EMAIL
export GIT_COMMITTER_NAME
export GIT_COMMITTER_EMAIL
fi
}
clear_stash () {
if test $# != 0
then
@ -67,6 +81,9 @@ clear_stash () {
}
create_stash () {
prepare_fallback_ident
stash_msg=
untracked=
while test $# != 0

View File

@ -1096,4 +1096,32 @@ test_expect_success 'stash -- <subdir> works with binary files' '
test_path_is_file subdir/untracked
'
test_expect_success 'stash works when user.name and user.email are not set' '
git reset &&
>1 &&
git add 1 &&
echo "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>" >expect &&
git stash &&
git show -s --format="%an <%ae>" refs/stash >actual &&
test_cmp expect actual &&
>2 &&
git add 2 &&
test_config user.useconfigonly true &&
test_config stash.usebuiltin true &&
(
sane_unset GIT_AUTHOR_NAME &&
sane_unset GIT_AUTHOR_EMAIL &&
sane_unset GIT_COMMITTER_NAME &&
sane_unset GIT_COMMITTER_EMAIL &&
test_unconfig user.email &&
test_unconfig user.name &&
test_must_fail git commit -m "should fail" &&
echo "git stash <git@stash>" >expect &&
>2 &&
git stash &&
git show -s --format="%an <%ae>" refs/stash >actual &&
test_cmp expect actual
)
'
test_done