Giter Club home page Giter Club logo

Comments (10)

tpope avatar tpope commented on July 1, 2024 4

FugitiveGitDir() handles all of that. You can just do

function! s:git_dir() abort
  return FugitiveGitDir()
endfunction

from gv.vim.

mhinz avatar mhinz commented on July 1, 2024 1

Thanks, tpope.

@mckellyln

You created the issue, so feel free to create a PR that removes s:git_dir() entirely and replaces its single use by FugitiveGitDir(). :)

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

Perhaps it is because I often invoke GV from an empty buffer and there was a change in fugitive:

@@ -181,6 +181,8 @@ function! FugitiveExtractGitDir(path) abort
   let path = s:Slash(a:path)
   if path =~# '^fugitive:'
     return matchstr(path, '\C^fugitive:\%(//\)\=\zs.\{-\}\ze\%(//\|::\|$\)')
+  elseif empty(path)
+    return ''
   elseif isdirectory(path)
     let path = fnamemodify(path, ':p:s?/$??')

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

Something like this works, but I'm sure there is a better way:

function! s:git_dir()
  if empty(get(b:, 'git_dir', ''))
    let l:gdir = fugitive#extract_git_dir(expand('%:p'))
    if empty(l:gdir)
      let l:gpath = './.git'
      if isdirectory(l:gpath)
        return l:gpath
      endif
    endif
    return l:gdir
  endif
  return b:git_dir
endfunction

from gv.vim.

mhinz avatar mhinz commented on July 1, 2024

@mckellyln

There will be two issues though:

  1. It only works if you're in the root of the repo.
  2. It will show . instead of the repo name in the statusline.

But the general approach is correct. So, maybe...

function! s:git_dir()
  if !empty(get(b:, 'git_dir', ''))
    return b:git_dir
  endif

  let git_dir = finddir('.git', expand('%').';')
  if !empty(git_dir)
    let b:git_dir = fnamemodify(git_dir, ':p:s?/$??')
    return b:git_dir
  endif

  return ''
endfunction

Other parts of the code use b:git_dir, so I just set it directly here. Might not be needed, though.

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

@mhinz awesome, thanks. Should you or I create a PR for this ?
I might still use fugitive#extract_git_dir(expand('%:p')), and only if that is empty then do your finddir code above ?

from gv.vim.

tpope avatar tpope commented on July 1, 2024

FugitiveGitDir() works in empty buffers now. For all intents and purposes fugitive#extract_git_dir() is deprecated.

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

ok, thank you @tpope.
So I can just do:

function! s:git_dir()
  if !empty(get(b:, 'git_dir', ''))
    return b:git_dir
  endif
  let b:git_dir = FugitiveGitDir()
  return b:git_dir
endfunction

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

cool

from gv.vim.

mckellyln avatar mckellyln commented on July 1, 2024

PR #70 created.
Thank you everyone.

from gv.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.