From e536231daf665fc2c0d303ce5d574e2599554c45 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 25 Jun 2019 20:38:44 +0200 Subject: [PATCH] phase1: add further Git clone/pull safety guards - 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 --- phase1/master.cfg | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/phase1/master.cfg b/phase1/master.cfg index 51c0262..edb4907 100644 --- a/phase1/master.cfg +++ b/phase1/master.cfg @@ -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", -- 2.30.2