gradle git:合并失败了,即使没有冲突
我正在使用。我定义了以下两项任务: PrepareTask.groovygradle git:合并失败了,即使没有冲突,git,gradle,groovy,Git,Gradle,Groovy,我正在使用。我定义了以下两项任务: PrepareTask.groovy class PrepareTask extends DefaultTask { public String branch private Grgit git @TaskAction public void executeTask(){ try { git = Grgit.open(dir: project.rootProject.projectDir) } catch (Re
class PrepareTask extends DefaultTask {
public String branch
private Grgit git
@TaskAction
public void executeTask(){
try {
git = Grgit.open(dir: project.rootProject.projectDir)
} catch (RepositoryNotFoundException e) {
println("Git is not available in this project.")
}
if (git){
def currentBranch = git.branch.getCurrent().getName()
if (currentBranch != branch){
git.checkout(branch: branch, createBranch: true)
}
}
}
}
class CommitTask extends DefaultTask {
public String prev_branch
public String message = "committing changes"
private Grgit git
@TaskAction
public void executeTask(){
try {
git = Grgit.open(dir: project.rootProject.projectDir)
} catch (RepositoryNotFoundException e) {
println("Git is not available in this project.")
}
if (git){
git.add(patterns: ['.'])
def commit = git.commit(message: message, all: true)
if (prev_branch){
def branch = git.branch.getCurrent().getName()
git.checkout(branch: prev_branch, createBranch: false)
git.merge(head: branch, mode: MergeOp.Mode.CREATE_COMMIT, message: "merging")
}
}
}
}
CommitTask.groovy
class PrepareTask extends DefaultTask {
public String branch
private Grgit git
@TaskAction
public void executeTask(){
try {
git = Grgit.open(dir: project.rootProject.projectDir)
} catch (RepositoryNotFoundException e) {
println("Git is not available in this project.")
}
if (git){
def currentBranch = git.branch.getCurrent().getName()
if (currentBranch != branch){
git.checkout(branch: branch, createBranch: true)
}
}
}
}
class CommitTask extends DefaultTask {
public String prev_branch
public String message = "committing changes"
private Grgit git
@TaskAction
public void executeTask(){
try {
git = Grgit.open(dir: project.rootProject.projectDir)
} catch (RepositoryNotFoundException e) {
println("Git is not available in this project.")
}
if (git){
git.add(patterns: ['.'])
def commit = git.commit(message: message, all: true)
if (prev_branch){
def branch = git.branch.getCurrent().getName()
git.checkout(branch: prev_branch, createBranch: false)
git.merge(head: branch, mode: MergeOp.Mode.CREATE_COMMIT, message: "merging")
}
}
}
}
我在gradle中有一个工作正常的updateSource
任务,我在build.gradle中设置了以下内容:
task prepare(type: PrepareTask){
branch = 'changes-branch'
}
task commit(type: CommitTask){
prev_branch = 'current-branch'
}
updateSource.dependsOn prepare
updateSource.finalizedBy commit
执行所有操作,创建并签出新分支,更新并提交源代码,然后再次签出原始分支。但当任务尝试合并分支时,失败:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':commit'.
> Problem merging.
添加--stacktrace
选项将显示:
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':commit'.
...
Caused by: org.ajoberstar.grgit.exception.GrgitException: Problem merging.
...
Caused by: org.eclipse.jgit.api.errors.CheckoutConflictException: Checkout conflict with files:
但这没有任何意义,原因有二。1.签出成功,并且2。我从一根干净的树枝开始