phase1: add further Git clone/pull safety guards
authorJo-Philipp Wich <jo@mein.io>
Tue, 25 Jun 2019 18:38:44 +0000 (20:38 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 25 Jun 2019 18:38:44 +0000 (20:38 +0200)
- Ensure that we're on a valid branch before invoking buildbot Git()
- Verify that we did end up on a proper branch or tag after clone/pull

Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
phase1/master.cfg

index 51c0262abbca6a3dfae930823a111eddc262ef75..edb490707caedf79cf50b11df9049ba3a8e4ff00 100644 (file)
@@ -535,6 +535,14 @@ for target in targets:
                        doStepIf = IsMakeCleanRequested(tuple[0])
                ))
 
+       # Workaround bug when switching from a checked out tag back to a branch
+       # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
+       factory.addStep(ShellCommand(
+               name = "gitcheckout",
+               description = "Ensure that Git HEAD is sane",
+               command = "if [ -d .git ]; then git checkout master; else exit 0; fi",
+               haltOnFailure = True))
+
        # check out the source
        # Git() runs:
          # if repo doesn't exist: 'git clone repourl'
@@ -579,6 +587,14 @@ for target in targets:
                doStepIf = IsTaggingRequested
        ))
 
+       # Verify that Git HEAD points to a tag or branch
+       # Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-June/017809.html
+       factory.addStep(ShellCommand(
+               name = "gitverify",
+               description = "Ensure that Git HEAD is pointing to a branch or tag",
+               command = 'git rev-parse --abbrev-ref HEAD | grep -vxqF HEAD || git show-ref --tags --dereference 2>/dev/null | sed -ne "/^$(git rev-parse HEAD) / { s|^.*/||; s|\\^.*||; p }" | grep -qE "^v[0-9][0-9]\\."',
+               haltOnFailure = True))
+
        factory.addStep(ShellCommand(
                name = "rmtmp",
                description = "Remove tmp folder",