Skip to content

Commit

Permalink
Merge pull request #184 from emulsify-ds/exit-on-error-when-repositor…
Browse files Browse the repository at this point in the history
…y-url-is-invalid

fix: gives user a specific error message when the repository URL does not end in .git
  • Loading branch information
mikeethedude authored Dec 16, 2022
2 parents 13f02d6 + 6f5514b commit 8f95c2b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
22 changes: 15 additions & 7 deletions src/handlers/systemInstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,21 @@ export async function getSystemRepoInfo(
): Promise<(GitCloneOptions & { name: string }) | void> {
// If a repository and checkout were specified, use that to return system information.
if (repository && checkout) {
const repoName = getGitRepoNameFromUrl(repository);
if (repoName) {
return {
name: repoName,
repository,
checkout,
};
try {
const repoName = getGitRepoNameFromUrl(repository);
if (repoName) {
return {
name: repoName,
repository,
checkout,
};
}
} catch (error: unknown) {
if (error instanceof Error) {
return log('error', error.message, EXIT_ERROR);
} else {
throw error;
}
}
}

Expand Down
12 changes: 7 additions & 5 deletions src/util/getGitRepoNameFromUrl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ describe('getGitRepoNameFromUrl', () => {
).toBe('emulsify-drupal');
});

it('can return void if given an invalid git url', () => {
it('can throw an Error if given an invalid git url', () => {
expect.assertions(2);
expect(getGitRepoNameFromUrl('')).toBe(undefined);
expect(
getGitRepoNameFromUrl('https://github.com/emulsify-ds/emulsify-drupal')
).toBe(undefined);
expect(() => {
getGitRepoNameFromUrl('');
}).toThrow(Error);
expect(() => {
getGitRepoNameFromUrl('https://github.com/emulsify-ds/emulsify-drupal');
}).toThrow(Error);
});
});
2 changes: 1 addition & 1 deletion src/util/getGitRepoNameFromUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function getGitRepoNameFromUrl(url: string): string | void {

// If no .git extension is provided, then this is an invalid git url.
if (!gitName.includes('.git')) {
return undefined;
throw new Error('The repository URL must end in .git.');
}
return R.head(gitName.split('.'));
}

0 comments on commit 8f95c2b

Please sign in to comment.