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
It is hard to define what a .git/
repository is
I did a bit of experimenting to see what Git considers as a Git repository.
As of 1.9.1, the minimal directory structure that must be inside a .git
directory for Git to consider it is:
mkdir objects refs
printf 'ref: refs/' > HEAD
as recognized by rev-parse
.
It is also obviously a corrupt repository in which most useful commands will fail.
The morale is: like any other format detection, false positives are inevitable, specially here that the minimal repo is so simple.
If you want something robust, instead of detecting if it is a Git repo, try to do whatever you want to do, and raise errors and deal with them if it fails.
It's easier to ask forgiveness than it is to get permission.