2021-01-14 11:40:40 +00:00
|
|
|
" -----------------------------------------------------------------------------
|
|
|
|
" - Fugitive.vim setup and extra mappings -
|
|
|
|
" -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
" Shorcut to push directly to current branch on origin
|
|
|
|
" Similar to `ggpush` in fish config
|
|
|
|
function! s:PushOrigin()
|
2021-01-14 14:11:46 +00:00
|
|
|
execute 'Git push origin ' . FugitiveHead()
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Shorcut to pull directly from current branch on origin
|
|
|
|
" Similar to `ggpull` in fish config
|
|
|
|
function! s:PullOrigin()
|
|
|
|
execute 'Git pull origin ' . FugitiveHead()
|
2021-01-14 11:40:40 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Generates url for creating PR for current branch
|
|
|
|
" Tested only with github.com
|
|
|
|
" Works regardless of ssh or https for origin config
|
|
|
|
" Hardcoded to use 'origin' remote
|
2021-01-15 11:49:50 +00:00
|
|
|
function! s:GetPrUrl(...)
|
2021-01-14 11:40:40 +00:00
|
|
|
let origin_url = fugitive#RemoteUrl('origin')
|
2021-01-14 13:13:40 +00:00
|
|
|
let origin_url = substitute(l:origin_url, '\.git$', '', '')
|
2021-01-14 11:40:40 +00:00
|
|
|
let origin_url = substitute(l:origin_url, ':', '/', '')
|
|
|
|
let origin_url = substitute(l:origin_url, 'git@', 'https://', '')
|
2021-01-15 11:49:50 +00:00
|
|
|
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
|
2021-01-14 11:40:40 +00:00
|
|
|
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
|
2021-01-15 11:49:50 +00:00
|
|
|
function! s:PrintPrUrl(...)
|
|
|
|
echo call('s:GetPrUrl', a:000)
|
2021-01-14 11:40:40 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Copies current branches PR url to system clipboard
|
2021-01-15 11:49:50 +00:00
|
|
|
function! s:CopyPrUrl(...)
|
|
|
|
let @+ = call('s:GetPrUrl', a:000)
|
2021-01-14 11:40:40 +00:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Opens current banches PR url in default browser
|
|
|
|
" Utilizes netrw browse, meaning it should behave same as netrw
|
2021-01-15 11:49:50 +00:00
|
|
|
function! s:OpenNewPr(...)
|
|
|
|
call netrw#BrowseX(call('s:GetPrUrl', a:000), 0)
|
2021-01-14 11:40:40 +00:00
|
|
|
endfunction
|
|
|
|
|
2021-01-14 14:38:31 +00:00
|
|
|
" Creates new branch and checks out to it
|
|
|
|
" Similar to `gcb` in fish config
|
|
|
|
function! s:CreateBranch(branch)
|
|
|
|
execute 'Git checkout -b ' . a:branch
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Switches to branch
|
|
|
|
function! s:CheckoutBranch(branch)
|
|
|
|
execute 'Git checkout ' . a:branch
|
|
|
|
endfunction
|
|
|
|
|
2021-01-14 11:40:40 +00:00
|
|
|
command! -nargs=0 Ggpush :call s:PushOrigin()
|
2021-01-14 15:54:17 +00:00
|
|
|
command! -nargs=0 Ggpull :call s:PullOrigin()
|
2021-01-15 11:49:50 +00:00
|
|
|
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>)
|
2021-01-14 14:38:31 +00:00
|
|
|
command! -nargs=1 Gcbranch :call s:CreateBranch(<f-args>)
|
|
|
|
command! -nargs=0 Gcmaster :call s:CheckoutBranch('main')
|
|
|
|
command! -nargs=0 Gcm Gcmaster
|
|
|
|
command! -nargs=0 Gcdev :call s:CheckoutBranch('develop')
|
|
|
|
command! -nargs=1 Gcheckout :call s:CheckoutBranch(<f-args>)
|
|
|
|
command! -nargs=1 Gc Gcheckout <args>
|