Skip to content

Commit 2beca9f

Browse files
committed
clone: Fetch the upstream remote specified in debian/upstream/metadata
This avoids a step if the workflow involves using `--upstream-vcs-tag`. Overridable with the --upstream-remote configuration option. Set this to the empty string to disable cloning.
1 parent 8f893f9 commit 2beca9f

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

gbp/config.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ class GbpOptionParser(OptionParser):
187187
'track': 'True',
188188
'track-missing': 'False',
189189
'upstream-branch': 'upstream',
190+
'upstream-remote': 'upstream',
190191
'upstream-tag': 'upstream/%(version)s',
191192
'upstream-tree': 'TAG',
192193
'upstream-vcs-tag': '',
@@ -201,6 +202,11 @@ class GbpOptionParser(OptionParser):
201202
'upstream-tree':
202203
"Where to generate the upstream tarball from "
203204
"(tag or branch), default is '%(upstream-tree)s'",
205+
'upstream-remote':
206+
"If debian/upstream/metadata specifies an upstream git repository, "
207+
"the remote name to fetch it into, default is "
208+
"'%(upstream-remote)s'. Set to an empty string to disable cloning "
209+
"upstream",
204210
'pq-from':
205211
"How to find the patch queue base. DEBIAN or TAG, "
206212
"the default is '%(pq-from)s'",

gbp/scripts/clone.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def build_parser(name):
117117

118118
branch_group.add_option("--all", action="store_true", dest="all", default=False,
119119
help="track all branches, not only debian and upstream")
120+
branch_group.add_config_file_option(option_name="upstream-remote", dest="upstream_remote")
120121
branch_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
121122
branch_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
122123
branch_group.add_boolean_config_file_option(option_name="pristine-tar", dest="pristine_tar")
@@ -208,6 +209,31 @@ def main(argv):
208209

209210
repo_setup.set_user_name_and_email(options.repo_user, options.repo_email, repo)
210211

212+
if options.upstream_remote:
213+
try:
214+
with open(os.path.join(clone_to, 'debian', 'upstream', 'metadata')) as f:
215+
import yaml
216+
217+
y = yaml.load(f, Loader=yaml.CSafeLoader)
218+
try:
219+
upstream_repo = y['Repository']
220+
221+
try:
222+
# check if it exists as a git repo
223+
repo.fetch(repo=upstream_repo)
224+
225+
repo.add_remote_repo(options.upstream_remote,
226+
upstream_repo,
227+
tags=True)
228+
except GitRepositoryError:
229+
gbp.log.warn(
230+
'Unable to fetch upstream repository %s, '
231+
'ignoring.' % upstream_repo)
232+
except KeyError:
233+
pass
234+
except FileNotFoundError:
235+
pass
236+
211237
if postclone:
212238
Hook('Postclone', options.postclone,
213239
extra_env={'GBP_GIT_DIR': repo.git_dir},

tests/component/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def check_tags(cls, repo, tags):
178178

179179
@classmethod
180180
def _check_repo_state(cls, repo, current_branch, branches, files=None,
181-
dirs=None, tags=None, clean=True):
181+
dirs=None, tags=None, clean=True, remotes=[]):
182182
"""
183183
Check that repository is clean and given branches, tags, files
184184
and dirs exist
@@ -191,6 +191,12 @@ def _check_repo_state(cls, repo, current_branch, branches, files=None,
191191
local_branches)
192192
eq_(set(local_branches), set(branches), assert_msg)
193193

194+
if remotes:
195+
repo_remotes = repo.get_remotes().keys()
196+
assert_msg = "Remotes: expected %s, found %s" % (remotes,
197+
repo_remotes)
198+
eq_(set(repo_remotes), set(remotes), assert_msg)
199+
194200
if files is not None or dirs is not None:
195201
# Get files of the working copy recursively
196202
local_f = set()

tests/component/deb/test_clone.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,15 @@ def test_clone_github(self):
8282
self.assertEquals(ret, 0)
8383
cloned = ComponentTestGitRepository(dest)
8484
self._check_repo_state(cloned, 'master', ['master'])
85+
86+
@skipUnless(os.getenv("GBP_NETWORK_TESTS"), "network tests disabled")
87+
def test_clone_upstream_remote(self):
88+
"""Test that cloning from github urls works"""
89+
dest = os.path.join(self._tmpdir,
90+
'cloned_repo')
91+
ret = clone(['arg0', "vcsgit:tepl", dest])
92+
self.assertEquals(ret, 0)
93+
cloned = ComponentTestGitRepository(dest)
94+
self._check_repo_state(cloned, 'debian/master',
95+
['debian/master', 'upstream/latest', 'pristine-tar'],
96+
remotes=['origin', 'upstream'])

0 commit comments

Comments
 (0)