Set b:git_dir early in BufReadCmd

We call :setlocal filetype=git before manually triggering BufReadPost,
which means that the FileType events in the plugin file containing
len(FugitiveGitDir()) checks all short circuited.  This wasn't noticed
before because:

* They're mostly nonessential, save for fugitive#MapJumps() which we
  also explicitly invoke in BufReadCmd.
* If :filetype on is invoked *after* Fugitive is loaded, then it will
  set the filetype a second time *after* we've properly set b:git_dir.
  (This was the case on my machine, except when reloading the plugin
  redefined the autocommands and thus reversed the order.)

The load order issue is also relevant to plain file buffers.  This will
require an additional fix.
This commit is contained in:
Tim Pope
2021-03-13 22:43:45 -05:00
parent 36f9211da2
commit f2956a923d

View File

@@ -2108,6 +2108,7 @@ function! fugitive#BufReadCmd(...) abort
if empty(dir)
return 'echo "Invalid Fugitive URL"'
endif
let b:git_dir = dir
if rev =~# '^:\d$'
let b:fugitive_type = 'stage'
else