Skip to content

Commit

Permalink
Handle attempting to sign-off without configs
Browse files Browse the repository at this point in the history
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 <vincent.fugnitto@ericsson.com>
  • Loading branch information
vince-fugnitto committed Sep 23, 2019
1 parent 2aa8f23 commit f949db1
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions packages/git/src/browser/git-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit f949db1

Please sign in to comment.