Skip to content
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

With Custom Repo when Check remote is disabled the link generated is always with the commit ID in URL #267

Open
gkns opened this issue Nov 24, 2022 · 4 comments

Comments

@gkns
Copy link

gkns commented Nov 24, 2022

My remote is Gerrit for review purposes, however, when I generate the link, I want it to point to the GitLab repo; Hence I have a custom domain configuration.

Since my repo is large, I have disabled the Check remote as recommended by the plugin.

But with the above changes, The link generated by Open in GitlabVMW (GitlabVMW is my custom domain configuration which is described below) will always have a commit ID in the file path.
This commit ID will not exist in remote since the commit IDs will be different for Gerrit and Gitlab; Making the link 404.
Eg link generated:
https://gitlab.eng.vmware.com/core-build/repo/-/blob/0361d35bb144cdeaf534a2b1dc03fd19d6af23e5/File.java#L116-L116

I think this is a bug that has to do with the Check remote feature.

My custom domain configuration is as follows:

// File at branch template : 
https://gitlab.eng.vmware.com/core-build/{remote:url:path:0}/-/blob/{branch}/{file:path}/{file:name}#L{line:start}-L{line:end}{line-block:end}

// File at commit template: 
https://gitlab.eng.vmware.com/core-build/{remote:url:path:1}/-/blob/{commit}/{file:name}{line-block:start}#L{line:start}-L{line:end}{line-block:end}

// Commit Template:
https://gitlab.eng.vmware.com/core-build/{remote:url:path:1}/-/commit/{commit}

Am I missing anything or can this be fixed?

@gkns
Copy link
Author

gkns commented Nov 24, 2022

Upon looking at the code, may the below be a fix?

Location

change the condition :

if (commit != null) {
          UrlOptionsFileAtCommit(baseUrl, repositoryFile, commit, context.lineSelection)
} else {
 ...
}

To may be:

if (commit != null && settings.shouldCheckRemote) {
          UrlOptionsFileAtCommit(baseUrl, repositoryFile, commit, context.lineSelection)
} else {
 ...
}

@gkns
Copy link
Author

gkns commented Nov 29, 2022

Hi, @ben-gibson, Any ideas to fix this locally as an interim measure?

@ben-gibson
Copy link
Owner

Sorry for the delayed response, I don't have my own laptop right now.

By unchecking the Check remote option, GitLink can't go to the remote to check if the commit or branch exists there. As it can't perform that check, it has to blindly assume it does (which is the behaviour most people wanted in #202). I think what you really need here is, a new option in the settings like Always use branch.

The only work around that I know of would be to re-enable the check remote option for now.

@gkns
Copy link
Author

gkns commented Nov 30, 2022

Thank you! Acknowledge.
For now, I have made the following tweaks in the custom-domain template and it works.

File at branch template :
https://gitlab.eng.vmware.com/core-build/{remote:url:path:1}/-/blob/<hardcoded-branch-name>/{file:path}/{file:name}#L{line:start}-L{line:end}{line-block:end}

File at commit template: 
https://gitlab.eng.vmware.com/core-build/{remote:url:path:1}/-/blob/{commit}/{file:name}{line-block:start}#L{line:start}-L{line:end}{line-block:end}

Commit Template:
https://gitlab.eng.vmware.com/core-build/{remote:url:path:1}/-/commit/{commit}

Additionally:

Fallback branch: <empty>
disable Check remote
remote gitlab (Added it using the git remote add command)

Although the above is completely customised for my requirements.
Anyone who encounters this issue can can actually tweak the URL template and get around this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants