i'm trying to build tasks to help my team. i have 2 mains branch for front & back and if the developper working on back and need to update front i want to cherry pick all commits from front and vice versa for front to back.
I'm using gradle 7.4.2
Here is my pseudocode to what i want to do :
if (${git branch --show-current} == 'front') {
def st = git cherry-pick $(git merge-base --fork-point back)..back
} else if (${git branch --show-current} == 'back') {
def st = git cherry-pick $(git merge-base --fork-point front)..front
}
But yeah, gradle don't look at that friendly ahahah
Well.. i'm badly new with gradle tasks so don't hesitate to tips me
Actually i have an error to the step to construct the request to get the commit to my final request
plugins {
id 'java'
id 'io.quarkus'
id 'base'
}
ext {
charset = 'UTF-8'
}
def current
task getGitCurrent(type: Exec) {
commandLine 'git', 'branch', '--show-current'
standardOutput = new ByteArrayOutputStream()
ext.current = {
standardOutput.toString(charset)
}
def currentRes = file("${buildDir}/current.txt")
outputs.file currentRes
doLast {
if (!buildDir.exists()) {
buildDir.mkdirs()
}
current = tasks.getGitCurrent.current()
println "current branch : ${current}"
}
}
def commitStart
task getGitCommitStart(dependsOn: 'getGitCurrent') {
doLast {
println "Branche A : ${current}"
def String notCurrent
if (current == "front") {
notCurrent = "back"
} else if (current == "back") {
notCurrent = "front"
} else notCurrent = "master"
println "Branche B : ${notCurrent}"
exec {
commandLine 'git', 'merge-base', '--fork-point', "$notCurrent"
standardOutput = new ByteArrayOutputStream()
ext.commitStartRes = {
standardOutput.toString(charset)
}
def commitStartRes = file("${buildDir}/commitStart.txt")
outputs.file commitStartRes
if (!buildDir.exists()) {
buildDir.mkdirs()
}
commitStart = tasks.getGitCommitStart.commitStart()
}
}
}
And i have this exception who correspond to the line :
outputs.file commitStartRes
* What went wrong:
Execution failed for task ':getGitCommitStart'.
> Cannot call TaskOutputs.file(Object) on task ':getGitCommitStart' after task has started execution.
I just don't understand why my task getGitCommitStart() don't working like getGitCurrent() because it gives me good results. The problem looks about doLast scope, something looks wrong but I'm a little confused, what i'm missing there ?