Skip to content

Fix gitorigin.port error for http(s) #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2025
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
4 changes: 2 additions & 2 deletions src/git/util/get-tool-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const generateUrlTokens = async (
return;
}

const remoteUrl = stripGitRemoteUrl(await getRemoteUrl(remoteName));
const remoteUrl = await getRemoteUrl(remoteName);
const tool = originUrlToToolUrl(remoteUrl);
const filePath = await getRelativePathOfActiveFile();
const defaultBranch = await getDefaultBranch(remoteName);
Expand All @@ -103,7 +103,7 @@ export const generateUrlTokens = async (
"tool.protocol": tool?.protocol ?? "https:",
"tool.commitpath": `/commit${isToolUrlPlural(remoteUrl) ? "s" : ""}/`,
"project.name": projectNameFromOrigin(origin),
"project.remote": remoteUrl,
"project.remote": stripGitRemoteUrl(remoteUrl),
"project.defaultbranch": defaultBranch,
"gitorigin.hostname": tool ? gitOriginHostname(tool) : "no-origin-url",
"gitorigin.path": gitRemotePath(stripGitSuffix(origin)),
Expand Down
77 changes: 76 additions & 1 deletion test/suite/generate-url-tokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ suite("Generate URL Tokens", () => {
});
});

suite("Use genrated URL tokens", () => {
suite("Use generated URL tokens", () => {
const exampleCommit: LineAttachedCommit = {
commit: {
author: {
Expand Down Expand Up @@ -555,4 +555,79 @@ suite("Use genrated URL tokens", () => {
"https://git.company.com/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
);
});

test("Url with port (#188 regression)", async () => {
const activeEditorStub = stub(getActive, "getActiveTextEditor");
const execcommandStub = stub(execcommand, "execute");
const propertyStub = stub(property, "getProperty");
activeEditorStub.returns({
document: {
isUntitled: false,
fileName: "/fake.file",
uri: Uri.parse("/fake.file"),
lineCount: 1024,
},
selection: {
active: {
line: 9,
},
},
});
execcommandStub
.withArgs(
match.string,
["symbolic-ref", "-q", "--short", "HEAD"],
match.object,
)
.resolves("master");
execcommandStub
.withArgs(match.string, ["config", "branch.master.remote"], match.object)
.resolves("origin");
execcommandStub
.withArgs(match.string, ["config", "remote.origin.url"], match.object)
.resolves("http://git.company.com:8080/project_x/test-repository.git");
execcommandStub
.withArgs(
match.string,
["ls-remote", "--get-url", "origin"],
match.object,
)
.resolves("http://git.company.com:8080/project_x/test-repository.git");
execcommandStub
.withArgs(
match.string,
["ls-files", "--full-name", "--", "/fake.file"],
match.object,
)
.resolves("/fake.file");
execcommandStub
.withArgs(
match.string,
["rev-parse", "--abbrev-ref", "origin/HEAD"],
match.object,
)
.resolves("origin/main");
propertyStub.withArgs("remoteName").returns("origin");

const tokens = await generateUrlTokens(exampleCommit);

activeEditorStub.restore();
execcommandStub.restore();
propertyStub.restore();

if (tokens === undefined) {
assert.notStrictEqual(tokens, undefined);
return;
}

const parsedUrl = parseTokens(
"${tool.protocol}//${gitorigin.hostname}${gitorigin.port}${gitorigin.path}${tool.commitpath}${hash}",
tokens,
);

assert.strictEqual(
parsedUrl,
"http://git.company.com:8080/project_x/test-repository/commit/60d3fd32a7a9da4c8c93a9f89cfda22a0b4c65ce",
);
})
});