Skip to content

Commit

Permalink
Add git commands 'cherry-pick', 'reset' and 'branch/tag -d' (#90)
Browse files Browse the repository at this point in the history
* Add git commands 'cherry-pick', 'reset' and 'branch/tag -d'

Change-Id: I861641433508b41e3f26e3b95aa3543659de7d08

* Fix typos

Change-Id: I791a6940ea40f9e2248995e4b4c073ec766ada42

* changed mappings b -> rb, bh -> rbh
  • Loading branch information
AlterDepp committed Jul 27, 2016
1 parent f061662 commit 1a9ed20
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/gitv.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,21 @@ modes.
must contain refs in the form of tags, remotes or
local branches.

visual cp Cherry-Picks the selected commits to the active
branch.
normal cp same as visual cp

visual rb Reset (mixed) the active branch to the top of the
selected commits
normal rb same as visual rb
visual rbh Reset (hard) the active branch to the top of the
selected commits
normal rbh same as visual rbh

visual d Delete a branch or tag on the selected line. You will
be asked which branch/tag to use.
normal d same as visual d

normal <leader>m Merges the first ref found on the current line in to
the branch currently pointed to by HEAD. This will
prompt you if you wish to use a fast-forward merge.
Expand Down
55 changes: 55 additions & 0 deletions plugin/gitv.vim
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,17 @@ fu! s:SetupMappings() "{{{
vnoremap <buffer> <silent> m :call <SID>MergeBranches()<cr>
nnoremap <buffer> <silent> <leader>m :call <SID>MergeToCurrent()<cr>
nmap <buffer> <silent> cp :call <SID>CherryPick()<cr>
vmap <buffer> <silent> cp :call <SID>CherryPick()<cr>
nmap <buffer> <silent> rb :call <SID>ResetBranch('--mixed')<cr>
vmap <buffer> <silent> rb :call <SID>ResetBranch('--mixed')<cr>
nmap <buffer> <silent> rbh :call <SID>ResetBranch('--hard')<cr>
vmap <buffer> <silent> rbh :call <SID>ResetBranch('--hard')<cr>
nmap <buffer> <silent> d :call <SID>DeleteRef()<cr>
vmap <buffer> <silent> d :call <SID>DeleteRef()<cr>
"movement
nnoremap <buffer> <silent> x :call <SID>JumpToBranch(0)<cr>
nnoremap <buffer> <silent> X :call <SID>JumpToBranch(1)<cr>
Expand Down Expand Up @@ -1010,6 +1021,50 @@ fu! s:MergeToCurrent()

call s:PerformMerge("HEAD", target, ff)
endfu "}}}
fu! s:CherryPick() range "{{{
let refs2 = s:GetGitvSha(a:firstline)
let refs1 = s:GetGitvSha(a:lastline)
if refs1 == refs2
let refs = refs1
else
let refs = refs1 . "^.." . refs2
endif

echom "Cherry-Pick " . refs
exec 'Git cherry-pick ' . refs
endfu "}}}
fu! s:ResetBranch(mode) range "{{{
let ref = s:GetGitvSha(a:firstline)

echom "Reset " . a:mode . " to " . ref
exec 'Git reset ' . a:mode . " " . ref
endfu "}}}
fu! s:DeleteRef() range "{{{
let refs = s:GetGitvRefs(a:firstline)
call filter(refs, 'v:val !=? "HEAD"')
let choice = confirm("Choose branch to delete:", s:GetConfirmString(refs, "Cancel"))
if choice == 0
return
endif
let choice = get(refs, choice-1, "")
if choice == ""
return
endif
if match(choice, 'tag: .*') < 0
let command = "branch"
else
let command = "tag"
endif
let choice = substitute(choice, "^t:", "", "")
let choice = substitute(choice, "^r:", "", "")
let choice = substitute(choice, "^tag: t:", "", "")
if s:IsFileMode()
let relPath = s:GetRelativeFilePath()
let choice .= " -- " . relPath
endif
echom "Delete " . command . " " . choice
exec 'Git ' . command . " -d " . choice
endfu "}}}
fu! s:StatGitvCommit() range "{{{
let shafirst = s:GetGitvSha(a:firstline)
let shalast = s:GetGitvSha(a:lastline)
Expand Down

0 comments on commit 1a9ed20

Please sign in to comment.