Tighten match for commit under cursor

Using `coo` to open a branch under the cursor that started with 4+ hex
digits (e.g., 1111-feat) would fail with the error `fatal: invalid
reference: 1111.`

This happened because the prior regex would consider these branch names
as commits when determining whether to treat what was under the cursor
as a branch or commit.

This changes the regex to use a negative look-ahead to further tighten
the match for a commit and require that a match on 4+ hex digits also
not end with a non-hex digit.

Resolves #2085.
This commit is contained in:
Eric Milford
2022-11-23 12:28:55 -06:00
committed by Tim Pope
parent 23b9b9b2a3
commit 49cc58573e

View File

@@ -7553,7 +7553,7 @@ function! s:SquashArgument(...) abort
if &filetype == 'fugitive' if &filetype == 'fugitive'
let commit = matchstr(getline('.'), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze \|^' . s:ref_header . ': \zs\S\+') let commit = matchstr(getline('.'), '^\%(\%(\x\x\x\)\@!\l\+\s\+\)\=\zs[0-9a-f]\{4,\}\ze \|^' . s:ref_header . ': \zs\S\+')
elseif has_key(s:temp_files, s:cpath(expand('%:p'))) elseif has_key(s:temp_files, s:cpath(expand('%:p')))
let commit = matchstr(getline('.'), '\S\@<!\x\{4,\}\>') let commit = matchstr(getline('.'), '\S\@<!\x\{4,\}\S\@!')
else else
let commit = s:Owner(@%) let commit = s:Owner(@%)
endif endif