Skip to content

Commit 5061ec1

Browse files
tgummererdscho
authored andcommitted
ident: don't require calling prepare_fallback_ident first
In fd5a584 ("ident: add the ability to provide a "fallback identity"", 2019-02-25) I made it a requirement to call prepare_fallback_ident as the first function in the ident API. However in stash we didn't actually end up following that. This leads to a BUG if user.email and user.name are set. It was not caught in the test suite because we only rely on environment variables for setting the user name and email instead of the config. Instead of making it a bug to call other functions in the ident API first, just return silently if the identity of a user was already set up. Reported-by: Denton Liu <[email protected]> Helped-by: Jeff King <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d3dc2ab commit 5061ec1

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

cache.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,6 @@ extern int is_terminal_dumb(void);
15201520
extern int git_ident_config(const char *, const char *, void *);
15211521
/*
15221522
* Prepare an ident to fall back on if the user didn't configure it.
1523-
* Must be called before any other function from the ident API.
15241523
*/
15251524
void prepare_fallback_ident(const char *name, const char *email);
15261525
extern void reset_ident_date(void);

ident.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,7 @@ int git_ident_config(const char *var, const char *value, void *data)
507507

508508
static void set_env_if(const char *key, const char *value, int *given, int bit)
509509
{
510-
if (*given & bit)
511-
BUG("%s was checked before prepare_fallback got called", key);
512-
if (getenv(key))
510+
if ((*given & bit) || getenv(key))
513511
return; /* nothing to do */
514512
setenv(key, value, 0);
515513
*given |= bit;

t/t3903-stash.sh

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

1099+
test_expect_success 'stash with user.name and user.email set works' '
1100+
test_config user.name "A U Thor" &&
1101+
test_config user.email "a.u@thor" &&
1102+
git stash
1103+
'
1104+
10991105
test_expect_success 'stash works when user.name and user.email are not set' '
11001106
git reset &&
11011107
>1 &&

0 commit comments

Comments
 (0)