Skip to content

Commit 7af9bbe

Browse files
authored
Merge pull request #188 from yuanliuu/main
Fix gitorigin.port error for http(s)
2 parents bb98406 + 90d61c3 commit 7af9bbe

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

src/git/util/get-tool-url.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export const generateUrlTokens = async (
9393
return;
9494
}
9595

96-
const remoteUrl = stripGitRemoteUrl(await getRemoteUrl(remoteName));
96+
const remoteUrl = await getRemoteUrl(remoteName);
9797
const tool = originUrlToToolUrl(remoteUrl);
9898
const filePath = await getRelativePathOfActiveFile();
9999
const defaultBranch = await getDefaultBranch(remoteName);
@@ -103,7 +103,7 @@ export const generateUrlTokens = async (
103103
"tool.protocol": tool?.protocol ?? "https:",
104104
"tool.commitpath": `/commit${isToolUrlPlural(remoteUrl) ? "s" : ""}/`,
105105
"project.name": projectNameFromOrigin(origin),
106-
"project.remote": remoteUrl,
106+
"project.remote": stripGitRemoteUrl(remoteUrl),
107107
"project.defaultbranch": defaultBranch,
108108
"gitorigin.hostname": tool ? gitOriginHostname(tool) : "no-origin-url",
109109
"gitorigin.path": gitRemotePath(stripGitSuffix(origin)),

test/suite/generate-url-tokens.test.ts

+76-1
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ suite("Generate URL Tokens", () => {
452452
});
453453
});
454454

455-
suite("Use genrated URL tokens", () => {
455+
suite("Use generated URL tokens", () => {
456456
const exampleCommit: LineAttachedCommit = {
457457
commit: {
458458
author: {
@@ -555,4 +555,79 @@ suite("Use genrated URL tokens", () => {
555555
"https://git.company.com/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
556556
);
557557
});
558+
559+
test("Url with port (#188 regression)", async () => {
560+
const activeEditorStub = stub(getActive, "getActiveTextEditor");
561+
const execcommandStub = stub(execcommand, "execute");
562+
const propertyStub = stub(property, "getProperty");
563+
activeEditorStub.returns({
564+
document: {
565+
isUntitled: false,
566+
fileName: "/fake.file",
567+
uri: Uri.parse("/fake.file"),
568+
lineCount: 1024,
569+
},
570+
selection: {
571+
active: {
572+
line: 9,
573+
},
574+
},
575+
});
576+
execcommandStub
577+
.withArgs(
578+
match.string,
579+
["symbolic-ref", "-q", "--short", "HEAD"],
580+
match.object,
581+
)
582+
.resolves("master");
583+
execcommandStub
584+
.withArgs(match.string, ["config", "branch.master.remote"], match.object)
585+
.resolves("origin");
586+
execcommandStub
587+
.withArgs(match.string, ["config", "remote.origin.url"], match.object)
588+
.resolves("http://git.company.com:8080/project_x/test-repository.git");
589+
execcommandStub
590+
.withArgs(
591+
match.string,
592+
["ls-remote", "--get-url", "origin"],
593+
match.object,
594+
)
595+
.resolves("http://git.company.com:8080/project_x/test-repository.git");
596+
execcommandStub
597+
.withArgs(
598+
match.string,
599+
["ls-files", "--full-name", "--", "/fake.file"],
600+
match.object,
601+
)
602+
.resolves("/fake.file");
603+
execcommandStub
604+
.withArgs(
605+
match.string,
606+
["rev-parse", "--abbrev-ref", "origin/HEAD"],
607+
match.object,
608+
)
609+
.resolves("origin/main");
610+
propertyStub.withArgs("remoteName").returns("origin");
611+
612+
const tokens = await generateUrlTokens(exampleCommit);
613+
614+
activeEditorStub.restore();
615+
execcommandStub.restore();
616+
propertyStub.restore();
617+
618+
if (tokens === undefined) {
619+
assert.notStrictEqual(tokens, undefined);
620+
return;
621+
}
622+
623+
const parsedUrl = parseTokens(
624+
"${tool.protocol}//${gitorigin.hostname}${gitorigin.port}${gitorigin.path}${tool.commitpath}${hash}",
625+
tokens,
626+
);
627+
628+
assert.strictEqual(
629+
parsedUrl,
630+
"http://git.company.com:8080/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
631+
);
632+
})
558633
});

0 commit comments

Comments
 (0)