1 " fugitive.vim - A Git wrapper so awesome, it should be illegal
2 " Maintainer: Tim Pope <http://tpo.pe/>
4 " GetLatestVimScripts: 2975 1 :AutoInstall: fugitive.vim
6 if exists('g:loaded_fugitive')
9 let g:loaded_fugitive = 1
11 let s:bad_git_dir = '/$\|^fugitive:'
13 " FugitiveGitDir() returns the detected Git dir for the given buffer number,
14 " or the current buffer if no argument is passed. This will be an empty
15 " string if no Git dir was found. Use !empty(FugitiveGitDir()) to check if
16 " Fugitive is active in the current buffer. Do not rely on this for direct
17 " filesystem access; use FugitiveFind('.git/whatever') instead.
18 function! FugitiveGitDir(...) abort
21 elseif !a:0 || type(a:1) == type(0) && a:1 < 0 || a:1 is# get(v:, 'true', -1)
22 if exists('g:fugitive_event')
23 return g:fugitive_event
25 let dir = get(b:, 'git_dir', '')
26 if empty(dir) && (empty(bufname('')) || &buftype =~# '^\%(nofile\|acwrite\|quickfix\|terminal\|prompt\)$')
27 return FugitiveExtractGitDir(getcwd())
28 elseif (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && &buftype =~# '^\%(nowrite\)\=$'
29 let b:git_dir = FugitiveExtractGitDir(bufnr(''))
32 return dir =~# s:bad_git_dir ? '' : dir
33 elseif type(a:1) == type(0) && a:1 isnot# 0
34 if a:1 == bufnr('') && (!exists('b:git_dir') || b:git_dir =~# s:bad_git_dir) && &buftype =~# '^\%(nowrite\)\=$'
35 let b:git_dir = FugitiveExtractGitDir(a:1)
37 let dir = getbufvar(a:1, 'git_dir')
38 return dir =~# s:bad_git_dir ? '' : dir
39 elseif type(a:1) == type('')
40 return substitute(s:Slash(a:1), '/$', '', '')
41 elseif type(a:1) == type({})
42 return get(a:1, 'git_dir', '')
48 " FugitiveReal() takes a fugitive:// URL and returns the corresponding path in
49 " the work tree. This may be useful to get a cleaner path for inclusion in
50 " the statusline, for example. Note that the file and its parent directories
51 " are not guaranteed to exist.
53 " This is intended as an abstract API to be used on any "virtual" path. For a
54 " buffer named foo://bar, check for a function named FooReal(), and if it
55 " exists, call FooReal("foo://bar").
56 function! FugitiveReal(...) abort
57 let file = a:0 ? a:1 : @%
58 if type(file) ==# type({})
59 let dir = FugitiveGitDir(file)
60 let tree = s:Tree(dir)
61 return s:VimSlash(empty(tree) ? dir : tree)
62 elseif file =~# '^\a\a\+:' || a:0 > 1
63 return call('fugitive#Real', [file] + a:000[1:-1])
64 elseif file =~# '^/\|^\a:\|^$'
67 return fnamemodify(file, ':p' . (file =~# '[\/]$' ? '' : ':s?[\/]$??'))
71 " FugitiveFind() takes a Fugitive object and returns the appropriate Vim
72 " buffer name. You can use this to generate Fugitive URLs ("HEAD:README") or
73 " to get the absolute path to a file in the Git dir (".git/HEAD"), the common
74 " dir (".git/config"), or the work tree (":(top)Makefile").
76 " An optional second argument provides the Git dir, or the buffer number of a
77 " buffer with a Git dir. The default is the current buffer.
78 function! FugitiveFind(...) abort
79 if a:0 && (type(a:1) ==# type({}) || type(a:1) ==# type(0))
80 return call('fugitive#Find', a:000[1:-1] + [FugitiveGitDir(a:1)])
82 return fugitive#Find(a:0 ? a:1 : bufnr(''), FugitiveGitDir(a:0 > 1 ? a:2 : -1))
86 " FugitiveParse() takes a fugitive:// URL and returns a 2 element list
87 " containing an object name ("commit:file") and the Git dir. It's effectively
88 " the inverse of FugitiveFind().
89 function! FugitiveParse(...) abort
90 let path = s:Slash(a:0 ? a:1 : @%)
91 if path !~# '^fugitive://'
94 let vals = matchlist(path, s:dir_commit_file)
96 return [(vals[2] =~# '^.\=$' ? ':' : '') . vals[2] . substitute(vals[3], '^/', ':', ''), vals[1]]
98 let v:errmsg = 'fugitive: invalid Fugitive URL ' . path
102 " FugitiveGitVersion() queries the version of Git in use. Pass up to 3
103 " arguments to return a Boolean of whether a certain minimum version is
104 " available (FugitiveGitVersion(2,3,4) checks for 2.3.4 or higher) or no
105 " arguments to get a raw string.
106 function! FugitiveGitVersion(...) abort
107 return call('fugitive#GitVersion', a:000)
110 " FugitiveResult() returns an object encapsulating the result of the most
111 " recent :Git command. Will be empty if no result is available. During a
112 " User FugitiveChanged event, this is guaranteed to correspond to the :Git
113 " command that triggered the event, or be empty if :Git was not the trigger.
114 " Pass in the name of a temp buffer to get the result object for that command
115 " instead. Contains the following keys:
117 " * "args": List of command arguments, starting with the subcommand. Will be
118 " empty for usages like :Git --help.
119 " * "git_dir": Git dir of the relevant repository.
120 " * "exit_status": The integer exit code of the process.
121 " * "flags": Flags passed directly to Git, like -c and --help.
122 " * "file": Path to file containing command output. Not guaranteed to exist,
123 " so verify with filereadable() before trying to access it.
124 function! FugitiveResult(...) abort
125 return call('fugitive#Result', a:000)
128 " FugitiveExecute() runs Git with a list of arguments and returns a dictionary
129 " with the following keys:
131 " * "exit_status": The integer exit code of the process.
132 " * "stdout": The stdout produced by the process, as a list of lines.
133 " * "stderr": The stdout produced by the process, as a list of lines.
135 " An optional second argument provides the Git dir, or the buffer number of a
136 " buffer with a Git dir. The default is the current buffer.
138 " An optional final argument is a callback Funcref, for asynchronous
140 function! FugitiveExecute(args, ...) abort
141 return call('fugitive#Execute', [a:args] + a:000)
144 " FugitiveShellCommand() turns an array of arugments into a Git command string
145 " which can be executed with functions like system() and commands like :!.
146 " Integer arguments will be treated as buffer numbers, and the appropriate
147 " relative path inserted in their place.
149 " An optional second argument provides the Git dir, or the buffer number of a
150 " buffer with a Git dir. The default is the current buffer.
151 function! FugitiveShellCommand(...) abort
152 return call('fugitive#ShellCommand', a:000)
155 " FugitivePrepare() is a deprecated alias for FugitiveShellCommand(). If you
156 " are using this in conjunction with system(), consider using
157 " FugitiveExecute() instead.
158 function! FugitivePrepare(...) abort
159 if !exists('s:did_prepare_warning')
160 let s:did_prepare_warning = 1
162 unsilent echomsg 'FugitivePrepare() has been superseded by FugitiveShellCommand()'
165 return call('fugitive#ShellCommand', a:000)
168 " FugitiveConfig() get returns an opaque structure that can be passed to other
169 " FugitiveConfig functions in lieu of a Git directory. This can be faster
170 " when performing multiple config queries. Do not rely on the internal
171 " structure of the return value as it is not guaranteed. If you want a full
172 " dictionary of every config value, use FugitiveConfigGetRegexp('.*').
174 " An optional argument provides the Git dir, or the buffer number of a
175 " buffer with a Git dir. The default is the current buffer. Pass a blank
176 " string to limit to the global config.
177 function! FugitiveConfig(...) abort
178 return call('fugitive#Config', a:000)
181 " FugitiveConfigGet() retrieves a Git configuration value. An optional second
182 " argument can be either the object returned by FugitiveConfig(), or a Git
183 " dir or buffer number to be passed along to FugitiveConfig().
184 function! FugitiveConfigGet(name, ...) abort
185 return get(call('FugitiveConfigGetAll', [a:name] + (a:0 ? [a:1] : [])), 0, get(a:, 2, ''))
188 " FugitiveConfigGetAll() is like FugitiveConfigGet() but returns a list of
190 function! FugitiveConfigGetAll(name, ...) abort
191 return call('fugitive#ConfigGetAll', [a:name] + a:000)
194 " FugitiveConfigGetRegexp() retrieves a dictionary of all configuration values
195 " with a key matching the given pattern. Like git config --get-regexp, but
196 " using a Vim regexp. Second argument has same semantics as
197 " FugitiveConfigGet().
198 function! FugitiveConfigGetRegexp(pattern, ...) abort
199 return call('fugitive#ConfigGetRegexp', [a:pattern] + a:000)
202 " FugitiveRemoteUrl() retrieves the remote URL for the given remote name,
203 " defaulting to the current branch's remote or "origin" if no argument is
204 " given. Similar to `git remote get-url`, but also attempts to resolve HTTP
205 " redirects and SSH host aliases.
207 " An optional second argument provides the Git dir, or the buffer number of a
208 " buffer with a Git dir. The default is the current buffer.
209 function! FugitiveRemoteUrl(...) abort
210 return call('fugitive#RemoteUrl', a:000)
213 " FugitiveRemote() returns a data structure parsed from the remote URL.
214 " For example, for remote URL "https://me@example.com:1234/repo.git", the
215 " returned dictionary will contain the following:
217 " * "scheme": "https"
218 " * "authority": "user@example.com:1234"
219 " * "path": "/repo.git" (for SSH URLs this may be a relative path)
220 " * "pathname": "/repo.git" (always coerced to absolute path)
221 " * "host": "example.com:1234"
222 " * "hostname": "example.com"
225 " * "path": "/repo.git"
226 " * "url": "https://me@example.com:1234/repo.git"
227 function! FugitiveRemote(...) abort
228 return call('fugitive#Remote', a:000)
231 " FugitiveDidChange() triggers a FugitiveChanged event and reloads the summary
232 " buffer for the current or given buffer number's repository. You can also
233 " give the result of a FugitiveExecute() and that context will be made
234 " available inside the FugitiveChanged() event.
236 " Passing the special argument 0 (the number zero) softly expires summary
237 " buffers for all repositories. This can be used after a call to system()
238 " with unclear implications.
239 function! FugitiveDidChange(...) abort
240 return call('fugitive#DidChange', a:000)
243 " FugitiveHead() retrieves the name of the current branch. If the current HEAD
244 " is detached, FugitiveHead() will return the empty string, unless the
245 " optional argument is given, in which case the hash of the current commit
246 " will be truncated to the given number of characters.
248 " An optional second argument provides the Git dir, or the buffer number of a
249 " buffer with a Git dir. The default is the current buffer.
250 function! FugitiveHead(...) abort
251 if a:0 && (type(a:1) ==# type({}) || type(a:1) ==# type('') && a:1 !~# '^\d\+$')
252 let dir = FugitiveGitDir(a:1)
253 let arg = get(a:, 2, 0)
255 let dir = FugitiveGitDir(a:2)
258 let dir = FugitiveGitDir()
259 let arg = get(a:, 1, 0)
264 return fugitive#Head(arg, dir)
267 function! FugitivePath(...) abort
268 if a:0 > 2 && type(a:1) ==# type({})
269 return fugitive#Path(a:2, a:3, FugitiveGitDir(a:1))
270 elseif a:0 && type(a:1) ==# type({})
271 return FugitiveReal(a:0 > 1 ? a:2 : @%)
273 return fugitive#Path(a:1, a:2, FugitiveGitDir(a:0 > 2 ? a:3 : -1))
275 return FugitiveReal(a:0 ? a:1 : @%)
279 function! FugitiveStatusline(...) abort
280 if empty(FugitiveGitDir(bufnr('')))
283 return fugitive#Statusline()
286 function! FugitiveActualDir(...) abort
287 return call('FugitiveGitDir', a:000)
290 let s:commondirs = {}
291 function! FugitiveCommonDir(...) abort
292 let dir = call('FugitiveActualDir', a:000)
296 if has_key(s:commondirs, dir)
297 return s:commondirs[dir]
299 if getfsize(dir . '/HEAD') >= 10
300 let cdir = get(s:ReadFile(dir . '/commondir', 1), 0, '')
301 if cdir =~# '^/\|^\a:/'
302 let s:commondirs[dir] = s:Slash(FugitiveVimPath(cdir))
304 let s:commondirs[dir] = simplify(dir . '/' . cdir)
306 let s:commondirs[dir] = dir
309 let s:commondirs[dir] = dir
311 return s:commondirs[dir]
314 function! FugitiveWorkTree(...) abort
315 let tree = s:Tree(FugitiveGitDir(a:0 ? a:1 : -1))
316 if tree isnot# 0 || a:0 > 1
323 function! FugitiveIsGitDir(...) abort
324 if !a:0 || type(a:1) !=# type('')
325 return !empty(call('FugitiveGitDir', a:000))
327 let path = substitute(a:1, '[\/]$', '', '') . '/'
328 return len(path) && getfsize(path.'HEAD') > 10 && (
329 \ isdirectory(path.'objects') && isdirectory(path.'refs') ||
330 \ getftype(path.'commondir') ==# 'file')
333 function! s:ReadFile(path, line_count) abort
334 if v:version < 800 && !filereadable(a:path)
338 return readfile(a:path, 'b', a:line_count)
344 let s:worktree_for_dir = {}
345 let s:dir_for_worktree = {}
346 function! s:Tree(path) abort
349 return len(dir) ==# 5 ? '/' : dir[0:-6]
353 if !has_key(s:worktree_for_dir, dir)
354 let s:worktree_for_dir[dir] = ''
355 let ext_wtc_pat = 'v:val =~# "^\\s*worktreeConfig *= *\\%(true\\|yes\\|on\\|1\\) *$"'
356 let config = s:ReadFile(dir . '/config', 50)
358 let ext_wtc_config = filter(copy(config), ext_wtc_pat)
359 if len(ext_wtc_config) == 1 && filereadable(dir . '/config.worktree')
360 let config += s:ReadFile(dir . '/config.worktree', 50)
363 let worktree = fnamemodify(FugitiveVimPath(get(s:ReadFile(dir . '/gitdir', 1), '0', '')), ':h')
367 if len(filter(s:ReadFile(FugitiveCommonDir(dir) . '/config', 50), ext_wtc_pat))
368 let config = s:ReadFile(dir . '/config.worktree', 50)
372 let wt_config = filter(copy(config), 'v:val =~# "^\\s*worktree *="')
374 let worktree = FugitiveVimPath(matchstr(wt_config[0], '= *\zs.*'))
375 elseif !exists('worktree')
376 call filter(config,'v:val =~# "^\\s*bare *= *true *$"')
378 let s:worktree_for_dir[dir] = 0
382 if exists('worktree')
383 let s:worktree_for_dir[dir] = s:Slash(resolve(worktree))
384 let s:dir_for_worktree[s:worktree_for_dir[dir]] = dir
387 if s:worktree_for_dir[dir] =~# '^\.'
388 return simplify(dir . '/' . s:worktree_for_dir[dir])
390 return s:worktree_for_dir[dir]
394 function! s:CeilingDirectories() abort
395 if !exists('s:ceiling_directories')
396 let s:ceiling_directories = []
398 for dir in split($GIT_CEILING_DIRECTORIES, has('win32') ? ';' : ':', 1)
402 call add(s:ceiling_directories, s:Slash(resolve(dir)))
404 call add(s:ceiling_directories, s:Slash(dir))
408 return s:ceiling_directories + get(g:, 'ceiling_directories', [s:Slash(fnamemodify(expand('~'), ':h'))])
411 function! FugitiveExtractGitDir(path) abort
412 if type(a:path) ==# type({})
413 return get(a:path, 'git_dir', '')
414 elseif type(a:path) == type(0)
415 let path = s:Slash(a:path > 0 ? bufname(a:path) : bufname(''))
417 let path = s:Slash(a:path)
419 if path =~# '^fugitive://'
420 return get(matchlist(path, s:dir_commit_file), 1, '')
424 let pre = substitute(matchstr(path, '^\a\a\+\ze:'), '^.', '\u&', '')
425 if len(pre) && exists('*' . pre . 'Real')
426 let path = {pre}Real(path)
428 let root = s:Slash(fnamemodify(path, ':p:h'))
430 let env_git_dir = len($GIT_DIR) ? s:Slash(simplify(fnamemodify(FugitiveVimPath($GIT_DIR), ':p:s?[\/]$??'))) : ''
431 call s:Tree(env_git_dir)
432 let ceiling_directories = s:CeilingDirectories()
433 while root !=# previous && root !~# '^$\|^//[^/]*$'
434 if index(ceiling_directories, root) >= 0
437 if root ==# $GIT_WORK_TREE && FugitiveIsGitDir(env_git_dir)
439 elseif has_key(s:dir_for_worktree, root)
440 return s:dir_for_worktree[root]
442 let dir = substitute(root, '[\/]$', '', '') . '/.git'
443 let type = getftype(dir)
444 if type ==# 'dir' && FugitiveIsGitDir(dir)
446 elseif type ==# 'link' && FugitiveIsGitDir(dir)
449 let line = get(s:ReadFile(dir, 1), 0, '')
450 let file_dir = s:Slash(FugitiveVimPath(matchstr(line, '^gitdir: \zs.*')))
451 if file_dir !~# '^/\|^\a:\|^$' && FugitiveIsGitDir(root . '/' . file_dir)
452 return simplify(root . '/' . file_dir)
453 elseif len(file_dir) && FugitiveIsGitDir(file_dir)
456 elseif FugitiveIsGitDir(root)
460 let root = fnamemodify(root, ':h')
465 function! FugitiveDetect(...) abort
469 if exists('b:git_dir') && b:git_dir =~# '^$\|' . s:bad_git_dir
472 if a:0 > 1 && a:2 is# 0 && !exists('#User#Fugitive')
475 if !exists('b:git_dir')
476 let b:git_dir = FugitiveExtractGitDir(a:0 ? a:1 : bufnr(''))
478 if empty(b:git_dir) || !exists('#User#Fugitive')
481 if v:version >= 704 || (v:version == 703 && has('patch442'))
482 doautocmd <nomodeline> User Fugitive
483 elseif &modelines > 0
484 let modelines = &modelines
487 doautocmd User Fugitive
489 let &modelines = modelines
492 doautocmd User Fugitive
497 function! FugitiveGitPath(path) abort
498 return s:Slash(a:path)
501 if exists('+shellslash')
503 let s:dir_commit_file = '\c^fugitive://\%(/\a\@=\)\=\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$'
505 function! s:Slash(path) abort
506 return tr(a:path, '\', '/')
509 function! s:VimSlash(path) abort
510 return tr(a:path, '\/', &shellslash ? '//' : '\\')
513 function FugitiveVimPath(path) abort
514 return tr(a:path, '\/', &shellslash ? '//' : '\\')
519 let s:dir_commit_file = '\c^fugitive://\(.\{-\}\)//\%(\(\x\{40,\}\|[0-3]\)\(/.*\)\=\)\=$'
521 function! s:Slash(path) abort
525 function! s:VimSlash(path) abort
529 if has('win32unix') && filereadable('/git-bash.exe')
530 function! FugitiveVimPath(path) abort
531 return substitute(a:path, '^\(\a\):', '/\l\1', '')
534 function! FugitiveVimPath(path) abort
541 function! s:ProjectionistDetect() abort
542 let file = s:Slash(get(g:, 'projectionist_file', ''))
543 let dir = FugitiveExtractGitDir(file)
544 let base = get(matchlist(file, s:dir_commit_file), 1, '')
546 let base = s:Tree(dir)
549 if exists('+shellslash') && !&shellslash
550 let base = tr(base, '/', '\')
552 let file = FugitiveFind('.git/info/projections.json', dir)
553 if filereadable(file)
554 call projectionist#append(base, file)
559 let s:addr_other = has('patch-8.1.560') || has('nvim-0.5.0') ? '-addr=other' : ''
560 let s:addr_tabs = has('patch-7.4.542') ? '-addr=tabs' : ''
561 let s:addr_wins = has('patch-7.4.542') ? '-addr=windows' : ''
564 command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#Complete G exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)
566 command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#Complete Git exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)
568 if exists(':Gstatus') != 2 && get(g:, 'fugitive_legacy_commands', 0)
569 exe 'command! -bang -bar -range=-1' s:addr_other 'Gstatus exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
570 \ '|echohl WarningMSG|echomsg ":Gstatus is deprecated in favor of :Git (with no arguments)"|echohl NONE'
571 elseif exists(':Gstatus') != 2 && !exists('g:fugitive_legacy_commands')
572 exe 'command! -bang -bar -range=-1' s:addr_other 'Gstatus'
573 \ ' echoerr ":Gstatus has been removed in favor of :Git (with no arguments)"'
576 for s:cmd in ['Commit', 'Revert', 'Merge', 'Rebase', 'Pull', 'Push', 'Fetch', 'Blame']
577 if exists(':G' . tolower(s:cmd)) != 2 && get(g:, 'fugitive_legacy_commands', 0)
578 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#' . s:cmd . 'Complete G' . tolower(s:cmd)
579 \ 'echohl WarningMSG|echomsg ":G' . tolower(s:cmd) . ' is deprecated in favor of :Git ' . tolower(s:cmd) . '"|echohl NONE|'
580 \ 'exe fugitive#Command(<line1>, <count>, +"<range>", <bang>0, "<mods>", "' . tolower(s:cmd) . ' " . <q-args>)'
581 elseif exists(':G' . tolower(s:cmd)) != 2 && !exists('g:fugitive_legacy_commands')
582 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#' . s:cmd . 'Complete G' . tolower(s:cmd)
583 \ 'echoerr ":G' . tolower(s:cmd) . ' has been removed in favor of :Git ' . tolower(s:cmd) . '"'
588 exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Gcd exe fugitive#Cd(<q-args>, 0)"
589 exe "command! -bar -bang -nargs=? -complete=customlist,fugitive#CdComplete Glcd exe fugitive#Cd(<q-args>, 1)"
591 exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Ggrep exe fugitive#GrepCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
592 exe 'command! -bang -nargs=? -range=-1' s:addr_wins '-complete=customlist,fugitive#GrepComplete Glgrep exe fugitive#GrepCommand(0, <count> > 0 ? <count> : 0, +"<range>", <bang>0, "<mods>", <q-args>)'
594 if exists(':Glog') != 2 && get(g:, 'fugitive_legacy_commands', 0)
595 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Glog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "")'
596 \ '|echohl WarningMSG|echomsg ":Glog is deprecated in favor of :Gclog"|echohl NONE'
597 elseif exists(':Glog') != 2 && !exists('g:fugitive_legacy_commands')
598 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Glog'
599 \ ' echoerr ":Glog has been removed in favor of :Gclog"'
601 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Gclog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "c")'
602 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete GcLog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "c")'
603 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete Gllog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "l")'
604 exe 'command! -bang -nargs=? -range=-1 -complete=customlist,fugitive#LogComplete GlLog :exe fugitive#LogCommand(<line1>,<count>,+"<range>",<bang>0,"<mods>",<q-args>, "l")'
606 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Ge exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>)'
607 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gedit exe fugitive#Open("edit<bang>", 0, "<mods>", <q-args>)'
608 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#ReadComplete Gpedit exe fugitive#Open("pedit", <bang>0, "<mods>", <q-args>)'
609 exe 'command! -bar -bang -nargs=* -range=-1' s:addr_other '-complete=customlist,fugitive#ReadComplete Gsplit exe fugitive#Open((<count> > 0 ? <count> : "").(<count> ? "split" : "edit"), <bang>0, "<mods>", <q-args>)'
610 exe 'command! -bar -bang -nargs=* -range=-1' s:addr_other '-complete=customlist,fugitive#ReadComplete Gvsplit exe fugitive#Open((<count> > 0 ? <count> : "").(<count> ? "vsplit" : "edit!"), <bang>0, "<mods>", <q-args>)'
611 exe 'command! -bar -bang -nargs=* -range=-1' s:addr_tabs '-complete=customlist,fugitive#ReadComplete Gtabedit exe fugitive#Open((<count> >= 0 ? <count> : "")."tabedit", <bang>0, "<mods>", <q-args>)'
613 if exists(':Gr') != 2
614 exe 'command! -bar -bang -nargs=* -range=-1 -complete=customlist,fugitive#ReadComplete Gr exe fugitive#ReadCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
616 exe 'command! -bar -bang -nargs=* -range=-1 -complete=customlist,fugitive#ReadComplete Gread exe fugitive#ReadCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
618 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gdiffsplit exe fugitive#Diffsplit(1, <bang>0, "<mods>", <q-args>)'
619 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Ghdiffsplit exe fugitive#Diffsplit(0, <bang>0, "<mods>", <q-args>)'
620 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gvdiffsplit exe fugitive#Diffsplit(0, <bang>0, "vertical <mods>", <q-args>)'
622 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gw exe fugitive#WriteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
623 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gwrite exe fugitive#WriteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
624 exe 'command! -bar -bang -nargs=* -complete=customlist,fugitive#EditComplete Gwq exe fugitive#WqCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
626 exe 'command! -bar -bang -nargs=0 GRemove exe fugitive#RemoveCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
627 exe 'command! -bar -bang -nargs=0 GUnlink exe fugitive#UnlinkCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
628 exe 'command! -bar -bang -nargs=0 GDelete exe fugitive#DeleteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
629 exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#CompleteObject GMove exe fugitive#MoveCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
630 exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#RenameComplete GRename exe fugitive#RenameCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
631 if exists(':Gremove') != 2 && get(g:, 'fugitive_legacy_commands', 0)
632 exe 'command! -bar -bang -nargs=0 Gremove exe fugitive#RemoveCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
633 \ '|echohl WarningMSG|echomsg ":Gremove is deprecated in favor of :GRemove"|echohl NONE'
634 elseif exists(':Gremove') != 2 && !exists('g:fugitive_legacy_commands')
635 exe 'command! -bar -bang -nargs=0 Gremove echoerr ":Gremove has been removed in favor of :GRemove"'
637 if exists(':Gdelete') != 2 && get(g:, 'fugitive_legacy_commands', 0)
638 exe 'command! -bar -bang -nargs=0 Gdelete exe fugitive#DeleteCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
639 \ '|echohl WarningMSG|echomsg ":Gdelete is deprecated in favor of :GDelete"|echohl NONE'
640 elseif exists(':Gdelete') != 2 && !exists('g:fugitive_legacy_commands')
641 exe 'command! -bar -bang -nargs=0 Gdelete echoerr ":Gremove has been removed in favor of :GRemove"'
643 if exists(':Gmove') != 2 && get(g:, 'fugitive_legacy_commands', 0)
644 exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#CompleteObject Gmove exe fugitive#MoveCommand( <line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
645 \ '|echohl WarningMSG|echomsg ":Gmove is deprecated in favor of :GMove"|echohl NONE'
646 elseif exists(':Gmove') != 2 && !exists('g:fugitive_legacy_commands')
647 exe 'command! -bar -bang -nargs=? -complete=customlist,fugitive#CompleteObject Gmove'
648 \ 'echoerr ":Gmove has been removed in favor of :GMove"'
650 if exists(':Grename') != 2 && get(g:, 'fugitive_legacy_commands', 0)
651 exe 'command! -bar -bang -nargs=1 -complete=customlist,fugitive#RenameComplete Grename exe fugitive#RenameCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
652 \ '|echohl WarningMSG|echomsg ":Grename is deprecated in favor of :GRename"|echohl NONE'
653 elseif exists(':Grename') != 2 && !exists('g:fugitive_legacy_commands')
654 exe 'command! -bar -bang -nargs=? -complete=customlist,fugitive#RenameComplete Grename'
655 \ 'echoerr ":Grename has been removed in favor of :GRename"'
658 exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject GBrowse exe fugitive#BrowseCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
659 if exists(':Gbrowse') != 2 && get(g:, 'fugitive_legacy_commands', 0)
660 exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject Gbrowse exe fugitive#BrowseCommand(<line1>, <count>, +"<range>", <bang>0, "<mods>", <q-args>)'
661 \ '|if <bang>1|redraw!|endif|echohl WarningMSG|echomsg ":Gbrowse is deprecated in favor of :GBrowse"|echohl NONE'
662 elseif exists(':Gbrowse') != 2 && !exists('g:fugitive_legacy_commands')
663 exe 'command! -bar -bang -range=-1 -nargs=* -complete=customlist,fugitive#CompleteObject Gbrowse'
664 \ 'echoerr ":Gbrowse has been removed in favor of :GBrowse"'
671 let g:io_fugitive = {
672 \ 'simplify': function('fugitive#simplify'),
673 \ 'resolve': function('fugitive#resolve'),
674 \ 'getftime': function('fugitive#getftime'),
675 \ 'getfsize': function('fugitive#getfsize'),
676 \ 'getftype': function('fugitive#getftype'),
677 \ 'filereadable': function('fugitive#filereadable'),
678 \ 'filewritable': function('fugitive#filewritable'),
679 \ 'isdirectory': function('fugitive#isdirectory'),
680 \ 'getfperm': function('fugitive#getfperm'),
681 \ 'setfperm': function('fugitive#setfperm'),
682 \ 'readfile': function('fugitive#readfile'),
683 \ 'writefile': function('fugitive#writefile'),
684 \ 'glob': function('fugitive#glob'),
685 \ 'delete': function('fugitive#delete'),
686 \ 'Real': function('FugitiveReal')}
691 autocmd BufNewFile,BufReadPost * call FugitiveDetect(+expand('<abuf>'), 0)
692 autocmd FileType netrw call FugitiveDetect(+expand('<abuf>'), 0)
693 autocmd BufFilePost * unlet! b:git_dir
696 \ call fugitive#MapCfile()
697 autocmd FileType gitcommit
698 \ call fugitive#MapCfile('fugitive#MessageCfile()')
699 autocmd FileType git,gitcommit
700 \ if &foldtext ==# 'foldtext()' |
701 \ setlocal foldtext=fugitive#Foldtext() |
703 autocmd FileType fugitive
704 \ call fugitive#MapCfile('fugitive#PorcelainCfile()')
705 autocmd FileType gitrebase
706 \ let &l:include = '^\%(pick\|squash\|edit\|reword\|fixup\|drop\|[pserfd]\)\>' |
707 \ if &l:includeexpr !~# 'Fugitive' |
708 \ let &l:includeexpr = 'v:fname =~# ''^\x\{4,\}$'' && len(FugitiveGitDir()) ? FugitiveFind(v:fname) : ' .
709 \ (len(&l:includeexpr) ? &l:includeexpr : 'v:fname') |
711 \ let b:undo_ftplugin = get(b:, 'undo_ftplugin', 'exe') . '|setl inex= inc='
713 autocmd BufReadCmd index{,.lock} nested
714 \ if FugitiveIsGitDir(expand('<amatch>:p:h')) |
715 \ let b:git_dir = s:Slash(expand('<amatch>:p:h')) |
716 \ exe fugitive#BufReadStatus(v:cmdbang) |
717 \ elseif filereadable(expand('<amatch>')) |
718 \ silent doautocmd BufReadPre |
719 \ keepalt noautocmd read <amatch> |
721 \ silent doautocmd BufReadPost |
723 \ silent doautocmd BufNewFile |
726 autocmd BufReadCmd fugitive://*//* nested exe fugitive#BufReadCmd() |
727 \ if &path =~# '^\.\%(,\|$\)' |
728 \ let &l:path = substitute(&path, '^\.,\=', '', '') |
730 autocmd BufWriteCmd fugitive://*//[0-3]/* nested exe fugitive#BufWriteCmd()
731 autocmd FileReadCmd fugitive://*//* nested exe fugitive#FileReadCmd()
732 autocmd FileWriteCmd fugitive://*//[0-3]/* nested exe fugitive#FileWriteCmd()
733 if exists('##SourceCmd')
734 autocmd SourceCmd fugitive://*//* nested exe fugitive#SourceCmd()
737 autocmd User Flags call Hoist('buffer', function('FugitiveStatusline'))
739 autocmd User ProjectionistDetect call s:ProjectionistDetect()
742 if get(g:, 'fugitive_no_maps')
746 let s:nowait = v:version >= 704 ? '<nowait>' : ''
748 function! s:Map(mode, lhs, rhs, flags) abort
749 let flags = a:flags . (a:rhs =~# '<Plug>' ? '' : '<script>')
752 let keys = get(g:, a:mode.'remap', {})
753 if len(keys) && type(keys) == type({})
755 if has_key(keys, head)
756 let head = keys[head]
762 let tail = matchstr(head, '<[^<>]*>$\|.$') . tail
763 let head = substitute(head, '<[^<>]*>$\|.$', '', '')
766 if empty(mapcheck(head.tail, a:mode))
767 exe a:mode.'map' s:nowait flags head.tail a:rhs
771 call s:Map('c', '<C-R><C-G>', 'fnameescape(fugitive#Object(@%))', '<expr>')
772 call s:Map('n', 'y<C-G>', ':<C-U>call setreg(v:register, fugitive#Object(@%))<CR>', '<silent>')
773 nmap <script><silent> <Plug>fugitive:y<C-G> :<C-U>call setreg(v:register, fugitive#Object(@%))<CR>
774 nmap <script> <Plug>fugitive: <Nop>