gradle-git-version
gradle-git-version copied to clipboard
Incorrectly marking builds as dirty
gradle-git-version is incorrectly marking my builds as dirty. After some experimentation, I discovered adding git status to circle.yml immediately before the broken build magically fixes it. I then ls-ed the entire workspace before and after git status, and discovered the .git/index file is being updated. According to https://www.kernel.org/pub/software/scm/git/docs/technical/racy-git.txt, the index file is maintained lazily, and git needs to verify the state of the world when determining the status. Presumably jgit is just a broken git implementation in this regard?
Ugh, yeah, not doing anything beyond asking JGit if the current repo is clean, so it's likely a JGit bug.
For improved debug, one thing we could do is add logging or another function that will return more details about what JGit status is using to decide what's dirty.
In particular, if you have a good repro of this, it'd be really helpful to print additional details to confirm its the index file using something like:
Git git = Git.wrap(new FileRepository(".git")
Status status = git.status().call()
println "clean " + status.isClean()
println "added " + status.getAdded()
println "changed " + status.getChanged()
println "conflicting " + status.getConflicting()
println "missing " + status.getMissing()
println "modified " + status.getModified()
println "removed " + status.getRemoved()
println "untracked " + status.getUntracked()
@chrisalice is this still an issue for you?
No idea, we left the git status workaround in place
Looks like a bug that likely won't be resolved, since it's 2 years old https://bugs.eclipse.org/bugs/show_bug.cgi?id=452189
I am having some trouble with this gradle-git-version marking all my builds as dirty. I have
plugins {
id "org.jenkins-ci.jpi" version '0.26.0'
id 'com.palantir.git-version' version '0.12.0-rc2'
}
...
version gitVersion(prefix: 'my-plugin-')
in my build.gradle but the generated version for my generated Jenkins plugin per the MANIFEST.MF is Plugin-Version: 1.3.dirty, and
$ git describe --tags --always --first-parent --match "my-plugin-*"
my-plugin-1.3
git status comes up clean. Any ideas?
any chance your repo has symlinks? we've had some jgit issues with symlinks in the past.
It seems my problem was that I had untracked files. Git describe doesn't mind untracked files, but apparently the jgit version does. For me this was solved by adding them to the .gitignore file.
I didn't see this in the Usage section of the repository's README.md; I would recommend adding this caveat to the documentation for clarity.
I ran into the same problem: gradle-git-version-0.12.0-rc2 marked all my builds a dirty. This kept happening even after I removed all untracked files or added them to .gitignore. At this point the printVersion task still appended a .dirty suffix to the project version.
As it turned out, the plugin does not respect global gitignore settings. I am using a global gitignore file in order to prevent IDE-specific files such as .idea/ from being commited. Only when I added those to the project's local .gitignore file the versioning worked as expected.
I ran into this problem on a repository that had a de-initialized submodule. After running git submodule init, JGit (and this plugin) started to return a clean result.
Came up against this same issue today, and can't use the workaround easily had to abandon using the plugin which is a shame as it did exactly what I was after. I realise it's Jgit's problem really just letting you know
I just encountered the same thing. What happened to me was Jenkins was creating untracked directories suffixed with @tmp which were left empty but not being deleted. I wonder if JGit sees these empty dirs as changes when git status does not? The problem went away after moving that stuff under a dir that was in .gitignore.
For me the problem was that Jenkins was setting the execution bit on gradlew. This of course made git see the workspace as dirty. Since our development environment is Windows based it was not obvious how to fix this. But git supports setting the file mode using "git add --chmod=+x".
I my case it was because I did git clone on Windows via WSL, which supports file permissions and thus sets .git/config like this:
[core]
repositoryformatversion = 0
filemode = false
while Gradle used the Windows permissions (can't see the WSL ones, which are in some kind of extended attribute on NTFS); so I fix this "constantly dirty" problem by setting filemode = false in .git/config.