allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#7207] Fixed handling of git repos with an invalid HEAD pointer
Date Wed, 02 Apr 2014 22:26:59 GMT
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 <cjohns@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 <cjohns@slashdotmedia.com>
Authored: Wed Apr 2 22:25:25 2014 +0000
Committer: Cory Johns <cjohns@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


Mime
View raw message