Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 24 additions & 3 deletions src/up.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,32 @@ export default class UpCommand extends AbstractServerCommand {
});

const ref = await GitUtils.getBranch(this.directory);
this._gitUrl = await GitUtils.getOriginURL(this.directory, { ref });
let gitUrlError;
try {
this._gitUrl = await GitUtils.getOriginURL(this.directory, { ref });
} catch (e) {
gitUrlError = e;
}

if (!this._gitUrl) {
throw Error('No git remote found. Make sure you have a remote "origin" configured.');
if (gitUrlError) {
if (this._originalUrl && !this._originalUrl.includes('{{')) {
this.log.warn(chalk`Could not parse git remote origin URL: {yellow ${gitUrlError.message}}`);
this.log.warn(chalk`Continuing with the provided {cyan --url} value.`);
this._url = this._originalUrl;
} else {
this.log.error(chalk`Could not parse git remote origin URL: {yellow ${gitUrlError.message}}`);
this.log.error('The git remote origin uses an SSH URL format that cannot be automatically resolved.');
this.log.error(chalk`Please specify the content origin URL using the {cyan --url} option:`);
this.log.error(chalk` {cyan aem up --url https://main--<repo>--<owner>.aem.page}`);
throw Error('Invalid git remote origin URL. Use --url to specify the content origin.');
}
} else {
throw Error('No git remote found. Make sure you have a remote "origin" configured.');
}
} else {
await this.initUrl(this._gitUrl, ref);
}
await this.initUrl(this._gitUrl, ref);
this._project.withProxyUrl(this._url);
const { site, org } = this.extractSiteAndOrg(this._url);
if (site && org) {
Expand Down
49 changes: 49 additions & 0 deletions test/up-cmd.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -855,4 +855,53 @@ describe('Integration test for up command with cache', function suite() {
// eslint-disable-next-line no-underscore-dangle
assert.strictEqual(cmd._url, 'https://custom.domain.com', 'User-provided --pagesUrl should be preserved during git reconfiguration');
});

it('shows helpful error when git remote origin uses non-parseable SSH format', async () => {
initGit(testDir, 'user@example.ghe.com:ACMEGROUP/acme-eds.git');
const cmd = new UpCommand()
.withLiveReload(false)
.withDirectory(testDir);

try {
await cmd.init();
assert.fail('Should have thrown an error for non-parseable SSH origin');
} catch (e) {
assert(
e.message.includes('Invalid git remote origin URL'),
`Expected SSH URL error, got: ${e.message}`,
);
}
});

it('starts successfully when non-parseable SSH origin is paired with --url', async () => {
initGit(testDir, 'user@example.ghe.com:ACMEGROUP/acme-eds.git');
const cmd = new UpCommand()
.withLiveReload(false)
.withDirectory(testDir)
.withHttpPort(0)
.withUrl('https://main--acme-eds--acmegroup.aem.page');

await new Promise((resolve, reject) => {
let error = null;
cmd
.on('started', async () => {
try {
// eslint-disable-next-line no-underscore-dangle
assert.strictEqual(cmd._url, 'https://main--acme-eds--acmegroup.aem.page');
} catch (e) {
error = e;
}
await cmd.stop();
})
.on('stopped', () => {
if (error) {
reject(error);
} else {
resolve();
}
})
.run()
.catch(reject);
});
});
});
Loading