Skip to content

Commit 07de0b8

Browse files
committed
Add completion for revision range
1 parent b7287bd commit 07de0b8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

autoload/fugitive.vim

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,6 +2415,17 @@ function! s:CompleteHeads(dir) abort
24152415
\ sort(s:LinesError([a:dir, 'rev-parse', '--symbolic', '--branches', '--tags', '--remotes'])[0])
24162416
endfunction
24172417

2418+
function! s:SplitRevRange(base, pat)
2419+
let index = matchend(a:base, a:pat)
2420+
if index == -1
2421+
return ['', a:base]
2422+
endif
2423+
let pre = a:base[:index - 1]
2424+
let base = a:base[index:]
2425+
return [pre, base]
2426+
endif
2427+
endfunction
2428+
24182429
function! fugitive#CompleteObject(base, ...) abort
24192430
let dir = a:0 == 1 ? a:1 : a:0 >= 3 ? a:3 : s:Dir()
24202431
let tree = s:Tree(dir)
@@ -2424,9 +2435,10 @@ function! fugitive#CompleteObject(base, ...) abort
24242435
let subdir = strpart(cwd, len(tree) + 1) . '/'
24252436
endif
24262437
let base = s:Expand(a:base)
2438+
let [pre, base] = s:SplitRevRange(base, '^[^:]*\/\@<!\.\.\.\=[\/\.]\@!')
24272439

24282440
if a:base =~# '^!\d*$' && base !~# '^!'
2429-
return [base]
2441+
return [pre . base]
24302442
elseif base =~# '^\.\=/\|^:(' || base !~# ':'
24312443
let results = []
24322444
if base =~# '^refs/'
@@ -2442,6 +2454,7 @@ function! fugitive#CompleteObject(base, ...) abort
24422454
let results += s:FilterEscape(heads, fnameescape(base))
24432455
endif
24442456
let results += a:0 == 1 || a:0 >= 3 ? fugitive#CompletePath(base, 0, '', dir, a:0 >= 4 ? a:4 : tree) : fugitive#CompletePath(base)
2457+
let results = map(results, 'pre . v:val')
24452458
return results
24462459

24472460
elseif base =~# '^:'
@@ -2461,7 +2474,7 @@ function! fugitive#CompleteObject(base, ...) abort
24612474
call map(entries,'s:sub(v:val,"^04.*\\zs$","/")')
24622475
call map(entries,'parent.s:sub(v:val,".*\t","")')
24632476
endif
2464-
return s:FilterEscape(entries, fnameescape(base))
2477+
return map(s:FilterEscape(entries, fnameescape(base)), 'pre . v:val')
24652478
endfunction
24662479

24672480
function! s:CompleteSub(subcommand, A, L, P, ...) abort

0 commit comments

Comments
 (0)