Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse bad config values #556

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions lib/errors.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** The git errors which can be parsed from failed git commands. */
export enum GitError {
BadConfigValue,
SSHKeyAuditUnverified,
SSHAuthenticationFailed,
SSHPermissionDenied,
Expand Down Expand Up @@ -64,6 +65,8 @@ export enum GitError {

/** A mapping from regexes to the git error they identify. */
export const GitErrorRegexes: { [regexp: string]: GitError } = {
"fatal: bad (?:numeric|boolean) config value '(.+)' for '(.+)'":
GitError.BadConfigValue,
'ERROR: ([\\s\\S]+?)\\n+\\[EPOLICYKEYAGE\\]\\n+fatal: Could not read from remote repository.':
GitError.SSHKeyAuditUnverified,
"fatal: Authentication failed for 'https://":
Expand Down
57 changes: 57 additions & 0 deletions test/fast/errors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,61 @@ describe('detects errors', () => {
// toContain because of realpath and we don't care about /private/ on macOS
expect(m![1]).toContain(repoName)
})
describe('BadConfigValue', () => {
it('detects bad boolean config value', async () => {
const repoPath = await initialize('bad-config-repo')

const filePath = 'text.md'
writeFileSync(join(repoPath, filePath), 'some text')
await GitProcess.exec(['add', filePath], repoPath)

await GitProcess.exec(['config', 'core.autocrlf', 'nab'], repoPath)

const result = await GitProcess.exec(
['commit', '-m', 'add a text file'],
repoPath
)

expect(result).toHaveGitError(GitError.BadConfigValue)

const errorEntry = Object.entries(GitErrorRegexes).find(
([_, v]) => v === GitError.BadConfigValue
)

expect(errorEntry).not.toBe(null)
const m = result.stderr.match(errorEntry![0])

expect(m![1]).toBe('nab')
expect(m![2]).toBe('core.autocrlf')
})
it('detects bad numeric config value', async () => {
const repoPath = await initialize('bad-config-repo')

const filePath = 'text.md'
writeFileSync(join(repoPath, filePath), 'some text')
await GitProcess.exec(['add', filePath], repoPath)

await GitProcess.exec(
['config', 'core.repositoryformatversion', 'nan'],
repoPath
)

const result = await GitProcess.exec(
['commit', '-m', 'add a text file'],
repoPath
)

expect(result).toHaveGitError(GitError.BadConfigValue)

const errorEntry = Object.entries(GitErrorRegexes).find(
([_, v]) => v === GitError.BadConfigValue
)

expect(errorEntry).not.toBe(null)
const m = result.stderr.match(errorEntry![0])

expect(m![1]).toBe('nan')
expect(m![2]).toBe('core.repositoryformatversion')
})
})
})
Loading