Skip to content

Commit

Permalink
Merge pull request #558 from desktop/parse-bad-config-values-info
Browse files Browse the repository at this point in the history
Add function to parse bad config value error info
  • Loading branch information
sergiou87 committed Mar 13, 2024
2 parents ab30fb8 + eb1d295 commit a49238a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
24 changes: 24 additions & 0 deletions lib/git-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,30 @@ export class GitProcess {

return null
}

public static parseBadConfigValueErrorInfo(
stderr: string
): { key: string; value: string } | null {
const errorEntry = Object.entries(GitErrorRegexes).find(
([_, v]) => v === GitError.BadConfigValue
)

if (errorEntry === undefined) {
return null
}

const m = stderr.match(errorEntry[0])

if (m === null) {
return null
}

if (!m[1] || !m[2]) {
return null
}

return { key: m[2], value: m[1] }
}
}

/**
Expand Down
13 changes: 4 additions & 9 deletions test/fast/errors-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ describe('detects errors', () => {

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')
const errorInfo = GitProcess.parseBadConfigValueErrorInfo(result.stderr)
expect(errorInfo).not.toBe(null)
expect(errorInfo!.value).toBe('nab')
expect(errorInfo!.key).toBe('core.autocrlf')
})
it('detects bad numeric config value', async () => {
const repoPath = await initialize('bad-config-repo')
Expand Down

0 comments on commit a49238a

Please sign in to comment.