diff options
-rw-r--r-- | lib/git/objects/commit.py | 6 | ||||
-rw-r--r-- | lib/git/refs.py | 2 | ||||
-rw-r--r-- | test/git/test_index.py | 2 |
3 files changed, 9 insertions, 1 deletions
diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index ae22fb76..1aedaabf 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -365,7 +365,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): new_commit.binsha = istream.binsha if head: + # need late import here, importing git at the very beginning throws + # as well ... + import git.refs try: + cur_commit = repo.head.commit + # Adjust the original head reference - force it + git.refs.SymbolicReference.create(repo, 'ORIG_HEAD', cur_commit, force=True) repo.head.commit = new_commit except ValueError: # head is not yet set to the ref our HEAD points to diff --git a/lib/git/refs.py b/lib/git/refs.py index 39c5ff29..399c4b78 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -277,7 +277,7 @@ class SymbolicReference(object): @classmethod def to_full_path(cls, path): """ - :return: string with a full path name which can be used to initialize + :return: string with a full repository-relative path which can be used to initialize a Reference instance, for instance by using ``Reference.from_path``""" if isinstance(path, SymbolicReference): path = path.path diff --git a/test/git/test_index.py b/test/git/test_index.py index b5600eeb..29a7404d 100644 --- a/test/git/test_index.py +++ b/test/git/test_index.py @@ -409,6 +409,7 @@ class TestIndex(TestBase): commit_message = "commit default head" new_commit = index.commit(commit_message, head=False) + assert cur_commit != new_commit assert new_commit.author.name == uname assert new_commit.author.email == umail assert new_commit.committer.name == uname @@ -421,6 +422,7 @@ class TestIndex(TestBase): # same index, no parents commit_message = "index without parents" commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True) + assert SymbolicReference(rw_repo, 'ORIG_HEAD').commit == cur_commit assert commit_no_parents.message == commit_message assert len(commit_no_parents.parents) == 0 assert cur_head.commit == commit_no_parents |