def _clone_missing(self, git_project, repo): """ Clone Missing """ branch = repo.default_branch fixed_ref = repo.fixed_ref clone_url = repo.clone_url qisys.sh.mkdir(git_project.path, recursive=True) git = qisrc.git.Git(git_project.path) remote_name = repo.default_remote.name try: git.init() git.remote("add", remote_name, clone_url) git.fetch(remote_name, "--quiet") if branch: git.checkout("-b", branch, "%s/%s" % (remote_name, branch)) if fixed_ref: git.checkout("-q", fixed_ref) except Exception: ui.error("Cloning repo failed") if git.is_empty(): qisys.sh.rm(git_project.path) self.worktree.remove_project(repo.src) return False self.save_project_config(git_project) self.load_git_projects() return True
def _clone_missing(self, git_project, repo): branch = repo.default_branch clone_url = repo.clone_url qisys.sh.mkdir(git_project.path, recursive=True) git = qisrc.git.Git(git_project.path) remote_name = repo.default_remote.name try: git.init() git.remote("add", remote_name, clone_url) git.fetch(remote_name, "--quiet") git.checkout("-b", branch, "%s/%s" % (remote_name, branch)) except: ui.error("Cloning repo failed") if git.is_empty(): qisys.sh.rm(git_project.path) self.worktree.remove_project(repo.src) return False self.save_project_config(git_project) self.load_git_projects() return True
def clone_missing(self, repo): """ Add a new project. :returns: a boolean telling if the clone succeeded """ worktree_project = self.worktree.add_project(repo.src) git_project = qisrc.project.GitProject(self, worktree_project) if os.path.exists(git_project.path): git = qisrc.git.Git(git_project.path) git_root = qisrc.git.get_repo_root(git_project.path) if not git_root == git_project.path: # Nested git projects: return self._clone_missing(git_project, repo) if git.is_valid() and git.is_empty(): ui.warning("Removing empty git project in", git_project.src) qisys.sh.rm(git_project.path) else: # Do nothing, the remote will be re-configured later # anyway return True return self._clone_missing(git_project, repo)
def _clone_missing(self, git_project, repo): branch = repo.default_branch clone_url = repo.clone_url qisys.sh.mkdir(git_project.path, recursive=True) git = qisrc.git.Git(git_project.path) remote_name = repo.default_remote.name try: git.init() git.remote("add", remote_name, clone_url) git.fetch(remote_name, "--quiet") remote_branch = "%s/%s" % (remote_name, branch) rc, _ = git.call("rev-parse", "--verify", "--quiet", remote_branch, raises=False) # When `remote_branch` is invalid, try to checkout `branch` instead git.checkout("-b", branch, branch if rc else remote_branch) except: ui.error("Cloning repo failed") if git.is_empty(): qisys.sh.rm(git_project.path) self.worktree.remove_project(repo.src) return False self.save_project_config(git_project) self.load_git_projects() return True
def _clone_missing(self, git_project, repo, worktree_clone=None): # You may be wondering why we use `git clone` when used with the --clone # option, and a combination of `git init`, `git fetch`, `git checkout` in # the general case. # The reason is that in the general case, we can have the following scenario: # - first foo/bar is created # - then foo/ is added to the manifest # In that case, trying to call `git clone` in foo/ will fail # # But when we are using --clone we know we have sorted the repos to clone # by their relative paths in the worktree, (see qisrc.sync.compute_repo_diff) # so we know foo/ will always be created before foo/bar/ branch = repo.default_branch fixed_ref = repo.fixed_ref clone_url = repo.clone_url git = qisrc.git.Git(git_project.path) remote_name = repo.default_remote.name remote_ref = "%s/%s" % (remote_name, branch) clone_project = None ok = True message = "" # Only use a local clone if: # * worktree_clone is set # * we find a matching project in the worktree_clone use_local = False if worktree_clone: clone_project = worktree_clone.find_repo(repo) if clone_project: use_local = True if use_local: # Only need to create the parent directory, `git clone` will take # care of the rest to_make = os.path.dirname(git_project.path) qisys.sh.mkdir(to_make) (ok, message) = git.local_clone(clone_project, clone_url, remote_name=remote_name, branch=branch) else: # Need to create the full path, since we will use # `git init ; git fetch ; git checkout` qisys.sh.mkdir(git_project.path, recursive=True) (ok, message) = git.safe_clone(clone_url, remote_name=remote_name, branch=branch) if not ok: ui.error("Cloning repo failed") ui.error(message) # If `git clone` fails, it's possible that the path does # not exist if os.path.exists(git_project.path) and git.is_empty(): qisys.sh.rm(git_project.path) self.worktree.remove_project(repo.src) return False if fixed_ref: rc, out = git.reset("--hard", fixed_ref, raises=False) if rc != 0: ui.error("Failed to reset to fixed ref") ui.error(out) return False self.save_project_config(git_project) self.load_git_projects() return True