Add support for base branch in vim PR commands
parent
1c76a83d48
commit
9772330d5c
|
@ -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(<f-args>)
|
||||
command! -nargs=? Gpr Gpropen <args>
|
||||
command! -nargs=? Gprprint :call s:PrintPrUrl(<f-args>)
|
||||
command! -nargs=? Gprcopy :call s:CopyPrUrl(<f-args>)
|
||||
command! -nargs=1 Gcbranch :call s:CreateBranch(<f-args>)
|
||||
command! -nargs=0 Gcmaster :call s:CheckoutBranch('main')
|
||||
command! -nargs=0 Gcm Gcmaster
|
||||
|
|
Loading…
Reference in New Issue