lambdalisue / vim-gina

👣 Asynchronously control git repositories in Neovim/Vim 8
http://www.vim.org/scripts/script.php?script_id=5531
MIT License
689 stars 27 forks source link

Support for `insteadOf` in `Gina browse` command #249

Closed jearbear closed 4 years ago

jearbear commented 4 years ago

I have this in my .gitconfig:

[url "git@github.com:"]
    insteadOf = gh:

The current method of fetching the remote url seems to rely on git config and effectively does git config remote.origin.url, but this will provide the url with gh:... which doesn't work with Gina browse, giving me this error:

[gina] No url translation pattern for "" is found.

I see two ways of fixing this:

  1. Modify the get_remote_url function to make a call out to git remote get-url origin which will return the fully resolved path. A similar approach was done for vim-fugitive: https://github.com/tpope/vim-fugitive/pull/874, though I'm not sure how involved it'll be for gina.vim.
  2. To avoid a call to git, perform some internal translation based on if insteadOf is present in the config. I imagine this is way more work than it's worth.
jearbear commented 4 years ago

Oh I realized the first solution isn't too hard. Does something like this seem reasonable?

diff --git a/autoload/gina/command/browse.vim b/autoload/gina/command/browse.vim
index 78e9de8..d713922 100644
--- a/autoload/gina/command/browse.vim
+++ b/autoload/gina/command/browse.vim
@@ -141,7 +141,11 @@ function! s:get_remote_url(git, commit1, commit2) abort
     endif
   endfor
   let remote_name = empty(remote_name) ? 'origin' : remote_name
-  return get(config, printf('remote.%s.url', remote_name), '')
+  let result = gina#process#call(a:git, ['remote', 'get-url', remote_name])
+  if result.status
+    throw gina#process#errormsg(result)
+  endif
+  return result.content[0]
 endfunction
 function! s:build_base_url(remote_url, scheme) abort
lambdalisue commented 4 years ago

It seems reasonable. Please send a PR 👍

lambdalisue commented 4 years ago

Closed by #250