##// 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 return blob.id
571 return blob.id
572
572
573 @reraise_safe_exceptions
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 repo_init = self._factory.repo_libgit2(wire)
578 repo_init = self._factory.repo_libgit2(wire)
576 with repo_init as repo:
579 with repo_init as repo:
577
580
@@ -590,6 +593,10 b' class GitRemote(RemoteBase):'
590 # validate this tree is in the repo...
593 # validate this tree is in the repo...
591 tree = repo[safe_str(tree)].id
594 tree = repo[safe_str(tree)].id
592
595
596 if parents:
597 # run via sha's and validate them in repo
598 parents = [repo[c].id for c in parents]
599 else:
593 parents = []
600 parents = []
594 # ensure we COMMIT on top of given branch head
601 # 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
602 # check if this repo has ANY branches, otherwise it's a new branch case we need to make
@@ -635,6 +642,12 b' class GitRemote(RemoteBase):'
635 with repo_init as repo:
642 with repo_init as repo:
636 repo_index = repo.index
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 for pathspec in updated:
651 for pathspec in updated:
639 blob_id = repo.create_blob(pathspec['content'])
652 blob_id = repo.create_blob(pathspec['content'])
640 ie = pygit2.IndexEntry(pathspec['path'], blob_id, mode2pygit(pathspec['mode']))
653 ie = pygit2.IndexEntry(pathspec['path'], blob_id, mode2pygit(pathspec['mode']))
@@ -647,9 +660,9 b' class GitRemote(RemoteBase):'
647 repo_index.write()
660 repo_index.write()
648
661
649 # Create a tree from the updated index
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 author = commit_data['author']
667 author = commit_data['author']
655 committer = commit_data['committer']
668 committer = commit_data['committer']
@@ -658,7 +671,7 b' class GitRemote(RemoteBase):'
658 date_args = [int(commit_data['commit_time']), int(commit_data['commit_timezone'])]
671 date_args = [int(commit_data['commit_time']), int(commit_data['commit_timezone'])]
659
672
660 new_commit_id = self.create_commit(wire, author, committer, message, branch,
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 # libgit2, ensure the branch is there and exists
676 # libgit2, ensure the branch is there and exists
664 self.create_branch(wire, branch, new_commit_id)
677 self.create_branch(wire, branch, new_commit_id)
@@ -680,12 +693,13 b' class GitRemote(RemoteBase):'
680 repo = self._factory.repo(wire)
693 repo = self._factory.repo(wire)
681
694
682 determine_wants = repo.object_store.determine_wants_all
695 determine_wants = repo.object_store.determine_wants_all
696
683 if refs:
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 determined = []
701 determined = []
688 for ref_name, ref_hash in remote_refs.items():
702 for ref_name, ref_hash in _remote_refs.items():
689 bytes_ref_name = safe_bytes(ref_name)
703 bytes_ref_name = safe_bytes(ref_name)
690
704
691 if bytes_ref_name in refs:
705 if bytes_ref_name in refs:
@@ -723,8 +737,13 b' class GitRemote(RemoteBase):'
723 repo[k] = remote_refs[k]
737 repo[k] = remote_refs[k]
724
738
725 if refs and not update_after:
739 if refs and not update_after:
740 # update to ref
726 # mikhail: explicitly set the head to the last ref.
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 if update_after:
748 if update_after:
730 # we want to check out HEAD
749 # we want to check out HEAD
General Comments 0
You need to be logged in to leave comments. Login now