Skip to content

Commit 930d960

Browse files
committed
Use gitpython to find a commit reference
Fixes #3842
1 parent 022c1d9 commit 930d960

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

readthedocs/vcs_support/backends/git.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import os
1010
import re
1111

12+
from git import Repo
13+
from git.exc import BadName
1214
from six import PY2, StringIO
1315

1416
from readthedocs.projects.exceptions import RepositoryError
@@ -254,8 +256,13 @@ def find_ref(self, ref):
254256
return ref
255257

256258
def ref_exists(self, ref):
257-
code, _, _ = self.run('git', 'show-ref', ref, record_as_success=True)
258-
return code == 0
259+
try:
260+
r = Repo(self.working_dir)
261+
if r.commit(ref):
262+
return True
263+
except BadName:
264+
return False
265+
return False
259266

260267
@property
261268
def env(self):

requirements/pip.txt

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

4848
# VCS
4949
httplib2==0.10.3
50+
GitPython==2.1.8
5051

5152
# Search
5253
elasticsearch==1.5.0

0 commit comments

Comments
 (0)