All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Cc: Johannes.Schindelin@gmx.de, slawica92@hotmail.com,
	Slavica Djukic <slavicadj.ip2018@gmail.com>
Subject: [PATCH 2+3/3] stash: tolerate missing user identity
Date: Fri, 02 Nov 2018 13:59:30 +0900	[thread overview]
Message-ID: <xmqq8t2cqdl9.fsf_-_@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20181101115834.19044-1-slawica92@hotmail.com> (Slavica Djukic's message of "Thu, 1 Nov 2018 12:58:34 +0100")

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.

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.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * This time with a proposed commit log message and a flip to the
   test; this would be able to replce 2/3 and 3/3 without waiting
   for ps/stash-in-c to stabilize and become ready to be based on
   further work like this one.

   We need to extend the test so that when a reasonable identity is
   present, the stashes are created under that identity and not with
   the fallback one, which I do not think is tested with the previous
   step, so there still is a bit of room to improve [PATCH 1/3]

 git-stash.sh     | 17 +++++++++++++++++
 t/t3903-stash.sh |  2 +-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/git-stash.sh b/git-stash.sh
index 94793c1a91..789ce2f41d 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -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
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index a9a573efa0..3dcf2f14d1 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1096,7 +1096,7 @@ test_expect_success 'stash -- <subdir> works with binary files' '
 	test_path_is_file subdir/untracked
 '
 
-test_expect_failure 'stash works when user.name and user.email are not set' '
+test_expect_success 'stash works when user.name and user.email are not set' '
 	git reset &&
 	>1 &&
 	git add 1 &&
-- 
2.19.1-801-gd582ea202b


  parent reply	other threads:[~2018-11-02  4:59 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-23 16:29 [PATCH 1/3] [Outreachy] t3903-stash: test without configured user name Slavica
2018-10-23 18:52 ` Christian Couder
2018-10-24 13:56   ` Slavica
2018-10-25  4:44     ` Junio C Hamano
2018-10-23 19:19 ` Eric Sunshine
2018-10-24  2:48 ` Junio C Hamano
2018-10-24  7:39   ` Johannes Schindelin
2018-10-24  9:58     ` Junio C Hamano
2018-10-24 15:18       ` Johannes Schindelin
2018-10-25  4:17         ` Junio C Hamano
2018-10-24 20:01 ` [PATCH v2 " Slavica Djukic
2018-10-24 20:05   ` Slavica Djukic
2018-10-24 20:25     ` Eric Sunshine
2018-10-25  4:48       ` Junio C Hamano
2018-10-25 19:13   ` [PATCH v3 " Slavica Djukic
2018-10-25 19:20     ` Slavica Djukic
2018-10-26  1:13       ` Junio C Hamano
2018-10-30 13:04         ` Slavica Djukic
2018-11-01 11:55       ` [PATCH 0/3] [Outreachy] make stash work if user.name and user.email are not configured Slavica Djukic
2018-11-01 11:58         ` [PATCH 1/3][Outreachy] t3903-stash: test without configured user.name and user.email Slavica Djukic
2018-11-01 14:53           ` Christian Couder
2018-11-02  4:59           ` Junio C Hamano [this message]
2018-11-01 12:00         ` [PATCH 2/3] [Outreachy] ident: introduce set_fallback_ident() function Slavica Djukic
2018-11-02  3:01           ` Junio C Hamano
2018-11-02  4:41             ` Junio C Hamano
2018-11-02  5:22               ` Junio C Hamano
2018-11-01 12:02         ` [PATCH 3/3] [Outreachy] stash: use " Slavica Djukic
2018-11-14 22:12         ` [PATCH v2 0/2] [Outreachy] make stash work if user.name and user.email are not configured Slavica Djukic
2018-11-14 22:25           ` [PATCH v2 1/2] [Outreachy] t3903-stash: test without configured user.name and user.email Slavica Djukic
2018-11-15 12:37             ` Johannes Schindelin
2018-11-16  5:55             ` Junio C Hamano
2018-11-16  6:26               ` Junio C Hamano
2018-11-16  6:32               ` Junio C Hamano
2018-11-16  8:28               ` Slavica Djukic
2018-11-16 10:12                 ` Junio C Hamano
2018-11-17 18:47                   ` Slavica Djukic
2018-11-18  6:28                     ` Junio C Hamano
2018-11-14 22:28           ` [PATCH v2 2/2] [Outreachy] stash: tolerate missing user identity Slavica Djukic
2018-11-16  5:35             ` Junio C Hamano
2018-11-18 13:29           ` [PATCH 0/1 v3] make stash work if user.name and user.email are not configured Slavica Djukic
2018-11-18 13:44             ` [PATCH 1/1 v3] stash: tolerate missing user identity Slavica Djukic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8t2cqdl9.fsf_-_@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=slavicadj.ip2018@gmail.com \
    --cc=slawica92@hotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.