Skip to content

Commit 4dba38f

Browse files
[clint] Unblock Github Copilot by trying a shallow-clone workaround
1 parent 9cf683e commit 4dba38f

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed
Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,48 @@
11
const { 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+
}

0 commit comments

Comments
 (0)