Skip to content

Commit 7da101b

Browse files
committed
submodule.update: previous_commit is now set according to the stored reflog value, and is not using ORIG_HEAD anymore
1 parent b81273e commit 7da101b

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

‎objects/submodule/root.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,15 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
6868
##################
6969
cur_commit = repo.head.commit
7070
if previous_commit is None:
71-
symref = repo.head.orig_head()
7271
try:
73-
previous_commit = symref.commit
74-
except Exception:
75-
pcommits = cur_commit.parents
76-
if pcommits:
77-
previous_commit = pcommits[0]
78-
else:
79-
# in this special case, we just diff against ourselve, which
80-
# means exactly no change
81-
previous_commit = cur_commit
82-
# END handle initial commit
83-
# END no ORIG_HEAD
72+
previous_commit = repo.commit(repo.head.log_entry(-1).oldhexsha)
73+
if previous_commit.binsha == previous_commit.NULL_BIN_SHA:
74+
raise IndexError
75+
#END handle initial commit
76+
except IndexError:
77+
# in new repositories, there is no previous commit
78+
previous_commit = cur_commit
79+
#END exception handling
8480
else:
8581
previous_commit = repo.commit(previous_commit) # obtain commit object
8682
# END handle previous commit

‎test/test_refs.py

+3
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ def test_is_valid(self):
149149
assert self.rorepo.head.reference.is_valid()
150150
assert SymbolicReference(self.rorepo, 'hellothere').is_valid() == False
151151

152+
def test_orig_head(self):
153+
assert type(self.rorepo.head.orig_head()) == SymbolicReference
154+
152155
@with_rw_repo('0.1.6')
153156
def test_head_reset(self, rw_repo):
154157
cur_head = rw_repo.head

0 commit comments

Comments
 (0)