aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2017-01-19 11:46:30 +0100
committerGuido Günther <agx@sigxcpu.org>2017-01-19 11:46:51 +0100
commitb863399aa94e5ec4cdd7c60f131fb229b8f3b7b0 (patch)
tree411f4f86da196d8f562ad95e00b9dd46a4d2bb3b
parent588b70c21ee5a30620aa9d2f3ef646e456e8dce3 (diff)
pull: Allow to specify remote on the command line
Closes: #851844
-rw-r--r--docs/manpages/gbp-pull.sgml10
-rwxr-xr-xgbp/scripts/pull.py31
-rw-r--r--tests/component/deb/test_pull.py52
3 files changed, 84 insertions, 9 deletions
diff --git a/docs/manpages/gbp-pull.sgml b/docs/manpages/gbp-pull.sgml
index 185a0d0..9795ac2 100644
--- a/docs/manpages/gbp-pull.sgml
+++ b/docs/manpages/gbp-pull.sgml
@@ -29,6 +29,7 @@
<arg><option>--debian-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--upstream-branch=</option><replaceable>branch_name</replaceable></arg>
<arg><option>--depth=</option><replaceable>depth</replaceable></arg>
+ <arg><replaceable>repository</replaceable></arg>
</cmdsynopsis>
</refsynopsisdiv>
<refsect1>
@@ -36,9 +37,16 @@
<para>
&gbp-pull; updates the <emphasis>debian</emphasis>,
<emphasis>upstream</emphasis> and <emphasis>pristine-tar</emphasis>
- branches from a remote repository in one go. It checks if the update is safe (would
+ branches from remote repositories in one go. It checks if the update is safe (would
result in a <emphasis>fast-forward</emphasis> merge) and aborts otherwise.
</para>
+ <para>
+ If given on the command line the changes are fetched from the
+ given repository otherwise the default
+ for <replaceable>repository</replaceable> is read from
+ the <replaceable>remote</replaceable> configuration for each
+ branch (in git's configuration).
+ </para>
</refsect1>
<refsect1>
<title>OPTIONS</title>
diff --git a/gbp/scripts/pull.py b/gbp/scripts/pull.py
index 004156b..ec8285f 100755
--- a/gbp/scripts/pull.py
+++ b/gbp/scripts/pull.py
@@ -1,6 +1,6 @@
# vim: set fileencoding=utf-8 :
#
-# (C) 2009,2013 Guido Guenther <agx@sigxcpu.org>
+# (C) 2009,2013,2017 Guido Guenther <agx@sigxcpu.org>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
@@ -31,7 +31,7 @@ from gbp.scripts.common import ExitCodes
import gbp.log
-def fast_forward_branch(branch, repo, options):
+def fast_forward_branch(rem_repo, branch, repo, options):
"""
update branch to its remote branch, fail on non fast forward updates
unless --force is given
@@ -40,7 +40,11 @@ def fast_forward_branch(branch, repo, options):
"""
update = False
- remote = repo.get_merge_branch(branch)
+ if rem_repo:
+ remote = 'refs/remotes/%s/%s' % (rem_repo, branch)
+ else:
+ remote = repo.get_merge_branch(branch)
+
if not remote:
gbp.log.warn("No branch tracking '%s' found - skipping." % branch)
return False
@@ -74,7 +78,7 @@ def fast_forward_branch(branch, repo, options):
def build_parser(name):
try:
parser = GbpOptionParser(command=os.path.basename(name), prefix='',
- usage='%prog [options] - safely update a repository from remote')
+ usage='%prog [options] [repo] - safely update a repository from remote')
except GbpError as err:
gbp.log.err(err)
return None
@@ -103,12 +107,17 @@ def parse_args(argv):
parser = build_parser(argv[0])
if not parser:
return None, None
- return parser.parse_args(argv)
+ options, args = parser.parse_args(argv)
+ if len(args) > 2:
+ parser.print_help(file=sys.stderr)
+ return None, None
+ return options, args
def main(argv):
retval = 0
current = None
+ rem_repo = None
(options, args) = parse_args(argv)
if not options:
@@ -116,6 +125,12 @@ def main(argv):
gbp.log.setup(options.color, options.verbose, options.color_scheme)
+ if len(args) == 2:
+ rem_repo = args[1]
+ gbp.log.info("Fetching from '%s'" % rem_repo)
+ else:
+ gbp.log.info("Fetching from default remote for each branch")
+
try:
repo = DebianGitRepository(os.path.curdir)
except GitRepositoryError:
@@ -147,10 +162,10 @@ def main(argv):
gbp.log.err(out)
raise GbpError
- repo.fetch(depth=options.depth)
- repo.fetch(depth=options.depth, tags=True)
+ repo.fetch(rem_repo, depth=options.depth)
+ repo.fetch(rem_repo, depth=options.depth, tags=True)
for branch in branches:
- if not fast_forward_branch(branch, repo, options):
+ if not fast_forward_branch(rem_repo, branch, repo, options):
retval = 2
if options.redo_pq:
diff --git a/tests/component/deb/test_pull.py b/tests/component/deb/test_pull.py
new file mode 100644
index 0000000..80f6fe6
--- /dev/null
+++ b/tests/component/deb/test_pull.py
@@ -0,0 +1,52 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2017 Guido Günther <agx@sigxcpu.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, please see
+# <http://www.gnu.org/licenses/>
+
+import os
+
+from tests.component import (ComponentTestBase,
+ ComponentTestGitRepository)
+from tests.component.deb.fixtures import RepoFixtures
+
+from nose.tools import eq_
+
+from gbp.scripts.clone import main as clone
+from gbp.scripts.pull import main as pull
+
+
+class TestPull(ComponentTestBase):
+ """Test cloning from a remote"""
+
+ @RepoFixtures.native
+ def test_pull_explicit_remote(self, repo):
+ """Test that pulling of debian native packages works"""
+ dest = os.path.join(self._tmpdir, 'cloned_repo')
+ clone(['arg0', repo.path, dest])
+ cloned = ComponentTestGitRepository(dest)
+ self._check_repo_state(cloned, 'master', ['master'])
+ eq_(pull(['argv0', 'origin']), 0)
+ assert len(repo.get_commits()) == 1
+
+ @RepoFixtures.native
+ def test_pull_default_remote(self, repo):
+ """Test that pulling of debian native packages works"""
+ dest = os.path.join(self._tmpdir, 'cloned_repo')
+ clone(['arg0', repo.path, dest])
+ cloned = ComponentTestGitRepository(dest)
+ self._check_repo_state(cloned, 'master', ['master'])
+ eq_(pull(['argv0']), 0)
+ assert len(repo.get_commits()) == 1