Determine if directory is under git control

后端 未结 10 1394
醉酒成梦
醉酒成梦 2021-01-30 12:25

How can I tell if a given directory is part of a git respository?

(The following is in python, but bash or something would be fine.)

os.path.isdir(\'.svn         


        
10条回答
  •  星月不相逢
    2021-01-30 13:07

    If you'd prefer to look for a .gitdirectory, here's a cute way of doing that in Ruby:

    require 'pathname'
    
    def gitcheck()
      Pathname.pwd.ascend {|p| return true if (p + ".git").directory? }
      false
    end
    

    I'm unable to find something similar to ascend in Python.

提交回复
热议问题