Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ export class Repository {
try {
await this.exec(args, options);
} catch (commitErr) {
await this.handleCommitError(commitErr);
await this.handleCommitError(commitErr, opts.requireUserConfig ?? true);
}
}

Expand All @@ -2145,7 +2145,7 @@ export class Repository {
}


private async handleCommitError(commitErr: unknown): Promise<void> {
private async handleCommitError(commitErr: unknown, requireUserConfig = true): Promise<void> {
if (commitErr instanceof GitError && /not possible because you have unmerged files/.test(commitErr.stderr || '')) {
commitErr.gitErrorCode = GitErrorCodes.UnmergedChanges;
throw commitErr;
Expand All @@ -2154,18 +2154,20 @@ export class Repository {
throw commitErr;
}

try {
await this.exec(['config', '--get-all', 'user.name']);
} catch (err) {
err.gitErrorCode = GitErrorCodes.NoUserNameConfigured;
throw err;
}
if (requireUserConfig) {
try {
await this.exec(['config', '--get-all', 'user.name']);
} catch (err) {
err.gitErrorCode = GitErrorCodes.NoUserNameConfigured;
throw err;
}

try {
await this.exec(['config', '--get-all', 'user.email']);
} catch (err) {
err.gitErrorCode = GitErrorCodes.NoUserEmailConfigured;
throw err;
try {
await this.exec(['config', '--get-all', 'user.email']);
} catch (err) {
err.gitErrorCode = GitErrorCodes.NoUserEmailConfigured;
throw err;
}
}

throw commitErr;
Expand Down