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

Handle range-diff commit header lines in s:cfile() #2353

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions autoload/fugitive.vim
Original file line number Diff line number Diff line change
Expand Up @@ -8135,6 +8135,9 @@ function! s:BranchCfile(result) abort
endfunction

let s:diff_header_pattern = '^diff --git \%("\=[abciow12]/.*\|/dev/null\) \%("\=[abciow12]/.*\|/dev/null\)$'
let s:rdiff_hash_or_missing = '\(\x\{7,40\}\|-\{7,40\}\)'
let s:rdiff_side = '\%(-\|\d\+\):\s\+' . s:rdiff_hash_or_missing
let s:rdiff_header_pattern = '^' . s:rdiff_side . '\s\+[=!<>]\s\+' . s:rdiff_side . '\s\+'
function! s:cfile() abort
let temp_state = s:TempState()
let name = substitute(get(get(temp_state, 'args', []), 0, ''), '\%(^\|-\)\(\l\)', '\u\1', 'g')
Expand Down Expand Up @@ -8232,6 +8235,19 @@ function! s:cfile() abort
let dcmds = ['', 'Gdiffsplit! >' . myhash . '^:' . fnameescape(files[0])]
endif

elseif getline('.') =~# s:rdiff_header_pattern
let ref = ''
let matches = matchlist(getline('.'), s:rdiff_header_pattern)
if matches[1] =~# '^-\+$' && matches[2] =~# '^\x\{7,40\}$'
let ref = matches[2]
elseif matches[2] =~# '^-\+$' && matches[1] =~# '^\x\{7,40\}$'
let ref = matches[1]
elseif matches[1] =~# '^\x\{7,40\}$' && matches[1] == matches[2]
let ref = matches[1]
elseif expand('<cword>') =~# '^\x\{7,40\}$'
let ref = expand('<cword>')
endif

elseif getline('.') =~# '^[+-]'
let [header_lnum, old_lnum, new_lnum] = s:HunkPosition(line('.'))
if new_lnum > 0
Expand Down