All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fetch2: Sanity check SRCREV matches rev/tag parameter
@ 2014-01-20 15:20 Richard Purdie
  0 siblings, 0 replies; only message in thread
From: Richard Purdie @ 2014-01-20 15:20 UTC (permalink / raw)
  To: bitbake-devel

Add a sanity check so that if some SRCREV is set and a rev parameter is given
to the url, the revision given should match.

Any tag parameter behaves the same as rev. If both are specified, error to
tell the user we're confused rather than do something which may or may not
be what they intended.

Also add some unittests for this.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index 4af089d..b4717c4 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -867,12 +867,6 @@ def srcrev_internal_helper(ud, d, name):
         c) None if not specified
     """
 
-    if 'rev' in ud.parm:
-        return ud.parm['rev']
-
-    if 'tag' in ud.parm:
-        return ud.parm['tag']
-
     srcrev = None
     pn = d.getVar("PN", True)
     attempts = []
@@ -889,6 +883,20 @@ def srcrev_internal_helper(ud, d, name):
         if srcrev and srcrev != "INVALID":
             break
 
+    if 'rev' in ud.parm and 'tag' in ud.parm:
+        raise FetchError("Please specify a ;rev= parameter or a ;tag= parameter in the url %s but not both." % (ud.url))
+
+    if 'rev' in ud.parm or 'tag' in ud.parm:
+        if 'rev' in ud.parm:
+            parmrev = ud.parm['rev']
+        else:
+            parmrev = ud.parm['tag']
+        if srcrev == "INVALID" or not srcrev:
+            return parmrev
+        if srcrev != parmrev:
+            raise FetchError("Conflicting revisions (%s from SRCREV and %s from the url) found, please spcify one valid value" % (srcrev, parmrev))
+        return parmrev
+
     rev = srcrev
     if rev == "INVALID" or not rev:
         var = "SRCREV_pn-%s" % pn
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index 4bcff54..eaab0de 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -382,6 +382,21 @@ class FetcherNetworkTest(FetcherTest):
             url1 = url2 = "git://git.openembedded.org/bitbake"
             self.gitfetcher(url1, url2)
 
+        def test_gitfetch_goodsrcrev(self):
+            # SRCREV is set but matches rev= parameter
+            url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
+            self.gitfetcher(url1, url2)
+
+        def test_gitfetch_badsrcrev(self):
+            # SRCREV is set but does not match rev= parameter
+            url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5"
+            self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
+
+        def test_gitfetch_tagandrev(self):
+            # SRCREV is set but does not match rev= parameter
+            url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5"
+            self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2)
+
         def test_gitfetch_premirror(self):
             url1 = "git://git.openembedded.org/bitbake"
             url2 = "git://someserver.org/bitbake"




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2014-01-20 15:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-20 15:20 [PATCH] fetch2: Sanity check SRCREV matches rev/tag parameter Richard Purdie

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.