diff options
-rw-r--r-- | objects/submodule/root.py | 20 | ||||
-rw-r--r-- | test/test_refs.py | 3 |
2 files changed, 11 insertions, 12 deletions
diff --git a/objects/submodule/root.py b/objects/submodule/root.py index ca51b34e..753c6df4 100644 --- a/objects/submodule/root.py +++ b/objects/submodule/root.py @@ -68,19 +68,15 @@ class RootModule(Submodule): ################## cur_commit = repo.head.commit if previous_commit is None: - symref = repo.head.orig_head() try: - previous_commit = symref.commit - except Exception: - pcommits = cur_commit.parents - if pcommits: - previous_commit = pcommits[0] - else: - # in this special case, we just diff against ourselve, which - # means exactly no change - previous_commit = cur_commit - # END handle initial commit - # END no ORIG_HEAD + previous_commit = repo.commit(repo.head.log_entry(-1).oldhexsha) + if previous_commit.binsha == previous_commit.NULL_BIN_SHA: + raise IndexError + #END handle initial commit + except IndexError: + # in new repositories, there is no previous commit + previous_commit = cur_commit + #END exception handling else: previous_commit = repo.commit(previous_commit) # obtain commit object # END handle previous commit diff --git a/test/test_refs.py b/test/test_refs.py index 52937de1..2338b4e4 100644 --- a/test/test_refs.py +++ b/test/test_refs.py @@ -149,6 +149,9 @@ class TestRefs(TestBase): assert self.rorepo.head.reference.is_valid() assert SymbolicReference(self.rorepo, 'hellothere').is_valid() == False + def test_orig_head(self): + assert type(self.rorepo.head.orig_head()) == SymbolicReference + @with_rw_repo('0.1.6') def test_head_reset(self, rw_repo): cur_head = rw_repo.head |