From 9772330d5cea850b04b7d1a018c8f83e77b8947a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Fri, 15 Jan 2021 12:49:50 +0100 Subject: [PATCH] Add support for base branch in vim PR commands --- symlinks/vim/plugin/fugitive.vim | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/symlinks/vim/plugin/fugitive.vim b/symlinks/vim/plugin/fugitive.vim index 6838adc..4c7fa2f 100644 --- a/symlinks/vim/plugin/fugitive.vim +++ b/symlinks/vim/plugin/fugitive.vim @@ -18,30 +18,34 @@ endfunction " Tested only with github.com " Works regardless of ssh or https for origin config " Hardcoded to use 'origin' remote -function! s:GetPrUrl() +function! s:GetPrUrl(...) let origin_url = fugitive#RemoteUrl('origin') let origin_url = substitute(l:origin_url, '\.git$', '', '') let origin_url = substitute(l:origin_url, ':', '/', '') let origin_url = substitute(l:origin_url, 'git@', 'https://', '') - let pr_url = l:origin_url . '/compare/' . FugitiveHead() . '?expand=1' + if a:0 == 0 + let pr_url = l:origin_url . '/compare/' . FugitiveHead() . '?expand=1' + else + let pr_url = l:origin_url . '/compare/' . a:1 . '...' . FugitiveHead() . '?expand=1' + endif return l:pr_url endfunction " Prints current branches PR url (not saved to :messages) " Makes it easy to use terminal for opening url on click -function! s:PrintPrUrl() - echo s:GetPrUrl() +function! s:PrintPrUrl(...) + echo call('s:GetPrUrl', a:000) endfunction " Copies current branches PR url to system clipboard -function! s:CopyPrUrl() - let @+ = s:GetPrUrl() +function! s:CopyPrUrl(...) + let @+ = call('s:GetPrUrl', a:000) endfunction " Opens current banches PR url in default browser " Utilizes netrw browse, meaning it should behave same as netrw -function! s:OpenNewPr() - call netrw#BrowseX(s:GetPrUrl(), 0) +function! s:OpenNewPr(...) + call netrw#BrowseX(call('s:GetPrUrl', a:000), 0) endfunction " Creates new branch and checks out to it @@ -57,10 +61,10 @@ endfunction command! -nargs=0 Ggpush :call s:PushOrigin() command! -nargs=0 Ggpull :call s:PullOrigin() -command! -nargs=0 Gpropen :call s:OpenNewPr() -command! -nargs=0 Gpr Gpropen -command! -nargs=0 Gprprint :call s:PrintPrUrl() -command! -nargs=0 Gprcopy :call s:CopyPrUrl() +command! -nargs=? Gpropen :call s:OpenNewPr() +command! -nargs=? Gpr Gpropen +command! -nargs=? Gprprint :call s:PrintPrUrl() +command! -nargs=? Gprcopy :call s:CopyPrUrl() command! -nargs=1 Gcbranch :call s:CreateBranch() command! -nargs=0 Gcmaster :call s:CheckoutBranch('main') command! -nargs=0 Gcm Gcmaster