summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bitbake/lib/bb/fetch2/git.py22
-rw-r--r--bitbake/lib/bb/tests/fetch.py42
2 files changed, 63 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 250109bf9e..aa972c5cf4 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -72,6 +72,7 @@ Supported SRC_URI options are:
72 72
73import collections 73import collections
74import errno 74import errno
75import fnmatch
75import os 76import os
76import re 77import re
77import subprocess 78import subprocess
@@ -180,6 +181,7 @@ class Git(FetchMethod):
180 ud.cloneflags += " --mirror" 181 ud.cloneflags += " --mirror"
181 182
182 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1" 183 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
184 ud.shallow_extra_refs = (d.getVar("BB_GIT_SHALLOW_EXTRA_REFS") or "").split()
183 185
184 depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH") 186 depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH")
185 if depth_default is not None: 187 if depth_default is not None:
@@ -265,8 +267,13 @@ class Git(FetchMethod):
265 if depth: 267 if depth:
266 tarballname = "%s-%s" % (tarballname, depth) 268 tarballname = "%s-%s" % (tarballname, depth)
267 269
270 shallow_refs = []
268 if not ud.nobranch: 271 if not ud.nobranch:
269 tarballname = "%s_%s" % (tarballname, "_".join(sorted(ud.branches.values())).replace('/', '.')) 272 shallow_refs.extend(ud.branches.values())
273 if ud.shallow_extra_refs:
274 shallow_refs.extend(r.replace('refs/heads/', '').replace('*', 'ALL') for r in ud.shallow_extra_refs)
275 if shallow_refs:
276 tarballname = "%s_%s" % (tarballname, "_".join(sorted(shallow_refs)).replace('/', '.'))
270 277
271 fetcher = self.__class__.__name__.lower() 278 fetcher = self.__class__.__name__.lower()
272 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname) 279 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname)
@@ -408,6 +415,19 @@ class Git(FetchMethod):
408 # Map srcrev+depths to revisions 415 # Map srcrev+depths to revisions
409 shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines() 416 shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines()
410 417
418 # Apply extra ref wildcards
419 all_refs = runfetchcmd('%s for-each-ref "--format=%%(refname)"' % ud.basecmd,
420 d, workdir=dest).splitlines()
421 for r in ud.shallow_extra_refs:
422 if not ud.bareclone:
423 r = r.replace('refs/heads/', 'refs/remotes/origin/')
424
425 if '*' in r:
426 matches = filter(lambda a: fnmatch.fnmatchcase(a, r), all_refs)
427 shallow_branches.extend(matches)
428 else:
429 shallow_branches.append(r)
430
411 # Make the repository shallow 431 # Make the repository shallow
412 shallow_cmd = ['git', 'make-shallow', '-s'] 432 shallow_cmd = ['git', 'make-shallow', '-s']
413 for b in shallow_branches: 433 for b in shallow_branches:
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 0b0116b455..3e2ce53056 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -1293,6 +1293,48 @@ class GitShallowTest(FetcherTest):
1293 with self.assertRaises(bb.fetch2.FetchError): 1293 with self.assertRaises(bb.fetch2.FetchError):
1294 self.fetch() 1294 self.fetch()
1295 1295
1296 def test_shallow_extra_refs(self):
1297 self.add_empty_file('a')
1298 self.add_empty_file('b')
1299 self.git('branch a_branch', cwd=self.srcdir)
1300 self.assertRefs(['master', 'a_branch'], cwd=self.srcdir)
1301 self.assertRevCount(2, cwd=self.srcdir)
1302
1303 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch')
1304 self.fetch_shallow()
1305
1306 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1307 self.assertRevCount(1)
1308
1309 def test_shallow_extra_refs_wildcard(self):
1310 self.add_empty_file('a')
1311 self.add_empty_file('b')
1312 self.git('branch a_branch', cwd=self.srcdir)
1313 self.git('tag v1.0', cwd=self.srcdir)
1314 self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir)
1315 self.assertRevCount(2, cwd=self.srcdir)
1316
1317 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
1318 self.fetch_shallow()
1319
1320 self.assertRefs(['master', 'origin/master', 'v1.0'])
1321 self.assertRevCount(1)
1322
1323 def test_shallow_missing_extra_refs(self):
1324 self.add_empty_file('a')
1325 self.add_empty_file('b')
1326
1327 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo')
1328 with self.assertRaises(bb.fetch2.FetchError):
1329 self.fetch()
1330
1331 def test_shallow_missing_extra_refs_wildcard(self):
1332 self.add_empty_file('a')
1333 self.add_empty_file('b')
1334
1335 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
1336 self.fetch()
1337
1296 if os.environ.get("BB_SKIP_NETTESTS") == "yes": 1338 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
1297 print("Unset BB_SKIP_NETTESTS to run network tests") 1339 print("Unset BB_SKIP_NETTESTS to run network tests")
1298 else: 1340 else: