@@ -20,11 +20,33 @@ function! easygit#gitdir(path, ...) abort
20
20
endfunction
21
21
22
22
function ! s: FindGitdir (path )
23
- let dir = finddir (' .git' , expand (a: path ).' ;' )
24
- if empty (dir ) | return ' ' | endif
25
- return fnamemodify (dir , ' :p:h' )
23
+ if ! empty ($GIT_DIR ) | return $GIT_DIR | endif
24
+ if get (g: , ' easygit_enable_root_rev_parse' , 1 )
25
+ let old_cwd = getcwd ()
26
+ let cwd = fnamemodify (a: path , ' :p:h' )
27
+ execute ' lcd ' .cwd
28
+ let root = system (' git rev-parse --show-toplevel' )
29
+ execute ' lcd ' .old_cwd
30
+ if v: shell_error | return ' ' | endif
31
+ return substitute (root, ' \r\?\n' , ' ' , ' ' ) . ' /.git'
32
+ else
33
+ let dir = finddir (' .git' , expand (a: path ).' ;' )
34
+ if dir | return fnamemodify (dir , ' :p:h' ) | endif
35
+ return ' '
36
+ endif
37
+ endfunction
38
+
39
+ " If cwd inside current file git root, return cwd, otherwise return git root
40
+ function ! easygit#smartRoot (... )
41
+ let suspend = a: 0 ? a: 1 : 0
42
+ let gitdir = easygit#gitdir (expand (' %' ), suspend )
43
+ if empty (gitdir) | return ' ' | endif
44
+ let root = fnamemodify (gitdir, ' :h' )
45
+ let cwd = getcwd ()
46
+ return cwd = ~# ' ^' . root ? cwd : root
26
47
endfunction
27
48
49
+
28
50
" cd or lcd to base directory of current file's git root
29
51
function ! easygit#cd (local) abort
30
52
let dir = easygit#gitdir (expand (' %' ))
@@ -575,16 +597,6 @@ function! easygit#listRemotes(...)
575
597
return substitute (output, ' \v(^|\n)\zs\s*' , ' ' , ' g' )
576
598
endfunction
577
599
578
- " If cwd inside current file git root, return cwd, otherwise return git root
579
- function ! easygit#smartRoot (... )
580
- let suspend = a: 0 ? a: 1 : 0
581
- let gitdir = easygit#gitdir (expand (' %' ), suspend )
582
- if empty (gitdir) | return ' ' | endif
583
- let root = fnamemodify (gitdir, ' :h' )
584
- let cwd = getcwd ()
585
- return cwd = ~# ' ^' . root ? cwd : root
586
- endfunction
587
-
588
600
function ! easygit#revert (args )
589
601
let root = easygit#smartRoot ()
590
602
if empty (root) | return | endif
0 commit comments