Skip to content

Commit

Permalink
Merge pull request #5002 from stsewd/use-git-python
Browse files Browse the repository at this point in the history
Replace git status and git submodules status for gitpython
  • Loading branch information
humitos authored Dec 18, 2018
2 parents 2796e15 + 93c031b commit dfbe6df
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import git
from builtins import str
from django.core.exceptions import ValidationError
from django.conf import settings
from git.exc import BadName
from git.exc import BadName, InvalidGitRepositoryError

from readthedocs.config import ALL
from readthedocs.projects.exceptions import RepositoryError
Expand Down Expand Up @@ -67,8 +66,11 @@ def update(self):
return self.clone()

def repo_exists(self):
code, _, _ = self.run('git', 'status', record=False)
return code == 0
try:
git.Repo(self.working_dir)
except InvalidGitRepositoryError:
return False
return True

def are_submodules_available(self, config):
"""Test whether git submodule checkout step should be performed."""
Expand All @@ -83,8 +85,8 @@ def are_submodules_available(self, config):
return False

# Keep compatibility with previous projects
code, out, _ = self.run('git', 'submodule', 'status', record=False)
return code == 0 and bool(out)
repo = git.Repo(self.working_dir)
return bool(repo.submodules)

def validate_submodules(self, config):
"""
Expand Down

0 comments on commit dfbe6df

Please sign in to comment.