enchanter
enchanter

Reputation: 924

How could I tell a give directory is git repo(bare or not bare) in Python

Is there any way to tell if a directory is a GIT repo in Python?

I am try to check if there's ".git" under that directory, but it doesn't work with bare repo.

Upvotes: 2

Views: 1345

Answers (1)

zymud
zymud

Reputation: 2249

You can use GitPython:

from git import Repo, InvalidGitRepositoryError

try:
    Repo(path_to_repo)
    print 'is git repo'
except InvalidGitRepositoryError:
    print 'isn`t git repo'

Upvotes: 3

Related Questions