From 1f678697ec0a4cc606671277d52b31e7cfde414c Mon Sep 17 00:00:00 2001 From: Git-Lior Date: Fri, 7 Sep 2018 12:10:58 +0300 Subject: [PATCH 1/3] Fix #57222 - improve no user.email/user.name config error message --- extensions/git/src/commands.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index e4b5320a561..0fcca88678f 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1714,6 +1714,12 @@ export class CommandCenter { type = 'warning'; options.modal = false; break; + case GitErrorCodes.NoUserNameConfigured: + case GitErrorCodes.NoUserEmailConfigured: + message = localize('missing user info', "Make sure that user.email and user.name are configured correctly.\n\n{0}\n{1}", + "git config --global user.email \"you@example.com\"", + "git config --global user.name \"Your Name\""); + break; default: const hint = (err.stderr || err.message || String(err)) .replace(/^error: /mi, '') From 63748f8088691438b3d9ce1c5440826fda029d3f Mon Sep 17 00:00:00 2001 From: Git-Lior Date: Fri, 7 Sep 2018 14:40:23 +0300 Subject: [PATCH 2/3] no user.email/user.name error message now shows current values --- extensions/git/src/commands.ts | 4 +++- extensions/git/src/git.ts | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 0fcca88678f..3d479c6e27e 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1716,7 +1716,9 @@ export class CommandCenter { break; case GitErrorCodes.NoUserNameConfigured: case GitErrorCodes.NoUserEmailConfigured: - message = localize('missing user info', "Make sure that user.email and user.name are configured correctly.\n\n{0}\n{1}", + message = localize('missing user info', "Make sure that user.email and user.name are configured correctly.\n\n{0}\n{1}\n\n{2}\n{3}", + "current user.name: " + err.userName || "", + "current user.email: " + err.userEmail || "", "git config --global user.email \"you@example.com\"", "git config --global user.name \"Your Name\""); break; diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index 3069b8fd77b..848b48e381d 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -978,20 +978,26 @@ export class Repository { throw commitErr; } - try { - await this.run(['config', '--get-all', 'user.name']); - } catch (err) { - err.gitErrorCode = GitErrorCodes.NoUserNameConfigured; - throw err; - } + let userName, userEmail; try { - await this.run(['config', '--get-all', 'user.email']); - } catch (err) { - err.gitErrorCode = GitErrorCodes.NoUserEmailConfigured; - throw err; + const nameResult = await this.run(['config', '--get-all', 'user.name']); + userName = nameResult.stdout.split('\n').filter(l => !!l).pop(); + } catch (err) { } + + try { + const emailResult = await this.run(['config', '--get-all', 'user.email']); + userEmail = emailResult.stdout.split('\n').filter(l => !!l).pop(); + } catch (err) { } + + if (userName && userEmail) { + throw commitErr; } + commitErr.gitErrorCode = !userName ? GitErrorCodes.NoUserNameConfigured : GitErrorCodes.NoUserEmailConfigured; + commitErr.userName = userName; + commitErr.userEmail = userEmail; + throw commitErr; } From 8d147f35b7e376a39258c2168489d5aca6561f0e Mon Sep 17 00:00:00 2001 From: Git-Lior Date: Sat, 8 Sep 2018 22:57:10 +0300 Subject: [PATCH 3/3] fixed no user.email/user.name error message order --- extensions/git/src/commands.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 3d479c6e27e..0eea2602482 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1717,8 +1717,8 @@ export class CommandCenter { case GitErrorCodes.NoUserNameConfigured: case GitErrorCodes.NoUserEmailConfigured: message = localize('missing user info', "Make sure that user.email and user.name are configured correctly.\n\n{0}\n{1}\n\n{2}\n{3}", - "current user.name: " + err.userName || "", "current user.email: " + err.userEmail || "", + "current user.name: " + err.userName || "", "git config --global user.email \"you@example.com\"", "git config --global user.name \"Your Name\""); break;