Open verhovsky opened 4 years ago
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.
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.
Can you please explain how git root path can be found from URL in clipboard?
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?
@verhovsky How to get right location of git root folder?
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.
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.