From 06ffdd61c9bc2e45e682011e09efeb4c658e2036 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 16 Aug 2024 11:41:01 +0200 Subject: [PATCH] fix(only-changed): show nice error message about shallow clones (#32189) Closes https://github.com/microsoft/playwright/issues/32188 --------- Signed-off-by: Simon Knott Co-authored-by: Max Schmitt --- packages/playwright/src/runner/vcs.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/playwright/src/runner/vcs.ts b/packages/playwright/src/runner/vcs.ts index 3e5fcfc4e3..707d820ed5 100644 --- a/packages/playwright/src/runner/vcs.ts +++ b/packages/playwright/src/runner/vcs.ts @@ -27,6 +27,18 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: stri ).split('\n').filter(Boolean); } catch (_error) { const error = _error as childProcess.SpawnSyncReturns; + + const unknownRevision = error.output.some(line => line?.includes('unknown revision')); + if (unknownRevision) { + const isShallowClone = childProcess.execSync('git rev-parse --is-shallow-repository', { encoding: 'utf-8', stdio: 'pipe' }).trim() === 'true'; + if (isShallowClone) { + throw new Error([ + `The repository is a shallow clone and does not have '${baseCommit}' available locally.`, + `Note that GitHub Actions checkout is shallow by default: https://github.com/actions/checkout` + ].join('\n')); + } + } + throw new Error([ `Cannot detect changed files for --only-changed mode:`, `git ${command}`,