From c58d4950d2c8cc8eddd21c2656c9e5a36b90bb09 Mon Sep 17 00:00:00 2001 From: vince-fugnitto Date: Thu, 19 Sep 2019 15:24:29 -0400 Subject: [PATCH] Handle attempting to sign-off without configs Fixes #4908 Handle the toolbar action to add a sign-off when the user does not have their `user.name` and `user.email` configured. Signed-off-by: vince-fugnitto --- packages/git/src/browser/git-contribution.ts | 32 ++++++++++++-------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/packages/git/src/browser/git-contribution.ts b/packages/git/src/browser/git-contribution.ts index cfc4cb6d676da..8e809ad80f0c6 100644 --- a/packages/git/src/browser/git-contribution.ts +++ b/packages/git/src/browser/git-contribution.ts @@ -704,20 +704,28 @@ export class GitContribution implements CommandContribution, MenuContribution, T if (!scmRepository) { return; } - const repository = scmRepository.provider.repository; - const [username, email] = (await Promise.all([ - this.git.exec(repository, ['config', 'user.name']), - this.git.exec(repository, ['config', 'user.email']) - ])).map(result => result.stdout.trim()); + try { + const repository = scmRepository.provider.repository; + const [username, email] = (await Promise.all([ + this.git.exec(repository, ['config', 'user.name']), + this.git.exec(repository, ['config', 'user.email']) + ])).map(result => result.stdout.trim()); - const signOff = `\n\nSigned-off-by: ${username} <${email}>`; - const value = scmRepository.input.value; - if (value.endsWith(signOff)) { - scmRepository.input.value = value.substr(0, value.length - signOff.length); - } else { - scmRepository.input.value = `${value}${signOff}`; + const signOff = `\n\nSigned-off-by: ${username} <${email}>`; + const value = scmRepository.input.value; + if (value.endsWith(signOff)) { + scmRepository.input.value = value.substr(0, value.length - signOff.length); + } else { + scmRepository.input.value = `${value}${signOff}`; + } + scmRepository.input.focus(); + } catch (e) { + scmRepository.input.issue = { + type: 'warning', + message: 'Make sure you configure your \'user.name\' and \'user.email\' in git.' + }; } - scmRepository.input.focus(); + } } export interface GitOpenFileOptions {