Skip to content

Commit

Permalink
fix(git-url): trimmed whitespace from the end of the remote result fr…
Browse files Browse the repository at this point in the history
…om simple-git

since it looks like auto-trimming is only available from the raw command

fixes #1166
  • Loading branch information
travi committed Feb 3, 2024
1 parent b11dd15 commit 965f3b7
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as td from 'testdouble';
// remark-usage-ignore-next 4
const {simpleGit} = await td.replaceEsm('simple-git');
const simpleGitInstance = td.object(['remote']);
td.when(simpleGit(process.cwd())).thenReturn(simpleGitInstance);
td.when(simpleGit({baseDir: process.cwd()})).thenReturn(simpleGitInstance);
td.when(simpleGitInstance.remote(['get-url', 'origin'])).thenResolve('git@github.com:form8ion/lift.git');

const {lift, questionNames} = await import('./lib/index.js');
Expand Down
4 changes: 2 additions & 2 deletions src/vcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {simpleGit} from 'simple-git';
import parseGitUrl from 'git-url-parse';

export async function determineExistingHostDetails({projectRoot}) {
const git = simpleGit(projectRoot);
const git = simpleGit({baseDir: projectRoot});
const remoteOrigin = await git.remote(['get-url', 'origin']);
const {owner, name, host} = parseGitUrl(remoteOrigin);
const {owner, name, host} = parseGitUrl(remoteOrigin.trimEnd());

return {owner, name, host};
}
4 changes: 2 additions & 2 deletions src/vcs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ describe('vcs', () => {
const remoteUrl = any.url();
const projectRoot = any.string();
const remote = vi.fn();
when(simpleGit.simpleGit).calledWith(projectRoot).mockReturnValue({remote});
when(remote).calledWith(['get-url', 'origin']).mockResolvedValue(remoteUrl);
when(simpleGit.simpleGit).calledWith({baseDir: projectRoot}).mockReturnValue({remote});
when(remote).calledWith(['get-url', 'origin']).mockResolvedValue(`${remoteUrl}\n`);
when(GitUrlParse).calledWith(remoteUrl).mockReturnValue({owner, name, host});

expect(await determineExistingHostDetails({projectRoot})).toEqual({owner, name, host});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let lift, questionNames;
Before(async function () {
const {simpleGit} = await td.replaceEsm('simple-git');
this.simpleGitInstance = td.object(['remote']);
td.when(simpleGit(process.cwd())).thenReturn(this.simpleGitInstance);
td.when(simpleGit({baseDir: process.cwd()})).thenReturn(this.simpleGitInstance);

// eslint-disable-next-line import/no-extraneous-dependencies,import/no-unresolved
({lift, questionNames} = await import('@form8ion/lift'));
Expand Down
2 changes: 1 addition & 1 deletion test/integration/features/step_definitions/vcs-steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Given('the repository hosted on {string}', async function (vcsHost) {

td
.when(this.simpleGitInstance.remote(['get-url', 'origin']))
.thenResolve(`git@${vcsHost}:${this.gitHostAccount}/${this.repositoryName}.git`);
.thenResolve(`git@${vcsHost}:${this.gitHostAccount}/${this.repositoryName}.git\n`);
});

Then('vcs details are provided to the enhancers', async function () {
Expand Down

0 comments on commit 965f3b7

Please sign in to comment.