Show More
@@ -461,7 +461,7 b' class BaseRepository(object):' | |||
|
461 | 461 | raise ValueError('message cannot be empty') |
|
462 | 462 | |
|
463 | 463 | shadow_repository_path = self._maybe_prepare_merge_workspace( |
|
464 | workspace_id, target_ref) | |
|
464 | workspace_id, target_ref, source_ref) | |
|
465 | 465 | |
|
466 | 466 | try: |
|
467 | 467 | return self._merge_repo( |
@@ -482,7 +482,7 b' class BaseRepository(object):' | |||
|
482 | 482 | """Internal implementation of merge.""" |
|
483 | 483 | raise NotImplementedError |
|
484 | 484 | |
|
485 | def _maybe_prepare_merge_workspace(self, workspace_id, target_ref): | |
|
485 | def _maybe_prepare_merge_workspace(self, workspace_id, target_ref, source_ref): | |
|
486 | 486 | """ |
|
487 | 487 | Create the merge workspace. |
|
488 | 488 |
@@ -402,6 +402,12 b' class GitRepository(BaseRepository):' | |||
|
402 | 402 | node = tree |
|
403 | 403 | return tree |
|
404 | 404 | |
|
405 | def get_remote_ref(self, ref_name): | |
|
406 | try: | |
|
407 | return self._ref_tree['refs']['remotes']['origin'][ref_name] | |
|
408 | except Exception: | |
|
409 | return | |
|
410 | ||
|
405 | 411 | def get_commit(self, commit_id=None, commit_idx=None, pre_load=None): |
|
406 | 412 | """ |
|
407 | 413 | Returns `GitCommit` object representing commit from git repository |
@@ -722,14 +728,24 b' class GitRepository(BaseRepository):' | |||
|
722 | 728 | stdout, _ = self.run_git_command(['rev-parse', 'HEAD']) |
|
723 | 729 | return stdout.strip() |
|
724 | 730 | |
|
725 | def _local_clone(self, clone_path, branch_name): | |
|
731 | def _local_clone(self, clone_path, branch_name, source_branch=None): | |
|
726 | 732 | """ |
|
727 | 733 | Create a local clone of the current repo. |
|
728 | 734 | """ |
|
729 | 735 | # N.B.(skreft): the --branch option is required as otherwise the shallow |
|
730 | 736 | # clone will only fetch the active branch. |
|
731 |
cmd = ['clone', '--branch', branch_name, |
|
|
737 | cmd = ['clone', '--branch', branch_name, | |
|
732 | 738 | self.path, os.path.abspath(clone_path)] |
|
739 | ||
|
740 | self.run_git_command(cmd, fail_on_stderr=False) | |
|
741 | ||
|
742 | # if we get the different source branch, make sure we also fetch it for | |
|
743 | # merge conditions | |
|
744 | if source_branch and source_branch != branch_name: | |
|
745 | # check if the ref exists. | |
|
746 | shadow_repo = GitRepository(os.path.abspath(clone_path)) | |
|
747 | if shadow_repo.get_remote_ref(source_branch): | |
|
748 | cmd = ['fetch', self.path, source_branch] | |
|
733 | 749 | self.run_git_command(cmd, fail_on_stderr=False) |
|
734 | 750 | |
|
735 | 751 | def _local_fetch(self, repository_path, branch_name): |
@@ -873,8 +889,16 b' class GitRepository(BaseRepository):' | |||
|
873 | 889 | False, False, None, MergeFailureReason.TARGET_IS_NOT_HEAD) |
|
874 | 890 | |
|
875 | 891 | shadow_repo = GitRepository(shadow_repository_path) |
|
892 | # checkout source, if it's different. Otherwise we could not | |
|
893 | # fetch proper commits for merge testing | |
|
894 | if source_ref.name != target_ref.name: | |
|
895 | if shadow_repo.get_remote_ref(source_ref.name): | |
|
896 | shadow_repo._checkout(source_ref.name) | |
|
897 | ||
|
898 | # checkout target | |
|
876 | 899 | shadow_repo._checkout(target_ref.name) |
|
877 | 900 | shadow_repo._local_pull(self.path, target_ref.name) |
|
901 | ||
|
878 | 902 | # Need to reload repo to invalidate the cache, or otherwise we cannot |
|
879 | 903 | # retrieve the last target commit. |
|
880 | 904 | shadow_repo = GitRepository(shadow_repository_path) |
@@ -939,10 +963,11 b' class GitRepository(BaseRepository):' | |||
|
939 | 963 | os.path.dirname(self.path), |
|
940 | 964 | '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id)) |
|
941 | 965 | |
|
942 | def _maybe_prepare_merge_workspace(self, workspace_id, target_ref): | |
|
966 | def _maybe_prepare_merge_workspace(self, workspace_id, target_ref, source_ref): | |
|
943 | 967 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) |
|
944 | 968 | if not os.path.exists(shadow_repository_path): |
|
945 |
self._local_clone( |
|
|
969 | self._local_clone( | |
|
970 | shadow_repository_path, target_ref.name, source_ref.name) | |
|
946 | 971 | |
|
947 | 972 | return shadow_repository_path |
|
948 | 973 |
@@ -693,7 +693,7 b' class MercurialRepository(BaseRepository' | |||
|
693 | 693 | os.path.dirname(self.path), |
|
694 | 694 | '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id)) |
|
695 | 695 | |
|
696 | def _maybe_prepare_merge_workspace(self, workspace_id, unused_target_ref): | |
|
696 | def _maybe_prepare_merge_workspace(self, workspace_id, unused_target_ref, unused_source_ref): | |
|
697 | 697 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) |
|
698 | 698 | if not os.path.exists(shadow_repository_path): |
|
699 | 699 | self._local_clone(shadow_repository_path) |
General Comments 0
You need to be logged in to leave comments.
Login now