diff options
| author | Matt Robenolt <matt@ydekproductions.com> | 2016-04-29 10:51:42 -0700 |
|---|---|---|
| committer | Matt Robenolt <matt@ydekproductions.com> | 2016-04-29 11:12:58 -0700 |
| commit | 25728c8190a7f008cdb00b1664cd4fd479060eaf (patch) | |
| tree | 56bb753a148d8471d20dafd7e6cb69cff8e8c328 | |
| parent | 719358b8d21024b6a7374683d5377d7354b4ec97 (diff) | |
| download | raven-packed-refs.tar.gz | |
Read git sha from packed-refs file after a git-gcpacked-refs
Fixes GH-758 GH-709
| -rw-r--r-- | raven/versioning.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/raven/versioning.py b/raven/versioning.py index c36b719..993a238 100644 --- a/raven/versioning.py +++ b/raven/versioning.py @@ -28,8 +28,9 @@ def fetch_git_sha(path, head=None): head = text_type(fp.read()).strip() if head.startswith('ref: '): + head = head[5:] revision_file = os.path.join( - path, '.git', *head.rsplit(' ', 1)[-1].split('/') + path, '.git', *head.split('/') ) else: return head @@ -40,6 +41,25 @@ def fetch_git_sha(path, head=None): if not os.path.exists(os.path.join(path, '.git')): raise InvalidGitRepository( '%s does not seem to be the root of a git repository' % (path,)) + + # Check for our .git/packed-refs' file since a `git gc` may have run + # https://git-scm.com/book/en/v2/Git-Internals-Maintenance-and-Data-Recovery + packed_file = os.path.join(path, '.git', 'packed-refs') + if os.path.exists(packed_file): + with open(packed_file, 'r') as fh: + for line in fh: + line = line.rstrip() + if not line: + continue + if line[:1] in ('#', '^'): + continue + try: + revision, ref = line.split(' ', 1) + except ValueError: + continue + if ref == head: + return text_type(revision) + raise InvalidGitRepository( 'Unable to find ref to head "%s" in repository' % (head,)) |
