Perform a shallow clone check on repos being used to generate version numbers

This commit is contained in:
Dan Hawkins 2019-08-01 08:55:18 +01:00
commit e7b86d9522
2 changed files with 23 additions and 1 deletions

View file

@ -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')

View file

@ -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()) {