Replace HEAD with @

The @ shortcut for HEAD was introduced in 1.8.5, which we now require.
This commit is contained in:
Tim Pope
2021-04-16 10:20:07 -04:00
parent 895e56daca
commit b227b887bb

View File

@@ -918,7 +918,7 @@ function! s:Owner(path, ...) abort
if commit =~# '^\x\{40,\}$' if commit =~# '^\x\{40,\}$'
return commit return commit
elseif commit ==# '2' elseif commit ==# '2'
return 'HEAD^{}' return '@'
elseif commit ==# '0' elseif commit ==# '0'
return '' return ''
endif endif
@@ -927,7 +927,7 @@ function! s:Owner(path, ...) abort
return '' return ''
endif endif
if commit ==# '3' if commit ==# '3'
return merge_head . '^{}' return merge_head
elseif commit ==# '1' elseif commit ==# '1'
return s:TreeChomp('merge-base', 'HEAD', merge_head, '--') return s:TreeChomp('merge-base', 'HEAD', merge_head, '--')
endif endif
@@ -1095,7 +1095,7 @@ function! fugitive#Find(object, ...) abort
let f = 'fugitive://' . dir . '//0/' . rev[1:-1] let f = 'fugitive://' . dir . '//0/' . rev[1:-1]
else else
if !exists('f') if !exists('f')
let commit = substitute(matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\|^:.*'), '^@\%($\|[~^]\|@{\)\@=', 'HEAD', '') let commit = matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\|^:.*')
let file = substitute(matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\zs:.*'), '^:', '/', '') let file = substitute(matchstr(rev, '^\%([^:.-]\|\.\.[^/:]\)[^:]*\zs:.*'), '^:', '/', '')
if file =~# '^/\.\.\=\%(/\|$\)\|^//\|^/\a\+:' if file =~# '^/\.\.\=\%(/\|$\)\|^//\|^/\a\+:'
let file = file =~# '^/\.' ? simplify(getcwd() . file) : file[1:-1] let file = file =~# '^/\.' ? simplify(getcwd() . file) : file[1:-1]
@@ -1111,7 +1111,7 @@ function! fugitive#Find(object, ...) abort
endif endif
let commits = split(commit, '\.\.\.-\@!', 1) let commits = split(commit, '\.\.\.-\@!', 1)
if len(commits) == 2 if len(commits) == 2
call map(commits, 'empty(v:val) || v:val ==# "@" ? "HEAD" : v:val') call map(commits, 'empty(v:val) ? "@" : v:val')
let commit = matchstr(s:ChompDefault('', [dir, 'merge-base'] + commits + ['--']), '\<[0-9a-f]\{40,\}\>') let commit = matchstr(s:ChompDefault('', [dir, 'merge-base'] + commits + ['--']), '\<[0-9a-f]\{40,\}\>')
endif endif
if commit !~# '^[0-9a-f]\{40,\}$\|^$' if commit !~# '^[0-9a-f]\{40,\}$\|^$'
@@ -3870,7 +3870,7 @@ function! s:StageDiff(diff) abort
return 'Git --paginate diff --no-ext-diff' return 'Git --paginate diff --no-ext-diff'
elseif len(info.paths) > 1 elseif len(info.paths) > 1
execute 'Gedit' . prefix s:fnameescape(':0:' . info.paths[0]) execute 'Gedit' . prefix s:fnameescape(':0:' . info.paths[0])
return a:diff . '! HEAD:'.s:fnameescape(info.paths[1]) return a:diff . '! @:'.s:fnameescape(info.paths[1])
elseif info.section ==# 'Staged' && info.sigil ==# '-' elseif info.section ==# 'Staged' && info.sigil ==# '-'
execute 'Gedit' prefix s:fnameescape(':0:'.info.paths[0]) execute 'Gedit' prefix s:fnameescape(':0:'.info.paths[0])
return a:diff . '! :0:%' return a:diff . '! :0:%'
@@ -4018,7 +4018,7 @@ function! s:StageDelete(lnum1, lnum2, count) abort
elseif info.section ==# 'Unstaged' elseif info.section ==# 'Unstaged'
call s:TreeChomp('checkout', '--', info.paths[0]) call s:TreeChomp('checkout', '--', info.paths[0])
else else
call s:TreeChomp('checkout', 'HEAD^{}', '--', info.paths[0]) call s:TreeChomp('checkout', '@', '--', info.paths[0])
endif endif
if len(undo) if len(undo)
call add(restore, ':Gsplit ' . s:fnameescape(info.relative[0]) . '|' . undo) call add(restore, ':Gsplit ' . s:fnameescape(info.relative[0]) . '|' . undo)
@@ -4093,7 +4093,7 @@ function! s:DoStageUnpushedHeading(heading) abort
let remote = '.' let remote = '.'
endif endif
let branch = matchstr(a:heading, 'to \%([^/]\+/\)\=\zs\S\+') let branch = matchstr(a:heading, 'to \%([^/]\+/\)\=\zs\S\+')
call feedkeys(':Git push ' . remote . ' ' . 'HEAD:' . 'refs/heads/' . branch) call feedkeys(':Git push ' . remote . ' ' . '@:' . 'refs/heads/' . branch)
endfunction endfunction
function! s:DoToggleUnpushedHeading(heading) abort function! s:DoToggleUnpushedHeading(heading) abort
@@ -4829,7 +4829,7 @@ function! fugitive#LogCommand(line1, count, range, bang, mods, args, type) abort
if len(path) && empty(filter(copy(args), 'v:val =~# "^[^-]"')) if len(path) && empty(filter(copy(args), 'v:val =~# "^[^-]"'))
let owner = s:Owner(@%, dir) let owner = s:Owner(@%, dir)
if len(owner) if len(owner)
call add(args, owner) call add(args, owner . (owner =~# '^\x\{40,}' ? '' : '^{}'))
endif endif
endif endif
if empty(extra_paths) if empty(extra_paths)
@@ -5366,7 +5366,7 @@ function! fugitive#Diffsplit(autodir, keepfocus, mods, arg, args) abort
elseif empty(commit) elseif empty(commit)
let parents = [s:Relative(':0:')] let parents = [s:Relative(':0:')]
elseif commit =~# '^\d\=$' elseif commit =~# '^\d\=$'
let parents = [s:Relative('HEAD:')] let parents = [s:Relative('@:')]
elseif commit =~# '^\x\x\+$' elseif commit =~# '^\x\x\+$'
let parents = s:LinesError(['rev-parse', commit . '^@'])[0] let parents = s:LinesError(['rev-parse', commit . '^@'])[0]
call map(parents, 's:Relative(v:val . ":")') call map(parents, 's:Relative(v:val . ":")')
@@ -5923,7 +5923,7 @@ function! s:BlameJump(suffix, ...) abort
return 'echoerr ' . string('fugitive: could not determine filename for blame') return 'echoerr ' . string('fugitive: could not determine filename for blame')
endif endif
if commit =~# '^0*$' if commit =~# '^0*$'
let commit = 'HEAD' let commit = '@'
let suffix = '' let suffix = ''
endif endif
let offset = line('.') - line('w0') let offset = line('.') - line('w0')
@@ -6263,7 +6263,7 @@ function! fugitive#BrowseCommand(line1, count, range, bang, mods, arg, args) abo
let commit = '' let commit = ''
if len(merge) if len(merge)
let owner = s:Owner(@%, dir) let owner = s:Owner(@%, dir)
let [commit, exec_error] = s:ChompError(['merge-base', 'refs/remotes/' . remote . '/' . merge, empty(owner) ? 'HEAD' : owner, '--'], dir) let [commit, exec_error] = s:ChompError(['merge-base', 'refs/remotes/' . remote . '/' . merge, empty(owner) ? '@' : owner, '--'], dir)
if exec_error if exec_error
let commit = '' let commit = ''
endif endif
@@ -6357,7 +6357,7 @@ endfunction
function! s:ContainingCommit() abort function! s:ContainingCommit() abort
let commit = s:Owner(@%) let commit = s:Owner(@%)
return empty(commit) ? 'HEAD' : commit return empty(commit) ? '@' : commit
endfunction endfunction
function! s:SquashArgument(...) abort function! s:SquashArgument(...) abort
@@ -6384,7 +6384,7 @@ function! s:NavigateUp(count) abort
elseif rev =~# '.:.' elseif rev =~# '.:.'
let rev = matchstr(rev, '^.[^:]*:') let rev = matchstr(rev, '^.[^:]*:')
elseif rev =~# '^:' elseif rev =~# '^:'
let rev = 'HEAD^{}' let rev = '@^{}'
elseif rev =~# ':$' elseif rev =~# ':$'
let rev = rev[0:-2] let rev = rev[0:-2]
else else
@@ -6762,9 +6762,9 @@ function! s:cfile() abort
let prefixes.a = myhash.'^:' let prefixes.a = myhash.'^:'
let prefixes.b = myhash.':' let prefixes.b = myhash.':'
endif endif
let ref = substitute(ref, '^\(\w\)/', '\=get(prefixes, submatch(1), "HEAD:")', '') let ref = substitute(ref, '^\(\w\)/', '\=get(prefixes, submatch(1), "@:")', '')
if exists('dref') if exists('dref')
let dref = substitute(dref, '^\(\w\)/', '\=get(prefixes, submatch(1), "HEAD:")', '') let dref = substitute(dref, '^\(\w\)/', '\=get(prefixes, submatch(1), "@:")', '')
endif endif
if ref ==# '/dev/null' if ref ==# '/dev/null'