| 14 | }; |
| 15 | |
| 16 | export async function normalizeGitRef( |
| 17 | ref: string | GitBranch, |
| 18 | git = simpleGit(), |
| 19 | ): Promise<GitBranch> { |
| 20 | if (typeof ref === 'object') { |
| 21 | return ref; |
| 22 | } |
| 23 | try { |
| 24 | const sha = await git.revparse(ref); |
| 25 | return { ref, sha }; |
| 26 | } catch (error) { |
| 27 | if ( |
| 28 | error instanceof GitError && |
| 29 | error.message.includes(`fatal: ambiguous argument '${ref}'`) |
| 30 | ) { |
| 31 | await git.fetch(['origin', ref, '--depth=1']); |
| 32 | const sha = await git.revparse('FETCH_HEAD'); |
| 33 | return { ref, sha }; |
| 34 | } |
| 35 | throw error; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | export async function listChangedFiles( |
| 40 | refs: { |