Show More
@@ -461,7 +461,7 b' class BaseRepository(object):' | |||||
461 | raise ValueError('message cannot be empty') |
|
461 | raise ValueError('message cannot be empty') | |
462 |
|
462 | |||
463 | shadow_repository_path = self._maybe_prepare_merge_workspace( |
|
463 | shadow_repository_path = self._maybe_prepare_merge_workspace( | |
464 | workspace_id, target_ref) |
|
464 | workspace_id, target_ref, source_ref) | |
465 |
|
465 | |||
466 | try: |
|
466 | try: | |
467 | return self._merge_repo( |
|
467 | return self._merge_repo( | |
@@ -482,7 +482,7 b' class BaseRepository(object):' | |||||
482 | """Internal implementation of merge.""" |
|
482 | """Internal implementation of merge.""" | |
483 | raise NotImplementedError |
|
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 | Create the merge workspace. |
|
487 | Create the merge workspace. | |
488 |
|
488 |
@@ -402,6 +402,12 b' class GitRepository(BaseRepository):' | |||||
402 | node = tree |
|
402 | node = tree | |
403 | return tree |
|
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 | def get_commit(self, commit_id=None, commit_idx=None, pre_load=None): |
|
411 | def get_commit(self, commit_id=None, commit_idx=None, pre_load=None): | |
406 | """ |
|
412 | """ | |
407 | Returns `GitCommit` object representing commit from git repository |
|
413 | Returns `GitCommit` object representing commit from git repository | |
@@ -722,16 +728,26 b' class GitRepository(BaseRepository):' | |||||
722 | stdout, _ = self.run_git_command(['rev-parse', 'HEAD']) |
|
728 | stdout, _ = self.run_git_command(['rev-parse', 'HEAD']) | |
723 | return stdout.strip() |
|
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 | Create a local clone of the current repo. |
|
733 | Create a local clone of the current repo. | |
728 | """ |
|
734 | """ | |
729 | # N.B.(skreft): the --branch option is required as otherwise the shallow |
|
735 | # N.B.(skreft): the --branch option is required as otherwise the shallow | |
730 | # clone will only fetch the active branch. |
|
736 | # clone will only fetch the active branch. | |
731 |
cmd = ['clone', '--branch', branch_name, |
|
737 | cmd = ['clone', '--branch', branch_name, | |
732 | self.path, os.path.abspath(clone_path)] |
|
738 | self.path, os.path.abspath(clone_path)] | |
|
739 | ||||
733 | self.run_git_command(cmd, fail_on_stderr=False) |
|
740 | self.run_git_command(cmd, fail_on_stderr=False) | |
734 |
|
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] | |||
|
749 | self.run_git_command(cmd, fail_on_stderr=False) | |||
|
750 | ||||
735 | def _local_fetch(self, repository_path, branch_name): |
|
751 | def _local_fetch(self, repository_path, branch_name): | |
736 | """ |
|
752 | """ | |
737 | Fetch a branch from a local repository. |
|
753 | Fetch a branch from a local repository. | |
@@ -873,8 +889,16 b' class GitRepository(BaseRepository):' | |||||
873 | False, False, None, MergeFailureReason.TARGET_IS_NOT_HEAD) |
|
889 | False, False, None, MergeFailureReason.TARGET_IS_NOT_HEAD) | |
874 |
|
890 | |||
875 | shadow_repo = GitRepository(shadow_repository_path) |
|
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 | shadow_repo._checkout(target_ref.name) |
|
899 | shadow_repo._checkout(target_ref.name) | |
877 | shadow_repo._local_pull(self.path, target_ref.name) |
|
900 | shadow_repo._local_pull(self.path, target_ref.name) | |
|
901 | ||||
878 | # Need to reload repo to invalidate the cache, or otherwise we cannot |
|
902 | # Need to reload repo to invalidate the cache, or otherwise we cannot | |
879 | # retrieve the last target commit. |
|
903 | # retrieve the last target commit. | |
880 | shadow_repo = GitRepository(shadow_repository_path) |
|
904 | shadow_repo = GitRepository(shadow_repository_path) | |
@@ -939,10 +963,11 b' class GitRepository(BaseRepository):' | |||||
939 | os.path.dirname(self.path), |
|
963 | os.path.dirname(self.path), | |
940 | '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id)) |
|
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 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) |
|
967 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) | |
944 | if not os.path.exists(shadow_repository_path): |
|
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 | return shadow_repository_path |
|
972 | return shadow_repository_path | |
948 |
|
973 |
@@ -693,7 +693,7 b' class MercurialRepository(BaseRepository' | |||||
693 | os.path.dirname(self.path), |
|
693 | os.path.dirname(self.path), | |
694 | '.__shadow_%s_%s' % (os.path.basename(self.path), workspace_id)) |
|
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 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) |
|
697 | shadow_repository_path = self._get_shadow_repository_path(workspace_id) | |
698 | if not os.path.exists(shadow_repository_path): |
|
698 | if not os.path.exists(shadow_repository_path): | |
699 | self._local_clone(shadow_repository_path) |
|
699 | self._local_clone(shadow_repository_path) |
General Comments 0
You need to be logged in to leave comments.
Login now