File tree Expand file tree Collapse file tree 1 file changed +45
-3
lines changed
Expand file tree Collapse file tree 1 file changed +45
-3
lines changed Original file line number Diff line number Diff line change 11const { execSync } = require ( 'child_process' ) ;
22
3+ const isShallowClone = ( ) => {
4+ try {
5+ return execSync ( 'git rev-parse --is-shallow-repository' , {
6+ encoding : 'utf8'
7+ } ) . trim ( ) === 'true' ;
8+ } catch ( e ) {
9+ return false ;
10+ }
11+ } ;
12+
13+ const tryUnshallow = ( ) => {
14+ if ( ! isShallowClone ( ) ) return true ;
15+
16+ console . log ( '📦 Shallow clone detected, fetching full history...' ) ;
17+ try {
18+ execSync ( 'git fetch --unshallow origin' , { stdio : 'inherit' } ) ;
19+ execSync ( 'git fetch origin main:main' , { stdio : 'inherit' } ) ;
20+ console . log ( '✅ Successfully fetched full history' ) ;
21+ return true ;
22+ } catch ( e ) {
23+ console . warn ( '⚠️ Could not fetch full history' ) ;
24+ return false ;
25+ }
26+ } ;
27+
28+ const canUseChangedSince = ( ) => {
29+ try {
30+ execSync ( 'git merge-base HEAD main' , { stdio : 'ignore' } ) ;
31+ return true ;
32+ } catch ( e ) {
33+ return false ;
34+ }
35+ } ;
36+
37+ // Main logic: try to use --changedSince, fall back to all tests if needed
338// https://jestjs.io/docs/cli#--changedsince
4- execSync ( `yarn test-unit --changedSince main` , {
5- stdio : 'inherit' ,
6- } ) ;
39+ if ( tryUnshallow ( ) || canUseChangedSince ( ) ) {
40+ execSync ( `yarn test-unit --changedSince main` , {
41+ stdio : 'inherit' ,
42+ } ) ;
43+ } else {
44+ console . warn ( '⚠️ Running all tests (cannot determine changed files)' ) ;
45+ execSync ( `yarn test-unit` , {
46+ stdio : 'inherit' ,
47+ } ) ;
48+ }
You can’t perform that action at this time.
0 commit comments