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

[feature-request] browse-*from*-remote: given a url, open the file/line/commit it points to #62

Open
verhovsky opened this issue Jan 16, 2020 · 6 comments

Comments

@verhovsky
Copy link

verhovsky commented Jan 16, 2020

Could this project support the inverse operation?

I have a URL in my clipboard

github.com/rmuslimov/browse-at-remote/blob/1a9392e9d1fad4e1aafb25b68b4e6857fde8f564/browse-at-remote.el#L39

and I want to open the file at that commit hash (or branch name) and at the line number in that URL in emacs.

@rmuslimov
Copy link
Owner

I don't think it is possible, since in standard flow (from editor to ui) we can call git commands to retrieve required information. In reverse flow information is not enough to locate file or even branch.

@verhovsky
Copy link
Author

What do you mean? All the information is there, the file is at git checkout 1a9392e9d1fad4e1aafb25b68b4e6857fde8f564 (or there could be a branch name in that part of the URL, git checkout should just work) and the absolute file path is $(git rev-parse --show-toplevel)/browse-at-remote.el on line 39.

@rmuslimov
Copy link
Owner

Can you please explain how git root path can be found from URL in clipboard?

@rmuslimov rmuslimov reopened this Mar 9, 2020
@verhovsky
Copy link
Author

Can you get the directory of the buffer where the "inverse browse-at-remote" command was called and then you do git rev-parse --show-toplevel in that directory and append everything after the blob name to it to get the path?

@rmuslimov
Copy link
Owner

@verhovsky How to get right location of git root folder?

@verhovsky
Copy link
Author

verhovsky commented Mar 23, 2020

You can't get it from the URL. You would get it from the location of the buffer I have open in Emacs when I run the inverse command. Just as you do now for the regular browse-at-remote commands.

If I have repositories a and b and I try to open a URL that is from a remote of repo a while I'm looking at a file in repo b, then you'll get the root location of repo b, extract the relative path from the url and then try to look up a file path that doesn't exist (it might exist by coincidence sometimes) and show me an error message like "This file doesn't exist. You might've opened a link from the wrong repo: {link I tried to open}". This would also happen if the file was created on the remote but I don't have it (just as I get 404 errors now if I try to browse-at-remote a file that the remote doesn't have, or try to look at a file that was deleted on the remote).

Additionally, if the remote url I'm trying to open doesn't exist in the .git/config file of the repo that I'm running the command from, you can guess that I'm probably running the command from the wrong repo. But that's not necessarily the case, I might just not have a remote configured as a remote, so this check isn't really necessary. Could just help you improve the error message.

@verhovsky verhovsky changed the title [feature-request] url to local filepath, commit hash and line number [feature-request] browse-*from*-remote: given a url, open the file/line/commit it points to Mar 11, 2021
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