Try to get sparse checkout to work with lfs
This commit is contained in:
parent
6b9f624770
commit
a6cdcccb12
2 changed files with 63 additions and 35 deletions
|
|
@ -83,7 +83,7 @@ def getcomponentartifacts(releaseinfo, String repofolder, String tempfolder, ite
|
|||
}
|
||||
if (publishablepaths.size() > 0) {
|
||||
def reporootsuffix = guessreporootsuffix(componentURL)
|
||||
gh.gitCheckout(componentURL, revision, repofolder, reporootsuffix, 1, true, publishablepaths) // Shallow clone
|
||||
gh.gitCheckoutAlt(componentURL, revision, repofolder, reporootsuffix, 1, true, publishablepaths) // Shallow clone
|
||||
}
|
||||
else {
|
||||
summaryappend("None ")
|
||||
|
|
|
|||
|
|
@ -90,37 +90,6 @@ def checkgitlfsinstall() {
|
|||
}
|
||||
}
|
||||
|
||||
def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
checkgitlfsinstall()
|
||||
def reporootpath = checkouttoreporoot(gitURL)
|
||||
if (!sparseitemlist.isEmpty()) {
|
||||
def itemstring = "Items in sparse item list:\n"
|
||||
for (item in sparseitemlist) {
|
||||
itemstring += item + "\n"
|
||||
}
|
||||
echo itemstring
|
||||
}
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
userRemoteConfigs: [
|
||||
[url: gitURL]
|
||||
],
|
||||
branches: [
|
||||
[name: revision]
|
||||
],
|
||||
doGenerateSubmoduleConfigurations: false,
|
||||
extensions: [
|
||||
[$class: 'GitLFSPull'],
|
||||
[$class: 'CleanBeforeCheckout'],
|
||||
[$class: 'CloneOption', depth: cloneDepth, noTags: false, reference: reporootpath, shallow: shallowClone, timeout: 120],
|
||||
[$class: 'CheckoutOption', timeout: 120],
|
||||
[$class: 'RelativeTargetDirectory', relativeTargetDir: targetDir],
|
||||
[$class: 'SparseCheckoutPaths', sparseCheckoutPaths: sparsecheckoutconfig(sparseitemlist)],
|
||||
],
|
||||
submoduleCfg: [],
|
||||
])
|
||||
}
|
||||
|
||||
//No credentials specified
|
||||
//Cloning the remote Git repository
|
||||
//Cloning repository git@hydra:print-server-releases/print_server_whole.git
|
||||
|
|
@ -174,10 +143,12 @@ def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repo
|
|||
// Commit message: "2.10180.7389.21125_3"
|
||||
// > git rev-list --no-walk d0788d22622862e441c5995a22629846573c39f3 # timeout=10
|
||||
|
||||
// gitCheckout (below) cannot handle sparse checkout and lfs at the moment - see https://issues.jenkins-ci.org/browse/JENKINS-43427 - see gitCheckoutAlt()
|
||||
def gitCheckout(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
def String lfsinstallandreporoot(String gitURL) {
|
||||
checkgitlfsinstall()
|
||||
def reporootpath = checkouttoreporoot(gitURL)
|
||||
return checkouttoreporoot(gitURL)
|
||||
}
|
||||
|
||||
def showsparseitemlist(ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
if (!sparseitemlist.isEmpty()) {
|
||||
def itemstring = "Items in sparse item list:\n"
|
||||
for (item in sparseitemlist) {
|
||||
|
|
@ -185,6 +156,9 @@ def gitCheckout(String gitURL, String revision, String targetDir, String repoRoo
|
|||
}
|
||||
echo itemstring
|
||||
}
|
||||
}
|
||||
|
||||
def docheckout(String gitURL, String revision, int cloneDepth, String reporootpath, boolean shallowClone, String targetDir, sparseitemlist) {
|
||||
checkout([
|
||||
$class: 'GitSCM',
|
||||
userRemoteConfigs: [
|
||||
|
|
@ -206,6 +180,60 @@ def gitCheckout(String gitURL, String revision, String targetDir, String repoRoo
|
|||
])
|
||||
}
|
||||
|
||||
// gitCheckout (below) cannot handle sparse checkout and lfs at the moment - see https://issues.jenkins-ci.org/browse/JENKINS-43427 - see gitCheckoutAlt()
|
||||
def gitCheckout(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
def String reporootpath = lfsinstallandreporoot(gitURL)
|
||||
showsparseitemlist(sparseitemlist)
|
||||
docheckout(gitURL, revision, cloneDepth, reporootpath, shallowClone, targetDir, sparseitemlist)
|
||||
}
|
||||
|
||||
def gitinit(String targetDir, String reporootpath) {
|
||||
if (!fileExists("${targetDir}/.git")) { // Git folder does not already exist
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
git init "${targetDir}"
|
||||
"""
|
||||
} else {
|
||||
bat """
|
||||
git init "${targetDir}"
|
||||
"""
|
||||
}
|
||||
dir("${targetDir}/.git/objects/info") {
|
||||
writeFile(file: 'alternates', text: "${reporootpath}/.git/objects")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def setlfsfetchinclude(String targetDir, ArrayList<String> sparseitemlist) {
|
||||
def String sparseitemliststring = ""
|
||||
if (!sparseitemlist.isEmpty()) {
|
||||
for (item in sparseitemlist) {
|
||||
sparseitemliststring += "${item},"
|
||||
}
|
||||
dir(targetDir) {
|
||||
if (isUnix()) {
|
||||
sh """
|
||||
git config lfs.fetchinclude "${sparseitemliststring}"
|
||||
"""
|
||||
} else {
|
||||
bat """
|
||||
git config lfs.fetchinclude "${sparseitemliststring}"
|
||||
"""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def gitCheckoutAlt(String gitURL, String revision, String targetDir, String repoRootSuffix = "", int cloneDepth = 1, boolean shallowClone = true, ArrayList<String> sparseitemlist = new ArrayList<String>()) {
|
||||
def String reporootpath = lfsinstallandreporoot(gitURL)
|
||||
showsparseitemlist(sparseitemlist)
|
||||
if (!sparseitemlist.isEmpty()) {
|
||||
gitinit(targetDir, reporootpath)
|
||||
setlfsfetchinclude(targetDir, sparseitemlist)
|
||||
}
|
||||
docheckout(gitURL, revision, cloneDepth, reporootpath, shallowClone, targetDir, sparseitemlist)
|
||||
}
|
||||
|
||||
def checkRepoExists(String gitURL) {
|
||||
def int result = 0
|
||||
if (isUnix()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue