You should detect them the way Git detects them, which is outlined in the answer you quoted. To wit, you need the following:
- an
objects/
directory;
- a
refs/
directory; and
- either a
HEAD
symlink or a HEAD
file that is properly formatted.
The exact specification is documented in the source code in setup.c
.
If you have what you suspect is a Git repository, you can change into it and run git rev-parse --git-dir
, which will exit successfully if you're in a Git repository, and exit unsuccessfully if you're not. You can also use git rev-parse --is-bare-repository
and look for either true
or false
to determine whether your repository is bare.
If you don't want to change into the repository, you can use git -C <DIR> rev-parse --git-dir
and similar to operate on the mentioned directory instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…