You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/04/03 00:26:59 UTC
git commit: [#7207] Fixed handling of git repos with an invalid HEAD
pointer
Repository: allura
Updated Branches:
refs/heads/master f72b7fdbc -> 461a4b542
[#7207] Fixed handling of git repos with an invalid HEAD pointer
Signed-off-by: Cory Johns <cj...@slashdotmedia.com>
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/461a4b54
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/461a4b54
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/461a4b54
Branch: refs/heads/master
Commit: 461a4b542feb39374c6eb7d601b154c2c658dabd
Parents: f72b7fd
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Wed Apr 2 22:25:25 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Wed Apr 2 22:25:25 2014 +0000
----------------------------------------------------------------------
ForgeGit/forgegit/model/git_repo.py | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/461a4b54/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 1cb771b..fef1b43 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -199,8 +199,8 @@ class GitImplementation(M.RepositoryImplementation):
"""Yield commit ids, starting with the head(s) of the commit tree and
ending with the root (first commit).
"""
- if not self._git.head.is_valid():
- return # empty repo
+ if self.is_empty():
+ return
seen = set()
for ci in self._git.iter_commits(all=True, topo_order=True):
if ci.binsha in seen:
@@ -480,7 +480,7 @@ class GitImplementation(M.RepositoryImplementation):
os.remove(tmpfilename)
def is_empty(self):
- return not self._git or len(self._git.heads) == 0
+ return not self.head
def is_file(self, path, rev=None):
path = path.strip('/')
@@ -493,6 +493,17 @@ class GitImplementation(M.RepositoryImplementation):
@LazyProperty
def head(self):
+ if not self._git or not self._git.heads:
+ return None
+ # if the repo's HEAD file doesn't point to a valid branch, we need to select one
+ # this can happen in particular with masterless repos
+ if not self._git.head.is_valid():
+ for head in self._git.heads:
+ if head.is_valid():
+ self._git.head.reference = head
+ break
+ else:
+ return None # no valid heads
return self._git.head.commit.hexsha
@LazyProperty