def test_set_tracking_branch_existing_branch_tracking_other(tmpdir): git = qisrc.git.Git(tmpdir.strpath) git.init() git.commit("-m", "empty", "--allow-empty") git.set_tracking_branch("master", "origin") ret = git.set_tracking_branch("master", "other") assert ret is True
def fetch_manifest(worktree, manifest_git_url, branch="master", profile="default", src="manifest/default"): """ Fetch the manifest for a worktree :param manifest_git_url: A git repository containing a 'manifest.xml' file, ala repo :param branch: The branch to use :param src: The path where to store the clone of the manifest Note: every changes made by the user directly in the manifest repo will be lost! """ manifest = worktree.get_project(src) if not manifest: clone_project(worktree, manifest_git_url, src=src) manifest = worktree.get_project(src) # Make sure manifest project is on the correct, up to date branch: git = qisrc.git.Git(manifest.path) git.set_remote("origin", manifest_git_url) git.set_tracking_branch(branch, "origin") git.checkout("-f", branch, quiet=True) git.fetch(quiet=True) git.reset("--hard", "origin/%s" % branch, quiet=True) filename = profile + ".xml" manifest_file = os.path.join(manifest.path, filename) if not os.path.exists(manifest_file): mess = "Could not find a file named '%s' " % filename mess += "in the repository: %s\n" % manifest_git_url raise Exception(mess) return manifest_file
def test_set_tracking_branch_existing_branch_tracking_ok(tmpdir): """ Test Set Tracking Branch Existing Branch Tacking Ok """ git = qisrc.git.Git(tmpdir.strpath) git.init() git.commit("-m", "empty", "--allow-empty") git.set_tracking_branch("master", "origin") ret = git.set_tracking_branch("master", "origin") assert ret is True
def init_worktree(worktree, manifest_location, setup_review=True): """ (re)-intianlize a worktree given a manifest location. Clonie any missing repository, set the correct remote and tracking branch on every repository :param setup_review: Also set up the projects for review """ errors = list() manifest = qisrc.manifest.load(manifest_location) if not manifest.projects: return project_count = len(manifest.projects) ui.info(ui.green, "Initializing worktree ...") setup_ok = True for i, project in enumerate(manifest.projects): ui.info( ui.green, "*", ui.reset, "(%2i/%2i)" % (i+1, project_count), ui.blue, project.name) # Use the same branch for the project as the branch # for the manifest, unless explicitely set: p_revision = project.revision p_url = project.fetch_url p_remote = project.remote p_src = project.path wt_project = worktree.get_project(p_src) if not wt_project: # Maybe we just need to add the project to the worktree: wt_project = add_if_missing(worktree, p_src, p_remote, p_url) if not wt_project: wt_project = clone_project(worktree, p_url, src=p_src, branch=p_revision, remote=p_remote) p_path = wt_project.path if project.review and setup_review and setup_ok: worktree.set_project_review(p_src, True) # If setup failed once, no point in trying for every project setup_ok = qisrc.review.setup_project(p_path, project.name, project.review_url, p_revision) git = qisrc.git.Git(p_path) git.set_remote(p_remote, p_url) git.set_tracking_branch(p_revision, p_remote) cur_branch = git.get_current_branch() if cur_branch != p_revision: if not cur_branch: ui.warning("Project", project.name, "is on a detached HEAD", "but should be on", p_revision) else: ui.warning("Project", project.name, "is on", cur_branch, "but should be on", p_revision) worktree.set_git_project_config(p_src, p_remote, p_revision) if not setup_ok: qisrc.review.warn_gerrit()
def test_set_tracking_branch(tmpdir): tmpdir = tmpdir.strpath bar_url = create_git_repo(tmpdir, "bar") work = os.path.join(tmpdir, "work") bar_src = os.path.join(work, "bar") git = qisrc.git.Git(bar_src) git.clone(bar_url) push_file(tmpdir, "bar", "README", "README on release", branch="release") push_file(tmpdir, "bar", "README", "README on master", branch="master") git.update_branch("master", "origin") git.set_tracking_branch("release", "origin") err = git.update_branch("release", "origin") assert not err # This should work out of the box git.pull() git.checkout("release") git.pull()
def test_set_remote(self): bar_url = create_git_repo(self.tmp, "bar", with_release_branch=True) work = os.path.join(self.tmp, "work") qibuild.sh.mkdir(work) bar_src = os.path.join(work, "bar") git = qisrc.git.Git(bar_src) git.clone(bar_url, "-o", "foo") # Must work: git.pull() git.set_remote("origin", bar_url) # Must NOT work: out, err_ = git.pull("origin", raises=False) self.assertFalse(out == 0) # Must work git.set_tracking_branch("master", "origin") git.pull() readme = read_readme(bar_src) self.assertEqual(readme, "bar\n") git.set_tracking_branch("stable", "origin", remote_branch="release-1.12") git.checkout("stable") git.pull() readme = read_readme(bar_src) self.assertEqual(readme, "bar on release-1.12\n")
def test_set_tracking_branch_on_empty_repo(tmpdir): git = qisrc.git.Git(tmpdir.strpath) git.init() ret = git.set_tracking_branch("master", "master", "origin") assert ret is False