summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests/fetch.py
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2017-05-13 02:46:33 +0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:57 +0100
commit35ecff3cf077bd22cf7d0a6145732cdcc34f15dc (patch)
tree14705c24efa0926d8ba6ccc2123c9fb2244e4345 /bitbake/lib/bb/tests/fetch.py
parent30485b2b1a3d49e0a72c9370e2ca2e763d83ace6 (diff)
downloadpoky-35ecff3cf077bd22cf7d0a6145732cdcc34f15dc.tar.gz
bitbake: fetch/git: add support for removing arbitrary revs for shallow
In certain cases, it's valuable to be able to exert more control over what history is removed, beyond srcrev+depth. As one example, you can remove most of the upstream kernel history from a kernel repository, keeping predominently the non-publically-accessible content. If the repository is private, the history in that repo couldn't be restored via `git fetch --unshallow`, but upstream history could be. Example usage: # Remove only these revs, not at a particular depth BB_GIT_SHALLOW_DEPTH_pn-linux-foo = "0" BB_GIT_SHALLOW_REVS_pn-linux-foo = "v4.1" (Bitbake rev: 97f856f0455d014ea34c28b1c25f09e13cdc851b) Signed-off-by: Christopher Larson <chris_larson@mentor.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests/fetch.py')
-rw-r--r--bitbake/lib/bb/tests/fetch.py66
1 files changed, 65 insertions, 1 deletions
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 73f7b3f78e..343ae8fe5e 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -1259,6 +1259,33 @@ class GitShallowTest(FetcherTest):
1259 self.add_empty_file('c') 1259 self.add_empty_file('c')
1260 self.add_empty_file('d') 1260 self.add_empty_file('d')
1261 self.git('checkout master', cwd=self.srcdir) 1261 self.git('checkout master', cwd=self.srcdir)
1262 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1263 self.add_empty_file('e')
1264 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1265 self.add_empty_file('f')
1266 self.assertRevCount(7, cwd=self.srcdir)
1267
1268 uri = self.d.getVar('SRC_URI', True).split()[0]
1269 uri = '%s;branch=master,a_branch;name=master,a_branch' % uri
1270
1271 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1272 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1273 self.d.setVar('SRCREV_master', '${AUTOREV}')
1274 self.d.setVar('SRCREV_a_branch', '${AUTOREV}')
1275
1276 self.fetch_shallow(uri)
1277
1278 self.assertRevCount(5)
1279 self.assertRefs(['master', 'origin/master', 'origin/a_branch'])
1280
1281 def test_shallow_multi_one_uri_depths(self):
1282 # Create initial git repo
1283 self.add_empty_file('a')
1284 self.add_empty_file('b')
1285 self.git('checkout -b a_branch', cwd=self.srcdir)
1286 self.add_empty_file('c')
1287 self.add_empty_file('d')
1288 self.git('checkout master', cwd=self.srcdir)
1262 self.add_empty_file('e') 1289 self.add_empty_file('e')
1263 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir) 1290 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1264 self.add_empty_file('f') 1291 self.add_empty_file('f')
@@ -1375,6 +1402,38 @@ class GitShallowTest(FetcherTest):
1375 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*') 1402 self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*')
1376 self.fetch() 1403 self.fetch()
1377 1404
1405 def test_shallow_remove_revs(self):
1406 # Create initial git repo
1407 self.add_empty_file('a')
1408 self.add_empty_file('b')
1409 self.git('checkout -b a_branch', cwd=self.srcdir)
1410 self.add_empty_file('c')
1411 self.add_empty_file('d')
1412 self.git('checkout master', cwd=self.srcdir)
1413 self.git('tag v0.0 a_branch', cwd=self.srcdir)
1414 self.add_empty_file('e')
1415 self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir)
1416 self.git('branch -d a_branch', cwd=self.srcdir)
1417 self.add_empty_file('f')
1418 self.assertRevCount(7, cwd=self.srcdir)
1419
1420 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1421 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1422
1423 self.fetch_shallow()
1424
1425 self.assertRevCount(5)
1426
1427 def test_shallow_invalid_revs(self):
1428 self.add_empty_file('a')
1429 self.add_empty_file('b')
1430
1431 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1432 self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0')
1433
1434 with self.assertRaises(bb.fetch2.FetchError):
1435 self.fetch()
1436
1378 if os.environ.get("BB_SKIP_NETTESTS") == "yes": 1437 if os.environ.get("BB_SKIP_NETTESTS") == "yes":
1379 print("Unset BB_SKIP_NETTESTS to run network tests") 1438 print("Unset BB_SKIP_NETTESTS to run network tests")
1380 else: 1439 else:
@@ -1383,11 +1442,16 @@ class GitShallowTest(FetcherTest):
1383 self.git('config core.bare true', cwd=self.srcdir) 1442 self.git('config core.bare true', cwd=self.srcdir)
1384 self.git('fetch --tags', cwd=self.srcdir) 1443 self.git('fetch --tags', cwd=self.srcdir)
1385 1444
1386 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '100') 1445 self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0')
1446 # Note that the 1.10.0 tag is annotated, so this also tests
1447 # reference of an annotated vs unannotated tag
1448 self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0')
1387 1449
1388 self.fetch_shallow() 1450 self.fetch_shallow()
1389 1451
1452 # Confirm that the history of 1.10.0 was removed
1390 orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines()) 1453 orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines())
1391 revs = len(self.git('rev-list master').splitlines()) 1454 revs = len(self.git('rev-list master').splitlines())
1392 self.assertNotEqual(orig_revs, revs) 1455 self.assertNotEqual(orig_revs, revs)
1393 self.assertRefs(['master', 'origin/master']) 1456 self.assertRefs(['master', 'origin/master'])
1457 self.assertRevCount(orig_revs - 1758)