Provide :Gedit - to open previous :Git output

Also, provide :GBrowse - to open the first URL contained in that output.
This commit is contained in:
Tim Pope
2021-03-18 00:57:30 -04:00
parent 6b39f6c641
commit a1cb01da5b
2 changed files with 36 additions and 4 deletions

View File

@@ -2321,6 +2321,20 @@ function! s:TempState(...) abort
return get(s:temp_files, s:cpath(fnamemodify(a:0 ? a:1 : @%, ':p')), {})
endfunction
function! fugitive#Result(...) abort
if !a:0 || a:1 =~# '^-\=$'
return get(g:, '_fugitive_last_job', {})
elseif type(a:1) == type(0)
return s:TempState(bufname(a:1))
elseif type(a:1) == type('')
return s:TempState(a:1)
elseif type(a:1) == type({}) && has_key(a:1, 'file')
return s:TempState(a:1.file)
else
return {}
endif
endfunction
function! s:TempReadPre(file) abort
if has_key(s:temp_files, s:cpath(a:file))
let dict = s:temp_files[s:cpath(a:file)]
@@ -4741,6 +4755,14 @@ function! s:OpenParse(string, wants_cmd) abort
endwhile
if len(args)
let file = join(args)
if file ==# '-'
let result = fugitive#Result()
if has_key(result, 'file')
let file = s:fnameescape(result.file)
else
throw 'fugitive: no previous command output'
endif
endif
elseif empty(expand('%'))
let file = ''
elseif empty(s:DirCommitFile(@%)[1]) && s:Relative('./') !~# '^\./\.git\>'
@@ -5932,10 +5954,19 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
endif
let validremote = '\.\|\.\=/.*\|[[:alnum:]_-]\+\%(://.\{-\}\)\='
if arg ==# '-'
if a:count >= 0
return 'echoerr ' . string('fugitive: ''-'' no longer required to get persistent URL if range given')
else
return 'echoerr ' . string('fugitive: use :0GBrowse instead of :GBrowse -')
let remote = ''
let rev = ''
let result = fugitive#Result()
if filereadable(get(result, 'file', ''))
for line in readfile(result.file, 4096)
let rev = s:fnameescape(matchstr(line, '\<https\=://[^[:space:]<>]*[^[:space:]<>.,;:"''!?]'))
if len(rev)
break
endif
endfor
if empty(rev)
return 'echoerr ' . string('fugitive: no URL found in output of last :Git')
endif
endif
elseif !exists('l:remote')
let remote = matchstr(arg, '@\zs\%('.validremote.'\)$')

View File

@@ -590,6 +590,7 @@ Makefile The file named Makefile in the work tree
!3^2 The second parent of the commit owning buffer #3
.git/config The repo config file
: The |fugitive-summary| buffer.
- A temp file containing the last |:Git| invocation's output
STATUSLINE *fugitive-statusline*