Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/utils/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
git: SimpleGit,
remoteName: string,
): Promise<string> {
// Verify the remote exists before attempting to contact it, so we can
// surface a clear error instead of a raw git exit-code-128 failure.
const remotes = await git.getRemotes(false);
if (!remotes.some(r => r.name === remoteName)) {
throw new ConfigurationError(
`Remote '${remoteName}' is not configured in this repository. ` +
`Ensure the repository has a remote named '${remoteName}' before running craft.`,
);
}

// This part is courtesy of https://stackoverflow.com/a/62397081/90297
return stripRemoteName(
await git
Expand Down Expand Up @@ -228,7 +238,7 @@

try {
await git.fetch();
} catch (_err) {

Check warning on line 241 in src/utils/git.ts

View workflow job for this annotation

GitHub Actions / Lint fixes

[@typescript-eslint/no-unused-vars] '_err' is defined but never used.
logger.debug('Failed to fetch from remote, using locally cached refs');
}

Expand All @@ -236,7 +246,7 @@
try {
const output = await git.raw('branch', '-r');
allBranches = parseGitBranchOutput(output);
} catch (_err) {

Check warning on line 249 in src/utils/git.ts

View workflow job for this annotation

GitHub Actions / Lint fixes

[@typescript-eslint/no-unused-vars] '_err' is defined but never used.
logger.debug('Failed to list remote branches');
return { exactMatches: [], fuzzyMatches: [] };
}
Expand Down
Loading