我第一次尝试在我的一个项目上设置这个,我很好奇为什么在我做了一个grgit.add()
.
我的build.gradle
task gitCommit {
group = "Custom"
description = "Commits the version build number changes to Git"
doLast{
VersionTracker.setPropertiesFile(versionPropertiesFilePath)
def appBuildVersion = VersionTracker.getBuild()
def commitMessage= "Incremented build number; " + appBuildVersion
try
{
logger.lifecycle("Commiting to Git")
logger.lifecycle("Before add:\n${grgit.status()}\n")
// Adds all tracked files to staging for commit
grgit.add(patterns: ["AndroidManifest.xml", "assets/version.properties"], update: true)
logger.lifecycle("After add:\n${grgit.status()}\n")
// Commits the tracked changes to the local repo
grgit.commit(message: commitMessage)
logger.lifecycle("After commit:\n${grgit.status()}")
// Pushes the changes to the remote repo
grgit.push()
}
catch (Exception e)
{
logger.error("Failed...", e)
}
finally
{
logger.lifecycle("Git connection closed")
// grgit.close()
}
}
}
过程
在运行脚本之前,我运行以下命令:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
然后我运行一个 gradle 脚本来提升版本,我得到了这个:
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: AndroidManifest.xml
modified: assets/version.properties
no changes added to commit (use "git add" and/or "git commit -a")
然后我运行gradle gitCommit
上面的脚本,它输出以下内容:
Commiting to Git
Before add:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])
After add:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])
After commit:
org.ajoberstar.grgit.Status(staged:org.ajoberstar.grgit.Status$Changes(added:[],modified:[], removed:[]), unstaged:org.ajoberstar.grgit.Status$Changes(added:[], modified: [Development/Android/AndroidManifest.xml, Development/Android/build.gradle, Development/Android/assets/version.properties, Development/Android/build.gradle, Development/Android/build.gradle], removed:[]), conflicts:[])
BUILD SUCCESSFUL in 9s
1 actionable task: 1 executed
但是,我再试git status
一次,得到这个:
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: AndroidManifest.xml
modified: assets/version.properties
no changes added to commit (use "git add" and/or "git commit -a")
我看到我领先于 master 1 次提交(经过一些测试,这是一个空提交),并且仍然有未暂存的更改提交。任何想法如何解决这个问题并让 grgit 实际提交到 repo,甚至添加更改以进行提交?