Skip to content
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
5 changes: 5 additions & 0 deletions python/commit_check_forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ def _git(repo: _Repository, args: list[str]) -> tuple[int, str, str]:
if args[:1] == ["config"]:
# No git config: identities come from the commits themselves.
return 1, "", ""
if args in (["var", "GIT_AUTHOR_IDENT"], ["var", "GIT_COMMITTER_IDENT"]):
# Who a commit not made yet would be by: here, a squash merge whose
# author is whoever presses Merge, which Bitbucket does not tell
# merge checks. Answer as git does with no identity configured.
return 128, "", "fatal: unable to auto-detect email address\n"
if args[:3] == ["log", "-n", "1"] and len(args) == 5 and args[3].startswith("--pretty=format:"):
sha = repo.resolve(args[4])
if sha is None:
Expand Down
19 changes: 19 additions & 0 deletions src/__tests__/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,25 @@ describe('the CLI in Pyodide', () => {
expect(JSON.parse(res.stdout).checks.map((c) => [c.rule_id, c.status])).toEqual([['CC013', 'fail']])
})

test('a squash message is checked without an author, as git with no identity would', async () => {
// Bitbucket does not tell a merge check who presses Merge, so the
// squash commit's author is unknown when the CLI asks git var.
const res = await cli.runCli({
argv: ['.commit-check-message', '-m', '-n', '-e', '-b', '--format', 'json', '--no-banner'],
files: [
{ path: 'cchk.toml', text: '[commit]\nai_attribution = "forbid"\n' },
{ path: '.commit-check-message', text: 'bad message' }
],
commits: [{ sha: sha(1), message: 'feat: x\n', parents: [], author }],
head: sha(1),
branch: 'feature/x'
})
expect(res.unsupported).toEqual([])
const status = Object.fromEntries(JSON.parse(res.stdout).checks.map((c) => [c.rule_id, c.status]))
expect(status.CC001).toBe('fail')
expect(status.CC017).not.toBe('fail')
})

test('a git command it does not know fails as git would, and is listed', async () => {
const res = await cli.runCli({ argv: ['-t', '--format', 'json', '--no-banner'], files: [], commits: [], head: null, branch: '' })
expect(res.unsupported).toEqual(['git tag --points-at HEAD'])
Expand Down