def _pull(repository: Repository, branch_name: str, override: str, feedback_cb: Callable) -> None: # TODO(billvb) Refactor to BranchManager feedback_cb(f"Pulling from remote branch \"{branch_name}\"...") cp = repository.git.commit_hash try: call_subprocess(f'git pull'.split(), cwd=repository.root_dir) call_subprocess(f'git submodule update --recursive'.split(), cwd=repository.root_dir) except subprocess.CalledProcessError as cp_error: if 'Automatic merge failed' in cp_error.stdout.decode(): feedback_cb( f"Detected merge conflict, resolution method = {override}") bm = BranchManager(repository, username='') conflicted_files = bm._infer_conflicted_files( cp_error.stdout.decode()) if 'abort' == override: call_subprocess(f'git reset --hard {cp}'.split(), cwd=repository.root_dir) raise MergeConflict('Merge conflict pulling upstream', conflicted_files) call_subprocess( f'git checkout --{override} {" ".join(conflicted_files)}'. split(), cwd=repository.root_dir) call_subprocess('git add .'.split(), cwd=repository.root_dir) call_subprocess('git commit -m "Merge"'.split(), cwd=repository.root_dir) feedback_cb("Resolved merge conflict") else: raise
def _pull(repository: Repository, branch_name: str, override: str, feedback_cb: Callable, username: Optional[str] = None) -> None: # TODO(billvb) Refactor to BranchManager feedback_cb(f"Pulling from remote branch \"{branch_name}\"...") cp = repository.git.commit_hash try: call_subprocess(f'git pull'.split(), cwd=repository.root_dir) if isinstance(repository, LabBook): if not username: raise ValueError( "Current logged in username required to checkout a Project with a linked dataset" ) InventoryManager().update_linked_dataset(repository, username, init=True) except subprocess.CalledProcessError as cp_error: if 'Automatic merge failed' in cp_error.stdout.decode(): feedback_cb( f"Detected merge conflict, resolution method = {override}") bm = BranchManager(repository, username='') conflicted_files = bm._infer_conflicted_files( cp_error.stdout.decode()) if 'abort' == override: call_subprocess(f'git reset --hard {cp}'.split(), cwd=repository.root_dir) raise MergeConflict('Merge conflict pulling upstream', conflicted_files) call_subprocess( f'git checkout --{override} {" ".join(conflicted_files)}'. split(), cwd=repository.root_dir) call_subprocess('git add .'.split(), cwd=repository.root_dir) call_subprocess('git commit -m "Merge"'.split(), cwd=repository.root_dir) feedback_cb("Resolved merge conflict") else: raise