Skip to content

Commit 7c1dcd8

Browse files
committed
Use gitpython to find a commit reference
Fixes #3842
1 parent f4e645d commit 7c1dcd8

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

readthedocs/vcs_support/backends/git.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import re
1111

1212
from django.core.exceptions import ValidationError
13-
import git
13+
from git import Repo
14+
from git.exc import BadName
1415
from six import PY2, StringIO
1516

1617
from readthedocs.core.validators import validate_repository_url
@@ -273,8 +274,13 @@ def find_ref(self, ref):
273274
return ref
274275

275276
def ref_exists(self, ref):
276-
code, _, _ = self.run('git', 'show-ref', ref, record_as_success=True)
277-
return code == 0
277+
try:
278+
r = git.Repo(self.working_dir)
279+
if r.commit(ref):
280+
return True
281+
except BadName:
282+
return False
283+
return False
278284

279285
@property
280286
def env(self):

requirements/pip.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ dnspython==1.15.0
4747

4848
# VCS
4949
httplib2==0.10.3
50-
gitpython==2.1.8
50+
GitPython==2.1.8
5151

5252
# Search
5353
elasticsearch==1.5.0

0 commit comments

Comments
 (0)