Skip to content

Commit 7a320ab

Browse files
committed
commit: when creating a new commit and advancing the head, it will now write the ORIG_HEAD reference as well
1 parent 1687283 commit 7a320ab

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

lib/git/objects/commit.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,13 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
365365
new_commit.binsha = istream.binsha
366366

367367
if head:
368+
# need late import here, importing git at the very beginning throws
369+
# as well ...
370+
import git.refs
368371
try:
372+
cur_commit = repo.head.commit
373+
# Adjust the original head reference - force it
374+
git.refs.SymbolicReference.create(repo, 'ORIG_HEAD', cur_commit, force=True)
369375
repo.head.commit = new_commit
370376
except ValueError:
371377
# head is not yet set to the ref our HEAD points to

lib/git/refs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def is_detached(self):
277277
@classmethod
278278
def to_full_path(cls, path):
279279
"""
280-
:return: string with a full path name which can be used to initialize
280+
:return: string with a full repository-relative path which can be used to initialize
281281
a Reference instance, for instance by using ``Reference.from_path``"""
282282
if isinstance(path, SymbolicReference):
283283
path = path.path

test/git/test_index.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ def mixed_iterator():
409409
commit_message = "commit default head"
410410

411411
new_commit = index.commit(commit_message, head=False)
412+
assert cur_commit != new_commit
412413
assert new_commit.author.name == uname
413414
assert new_commit.author.email == umail
414415
assert new_commit.committer.name == uname
@@ -421,6 +422,7 @@ def mixed_iterator():
421422
# same index, no parents
422423
commit_message = "index without parents"
423424
commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True)
425+
assert SymbolicReference(rw_repo, 'ORIG_HEAD').commit == cur_commit
424426
assert commit_no_parents.message == commit_message
425427
assert len(commit_no_parents.parents) == 0
426428
assert cur_head.commit == commit_no_parents

0 commit comments

Comments
 (0)