commit 01b9a645b6dc3abb699237d2fe30c0a1bb90d26e (tree)
parent 74aefa53acbc0653a97a6cd640b5dd57d591a7c3
Author: Tim Pope <code@tpope.net>
Date: Thu, 14 Feb 2019 17:06:12 -0500
Provide checkout --ours/--theirs on X
Closes https://github.com/tpope/vim-fugitive/issues/954
Diffstat:
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/autoload/fugitive.vim b/autoload/fugitive.vim
@@ -1407,6 +1407,7 @@ function! fugitive#BufReadStatus() abort
let branch = head
endif
+ let b:fugitive_status = {'Staged': {}, 'Unstaged': {}}
let [staged, unstaged] = [[], []]
let i = 0
while i < len(output)
@@ -1422,13 +1423,22 @@ function! fugitive#BufReadStatus() abort
let i += 1
endif
if line[0] !~# '[ ?!#]'
- call add(staged, {'type': 'File', 'status': line[0], 'filename': (line[0] =~# '[RC]' ? files : file)})
+ call add(staged, {'type': 'File', 'status': line[0], 'filename': files})
+ let b:fugitive_status['Staged'][files] = line[0]
endif
if line[1] !~# '[ !#]'
- call add(unstaged, {'type': 'File', 'status': line[1], 'filename': (line[1] =~# '[RC]' ? files : file)})
+ call add(unstaged, {'type': 'File', 'status': line[1], 'filename': files})
+ let b:fugitive_status['Unstaged'][files] = line[1]
endif
endwhile
+ for dict in staged
+ let b:fugitive_status['Staged'][dict.filename] = dict.status
+ endfor
+ for dict in unstaged
+ let b:fugitive_status['Unstaged'][dict.filename] = dict.status
+ endfor
+
let config = fugitive#Config()
let pull_type = 'Pull'
@@ -2434,6 +2444,13 @@ function! s:StageDelete(lnum, count) abort
catch /^fugitive:/
return 'echoerr v:errmsg'
endtry
+ elseif a:count == 2
+ call s:TreeChomp('checkout', '--ours', '--', info.paths[0])
+ elseif a:count == 3
+ call s:TreeChomp('checkout', '--theirs', '--', info.paths[0])
+ elseif info.status =~# '[ADU]' &&
+ \ get(b:fugitive_status[info.section ==# 'Staged' ? 'Unstaged' : 'Staged'], info.filename, '') =~# '[AU]'
+ call s:TreeChomp('checkout', info.section ==# 'Staged' ? '--ours' : '--theirs', '--', info.paths[0])
elseif info.status ==# 'U'
call s:TreeChomp('rm', '--', info.paths[0])
elseif info.status ==# 'A'
diff --git a/doc/fugitive.txt b/doc/fugitive.txt
@@ -259,7 +259,10 @@ u Unstage (reset) the file or hunk under the cursor.
X Discard the change under the cursor. This uses
`checkout` or `clean` under the hood. A command is
echoed that shows how to undo the change. Consult
- `:messages` to see it again.
+ `:messages` to see it again. You can use this during
+ a merge conflict do discard "our" changes (--theirs)
+ in the "Unstaged" section or discard "their" changes
+ (--ours) in the "Staged" section.
*fugitive_=*
= Toggle an inline diff of the file under the cursor.