Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use upstream ref if possible #42

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions plugin/vim-gh-line.vim
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,31 @@ func! s:Action(remote_url, action)
endif
endfunc

func! s:BranchName(cdDir, ref)
return trim(system(a:cdDir . 'git rev-parse --abbrev-ref ' . a:ref))
endfunc

func! s:CommitRef(cdDir)
let l:upstreamBranch = system(a:cdDir . 'git rev-parse --abbrev-ref --symbolic-full-name @{u}')
if v:shell_error == 0
return l:upstreamBranch
else
let l:currentBranch = s:BranchName(a:cdDir, 'HEAD')
let l:branch = input('Please provide a remote branch (defaults to ' . l:currentBranch . '): ')
if len(l:branch) == 0
return l:currentBranch
endif

return l:branch
endif
endfunc

func! s:Commit(cdDir)
let l:ref = s:CommitRef(a:cdDir)
if exists('g:gh_use_canonical') && g:gh_use_canonical > 0
return system(a:cdDir . 'git rev-parse HEAD')
return system(a:cdDir . 'git rev-parse ' . l:ref)
else
return system(a:cdDir . 'git rev-parse --abbrev-ref HEAD')
return s:BranchName(l:ref)
endif
endfunc

Expand Down
2 changes: 1 addition & 1 deletion test/vim-gh-line_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func! s:testCommit(sid)

let g:gh_use_canonical = 0
let l:act = s:callWithSID(a:sid, 'Commit', l:cdDir)
call assert_match(l:branch, l:act,
call assert_equal(l:branch, l:act,
\ 'Expected to find branch name in the Commit output ')
unlet g:gh_use_canonical
endfunction
Expand Down