From e7b86d95226095c5f2f601b6e08a6710705aa942 Mon Sep 17 00:00:00 2001 From: Dan Hawkins Date: Thu, 1 Aug 2019 08:55:18 +0100 Subject: [PATCH] Perform a shallow clone check on repos being used to generate version numbers --- versioncontrol/git.groovy | 15 +++++++++++++++ versionnumbering/generate.groovy | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/versioncontrol/git.groovy b/versioncontrol/git.groovy index 3ea97ec..0e27faf 100644 --- a/versioncontrol/git.groovy +++ b/versioncontrol/git.groovy @@ -4,6 +4,21 @@ import hudson.plugins.git.extensions.impl.* clh = load("${autobuilder.commonscripts()}/commandline/commandline.groovy") +def boolean isShallowClonedRepo(String gitrootpath) { + def boolean isshallowclone = true + + dir( gitrootpath) { + if (isUnix()) { + isshallowclone = sh(returnStdout: true, script: "git rev-parse --is-shallow-repository").trim().toBoolean() + } + else { + isshallowclone = bat(returnStdout: true, script: "@git rev-parse --is-shallow-repository").trim().toBoolean() + } + echo "Repo at ${gitrootpath} is shallow cloned: Change count: ${isshallowclone}" + } + return isshallowclone +} + String getGitInfo(String workingSetRootPath) { dir(workingSetRootPath) { return clh.getCommandOutput('git rev-parse HEAD') diff --git a/versionnumbering/generate.groovy b/versionnumbering/generate.groovy index f4f1bdc..2e4f60d 100644 --- a/versionnumbering/generate.groovy +++ b/versionnumbering/generate.groovy @@ -1,4 +1,5 @@ - +gh = load("${autobuilder.commonscripts()}/versioncontrol/git.groovy") + def int maxversionnumber() { def int MAXVERSIONNUMBER = 65535 return MAXVERSIONNUMBER @@ -15,6 +16,12 @@ def getGitRevision(String gitrootpath, int basebuildnumber) { def String gitrevision def String remoteinfo def String remoteurl + + def boolean isShallowCloned = gh.isShallowClonedRepo(gitrootpath) + if (isShallowCloned) { + error("Cannot generate a version number from a shallow cloned repo at ${gitrootpath}") + } + dir( gitrootpath) { def int changecount = 0 if (isUnix()) {