From d8ed8bd84cb5f37ebda2bb4dbf18b0bd7faacd0c Mon Sep 17 00:00:00 2001 From: Markus Lehtonen Date: Tue, 15 Jan 2013 16:28:24 +0200 Subject: gbp-pull: implement --all cmdline option This updates all remote-tracking branches (for the remote that is fetched from) whose local branch name is identical to the remote branch name. Signed-off-by: Markus Lehtonen --- docs/manpages/gbp-pull.xml | 8 ++++++++ gbp/scripts/pull.py | 25 +++++++++++++++++++++---- tests/component/deb/test_pull.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 4 deletions(-) diff --git a/docs/manpages/gbp-pull.xml b/docs/manpages/gbp-pull.xml index a075bc38..462004ea 100644 --- a/docs/manpages/gbp-pull.xml +++ b/docs/manpages/gbp-pull.xml @@ -23,6 +23,7 @@ &man.common.options.synopsis; + @@ -62,6 +63,13 @@ makes you lose your modifications. + + + + Update all remote-tracking branches that have identical name in the + remote repository. + + diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py index bb821b10..a4851157 100755 --- a/gbp/scripts/pull.py +++ b/gbp/scripts/pull.py @@ -62,7 +62,8 @@ def fast_forward_branch(rem_repo, branch, repo, options): gbp.log.info("Non-fast forwarding '%s' due to --force" % branch) update = True else: - gbp.log.warn("Skipping non-fast forward of '%s' - use --force" % branch) + gbp.log.warn("Skipping non-fast forward of '%s' - use --force or " + "update manually" % branch) if update: gbp.log.info("Updating '%s': %s..%s" % (branch, @@ -90,6 +91,9 @@ def build_parser(name): branch_group.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch") branch_group.add_option("--force", action="store_true", dest="force", default=False, help="force a branch update even if it can't be fast forwarded") + branch_group.add_option("--all", action="store_true", default=False, + help="update all remote-tracking branches that " + "have identical name in the remote") branch_group.add_option("--redo-pq", action="store_true", dest="redo_pq", default=False, help="redo the patch queue branch after a pull. Warning: this drops the old patch-queue branch") branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch") @@ -140,7 +144,7 @@ def main(argv): return 1 try: - branches = [] + branches = set() try: current = repo.get_branch() except GitRepositoryError: @@ -153,10 +157,23 @@ def main(argv): for branch in [options.debian_branch, options.upstream_branch]: if repo.has_branch(branch): - branches += [branch] + branches.add(branch) if repo.has_pristine_tar_branch() and options.pristine_tar: - branches += [repo.pristine_tar_branch] + branches.add(repo.pristine_tar_branch) + + if options.all: + current_remote = repo.get_merge_branch(current) + if current_remote: + fetch_remote = current_remote.split('/')[0] + else: + fetch_remote = 'origin' + for branch in repo.get_local_branches(): + merge_branch = repo.get_merge_branch(branch) + if merge_branch: + rem, rem_br = merge_branch.split('/', 1) + if rem == fetch_remote and branch == rem_br: + branches.add(branch) (ret, out) = repo.is_clean() if not ret: diff --git a/tests/component/deb/test_pull.py b/tests/component/deb/test_pull.py index 53588f6f..34fc3044 100644 --- a/tests/component/deb/test_pull.py +++ b/tests/component/deb/test_pull.py @@ -50,3 +50,32 @@ class TestPull(ComponentTestBase): self._check_repo_state(cloned, 'master', ['master']) eq_(pull(['argv0']), 0) assert len(repo.get_commits()) == 1 + + @RepoFixtures.quilt30() + def test_pull_all(self, repo): + """Test the '--all' commandline option""" + # Create new branch in repo + repo.create_branch('foob') + + # Clone and create new commits in origin + dest = os.path.join(self._tmpdir, 'cloned_repo') + clone(['arg0', '--all', repo.path, dest]) + cloned = ComponentTestGitRepository(dest) + tmp_workdir = os.path.join(self._tmpdir, 'tmp_workdir') + os.mkdir(tmp_workdir) + with open(os.path.join(tmp_workdir, 'new_file'), 'w'): + pass + repo.commit_dir(tmp_workdir, 'New commit in master', branch='master') + repo.commit_dir(tmp_workdir, 'New commit in foob', branch='foob') + + # Check that the branch is not updated when --all is not used + eq_(pull(['argv0']), 0) + eq_(len(cloned.get_commits(until='master')), 3) + eq_(len(cloned.get_commits(until='upstream')), 1) + eq_(len(cloned.get_commits(until='foob')), 2) + + # Check that --all updates all branches + repo.commit_dir(tmp_workdir, 'New commit in upstream', branch='upstream') + eq_(pull(['argv0', '--all']), 0) + eq_(len(cloned.get_commits(until='foob')), 3) + eq_(len(cloned.get_commits(until='upstream')), 2) -- cgit v1.2.3