From 36baa2673f8e899d47884bdc4ff95fb1fd747b86 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 16 Aug 2024 09:53:36 +0200 Subject: [PATCH 1/3] fix(only-changed): show nice error message about shallow clones --- packages/playwright/src/runner/vcs.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/playwright/src/runner/vcs.ts b/packages/playwright/src/runner/vcs.ts index 3e5fcfc4e30cf..6ee321b732791 100644 --- a/packages/playwright/src/runner/vcs.ts +++ b/packages/playwright/src/runner/vcs.ts @@ -27,6 +27,20 @@ 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([ + `Revision '${baseCommit}' is not available in the local repository.`, + `On CI, this is likely caused by a shallow clone.`, + `To fix, clone the full repository history:`, + ' https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches' + ].join('\n')); + } + } + throw new Error([ `Cannot detect changed files for --only-changed mode:`, `git ${command}`, From dd0eddd55691988d80697ffdf5314da814eefb33 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 16 Aug 2024 10:20:19 +0200 Subject: [PATCH 2/3] Update packages/playwright/src/runner/vcs.ts Co-authored-by: Max Schmitt Signed-off-by: Simon Knott --- packages/playwright/src/runner/vcs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/playwright/src/runner/vcs.ts b/packages/playwright/src/runner/vcs.ts index 6ee321b732791..9403e86cde668 100644 --- a/packages/playwright/src/runner/vcs.ts +++ b/packages/playwright/src/runner/vcs.ts @@ -36,7 +36,7 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: stri `Revision '${baseCommit}' is not available in the local repository.`, `On CI, this is likely caused by a shallow clone.`, `To fix, clone the full repository history:`, - ' https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches' + 'e.g. for GitHub Actions: https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches' ].join('\n')); } } From 91b478e47537895b77c7b8b877b28e51802afef5 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Fri, 16 Aug 2024 10:57:10 +0200 Subject: [PATCH 3/3] simplify error message to not point user into wrong direction --- packages/playwright/src/runner/vcs.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/playwright/src/runner/vcs.ts b/packages/playwright/src/runner/vcs.ts index 9403e86cde668..707d820ed5710 100644 --- a/packages/playwright/src/runner/vcs.ts +++ b/packages/playwright/src/runner/vcs.ts @@ -33,10 +33,8 @@ export async function detectChangedTestFiles(baseCommit: string, configDir: stri const isShallowClone = childProcess.execSync('git rev-parse --is-shallow-repository', { encoding: 'utf-8', stdio: 'pipe' }).trim() === 'true'; if (isShallowClone) { throw new Error([ - `Revision '${baseCommit}' is not available in the local repository.`, - `On CI, this is likely caused by a shallow clone.`, - `To fix, clone the full repository history:`, - 'e.g. for GitHub Actions: https://github.com/actions/checkout#fetch-all-history-for-all-tags-and-branches' + `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')); } }