Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace git status and git submodules status for gitpython #5002

Merged
merged 1 commit into from
Dec 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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