diff --git a/extensions/git/src/commands.ts b/extensions/git/src/commands.ts index 88b3d4cd2844acc7535074f8f2e91222bdd964e3..8c5534a2b9152ad009d3b5c5aa7c93f983647514 100644 --- a/extensions/git/src/commands.ts +++ b/extensions/git/src/commands.ts @@ -1860,6 +1860,14 @@ 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}\n\n{2}\n{3}", + "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; default: const hint = (err.stderr || err.message || String(err)) .replace(/^error: /mi, '') diff --git a/extensions/git/src/git.ts b/extensions/git/src/git.ts index f66646bb2c55ad6ed3facd136530c4875023ed09..df93ffcc2b4baa6fc5596a146589ad058ec87b78 100644 --- a/extensions/git/src/git.ts +++ b/extensions/git/src/git.ts @@ -998,20 +998,26 @@ export class Repository { throw commitErr; } + let userName, userEmail; + try { - await this.run(['config', '--get-all', 'user.name']); - } catch (err) { - err.gitErrorCode = GitErrorCodes.NoUserNameConfigured; - throw err; - } + const nameResult = await this.run(['config', '--get-all', 'user.name']); + userName = nameResult.stdout.split('\n').filter(l => !!l).pop(); + } catch (err) { } try { - await this.run(['config', '--get-all', 'user.email']); - } catch (err) { - err.gitErrorCode = GitErrorCodes.NoUserEmailConfigured; - throw err; + 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; }