Skip to content

Commit

Permalink
Merge pull request #556 from desktop/parse-bad-config-values
Browse files Browse the repository at this point in the history
Parse bad config values
  • Loading branch information
sergiou87 committed Mar 8, 2024
2 parents 0f5a4f1 + 224cd7c commit c362367
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/errors.ts
@@ -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
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')
})
})
})

0 comments on commit c362367

Please sign in to comment.