##// END OF EJS Templates
fix(git): fixed case when we want a set explicit ref instead of last one that is not stable
super-admin -
r1173:76143c56 default
parent child Browse files
Show More
@@ -571,7 +571,10 b' class GitRemote(RemoteBase):'
571 571 return blob.id
572 572
573 573 @reraise_safe_exceptions
574 def create_commit(self, wire, author, committer, message, branch, new_tree_id, date_args: list[int, int] = None):
574 def create_commit(self, wire, author, committer, message, branch, new_tree_id,
575 date_args: list[int, int] = None,
576 parents: list | None = None):
577
575 578 repo_init = self._factory.repo_libgit2(wire)
576 579 with repo_init as repo:
577 580
@@ -590,16 +593,20 b' class GitRemote(RemoteBase):'
590 593 # validate this tree is in the repo...
591 594 tree = repo[safe_str(tree)].id
592 595
593 parents = []
594 # ensure we COMMIT on top of given branch head
595 # check if this repo has ANY branches, otherwise it's a new branch case we need to make
596 if branch in repo.branches.local:
597 parents += [repo.branches[branch].target]
598 elif [x for x in repo.branches.local]:
599 parents += [repo.head.target]
600 #else:
601 # in case we want to commit on new branch we create it on top of HEAD
602 #repo.branches.local.create(branch, repo.revparse_single('HEAD'))
596 if parents:
597 # run via sha's and validate them in repo
598 parents = [repo[c].id for c in parents]
599 else:
600 parents = []
601 # ensure we COMMIT on top of given branch head
602 # check if this repo has ANY branches, otherwise it's a new branch case we need to make
603 if branch in repo.branches.local:
604 parents += [repo.branches[branch].target]
605 elif [x for x in repo.branches.local]:
606 parents += [repo.head.target]
607 #else:
608 # in case we want to commit on new branch we create it on top of HEAD
609 #repo.branches.local.create(branch, repo.revparse_single('HEAD'))
603 610
604 611 # # Create a new commit
605 612 commit_oid = repo.create_commit(
@@ -635,6 +642,12 b' class GitRemote(RemoteBase):'
635 642 with repo_init as repo:
636 643 repo_index = repo.index
637 644
645 commit_parents = None
646 if commit_tree and commit_data['parents']:
647 commit_parents = commit_data['parents']
648 parent_commit = repo[commit_parents[0]]
649 repo_index.read_tree(parent_commit.tree)
650
638 651 for pathspec in updated:
639 652 blob_id = repo.create_blob(pathspec['content'])
640 653 ie = pygit2.IndexEntry(pathspec['path'], blob_id, mode2pygit(pathspec['mode']))
@@ -647,9 +660,9 b' class GitRemote(RemoteBase):'
647 660 repo_index.write()
648 661
649 662 # Create a tree from the updated index
650 commit_tree = repo_index.write_tree()
663 written_commit_tree = repo_index.write_tree()
651 664
652 new_tree_id = commit_tree
665 new_tree_id = written_commit_tree
653 666
654 667 author = commit_data['author']
655 668 committer = commit_data['committer']
@@ -658,7 +671,7 b' class GitRemote(RemoteBase):'
658 671 date_args = [int(commit_data['commit_time']), int(commit_data['commit_timezone'])]
659 672
660 673 new_commit_id = self.create_commit(wire, author, committer, message, branch,
661 new_tree_id, date_args=date_args)
674 new_tree_id, date_args=date_args, parents=commit_parents)
662 675
663 676 # libgit2, ensure the branch is there and exists
664 677 self.create_branch(wire, branch, new_commit_id)
@@ -680,12 +693,13 b' class GitRemote(RemoteBase):'
680 693 repo = self._factory.repo(wire)
681 694
682 695 determine_wants = repo.object_store.determine_wants_all
696
683 697 if refs:
684 refs = [ascii_bytes(x) for x in refs]
698 refs: list[bytes] = [ascii_bytes(x) for x in refs]
685 699
686 def determine_wants_requested(remote_refs):
700 def determine_wants_requested(_remote_refs):
687 701 determined = []
688 for ref_name, ref_hash in remote_refs.items():
702 for ref_name, ref_hash in _remote_refs.items():
689 703 bytes_ref_name = safe_bytes(ref_name)
690 704
691 705 if bytes_ref_name in refs:
@@ -723,8 +737,13 b' class GitRemote(RemoteBase):'
723 737 repo[k] = remote_refs[k]
724 738
725 739 if refs and not update_after:
740 # update to ref
726 741 # mikhail: explicitly set the head to the last ref.
727 repo[HEAD_MARKER] = remote_refs[refs[-1]]
742 update_to_ref = refs[-1]
743 if isinstance(update_after, str):
744 update_to_ref = update_after
745
746 repo[HEAD_MARKER] = remote_refs[update_to_ref]
728 747
729 748 if update_after:
730 749 # we want to check out HEAD
General Comments 0
You need to be logged in to leave comments. Login now