Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/manpages/gbp-pull.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

&man.common.options.synopsis;
<arg><option>--force</option></arg>
<arg><option>--all</option></arg>
<arg><option>--redo-pq</option></arg>
<arg><option>--[no-]pristine-tar</option></arg>
<arg><option>--ignore-branch</option></arg>
Expand Down Expand Up @@ -62,6 +63,13 @@
makes you lose your modifications.</para></warning></para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--all</option></term>
<listitem>
<para>Update all remote-tracking branches that have identical name in the
remote repository.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>--redo-pq</option></term>
<listitem>
Expand Down
25 changes: 21 additions & 4 deletions gbp/scripts/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -140,7 +144,7 @@ def main(argv):
return 1

try:
branches = []
branches = set()
try:
current = repo.get_branch()
except GitRepositoryError:
Expand All @@ -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:
Expand Down
31 changes: 30 additions & 1 deletion tests/component/deb/test_pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@


class TestPull(ComponentTestBase):
"""Test cloning from a remote"""
"""Test pulling from a remote"""

@RepoFixtures.native()
def test_pull_explicit_remote(self, repo):
Expand All @@ -50,3 +50,32 @@ def test_pull_default_remote(self, repo):
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)