cli: fall back --since diff to use ref if merge base lookup fails

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-03-05 17:23:11 +01:00
parent de1e46c9b6
commit dc6002a7b9
2 changed files with 14 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
The `--since` flag of repo commands now silently falls back to using the provided `ref` directly if no merge base is available.
+9 -2
View File
@@ -50,9 +50,16 @@ export async function listChangedFiles(ref: string) {
if (!ref) {
throw new Error('ref is required');
}
const [base] = await runGit('merge-base', 'HEAD', ref);
const tracked = await runGit('diff', '--name-only', base);
let diffRef = ref;
try {
const [base] = await runGit('merge-base', 'HEAD', ref);
diffRef = base;
} catch {
// silently fall back to using the ref directly if merge base is not available
}
const tracked = await runGit('diff', '--name-only', diffRef);
const untracked = await runGit('ls-files', '--others', '--exclude-standard');
return Array.from(new Set([...tracked, ...untracked]));