fix: improve error handling in getCommitsSinceLastTag

- Add nested try-catch to handle git log failures
- Return empty array if all git attempts fail
- Add warning message when commit history cannot be retrieved
This commit is contained in:
2026-03-31 23:22:38 -07:00
parent 89d0d08162
commit fe133eab99
+10 -2
View File
@@ -48,14 +48,22 @@ function getCommitsSinceLastTag() {
if (!latestTag) { if (!latestTag) {
// No tags yet, get all commits // No tags yet, get all commits
return execSync('git log --oneline --format=%s', { encoding: 'utf8' }).trim().split('\n'); const commits = execSync('git log --oneline --format=%s', { encoding: 'utf8' }).trim();
return commits ? commits.split('\n') : [];
} }
const commits = execSync(`git log ${latestTag}..HEAD --oneline --format=%s`, { encoding: 'utf8' }).trim(); const commits = execSync(`git log ${latestTag}..HEAD --oneline --format=%s`, { encoding: 'utf8' }).trim();
return commits ? commits.split('\n') : []; return commits ? commits.split('\n') : [];
} catch (error) { } catch (error) {
// If no commits since tag or other error, get recent commits // If no commits since tag or other error, get recent commits
return execSync('git log --oneline --format=%s -n 20', { encoding: 'utf8' }).trim().split('\n'); try {
const commits = execSync('git log --oneline --format=%s -n 20', { encoding: 'utf8' }).trim();
return commits ? commits.split('\n') : [];
} catch (innerError) {
// If all git log attempts fail, return empty array
console.warn('Warning: Could not retrieve commit history, defaulting to patch version');
return [];
}
} }
} }