gradle-git-version icon indicating copy to clipboard operation
gradle-git-version copied to clipboard

Incorrectly marking builds as dirty

Open alicederyn opened this issue 9 years ago • 14 comments

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?

alicederyn avatar Mar 30 '16 11:03 alicederyn

Ugh, yeah, not doing anything beyond asking JGit if the current repo is clean, so it's likely a JGit bug.

markelliot avatar Mar 30 '16 11:03 markelliot

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()

markelliot avatar Mar 30 '16 11:03 markelliot

@chrisalice is this still an issue for you?

markelliot avatar May 26 '16 05:05 markelliot

No idea, we left the git status workaround in place

alicederyn avatar May 26 '16 07:05 alicederyn

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

hdost avatar Oct 17 '16 17:10 hdost

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?

timothy-thomas avatar May 25 '18 21:05 timothy-thomas

any chance your repo has symlinks? we've had some jgit issues with symlinks in the past.

markelliot avatar May 28 '18 09:05 markelliot

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.

timothy-thomas avatar May 29 '18 16:05 timothy-thomas

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.

seifertm avatar Jun 06 '18 11:06 seifertm

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.

philgebhardt avatar Sep 25 '18 01:09 philgebhardt

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

RobMaskell avatar Oct 03 '20 22:10 RobMaskell

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.

wrlyonsjr avatar Jan 28 '21 16:01 wrlyonsjr

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".

baldervanx avatar Dec 08 '21 09:12 baldervanx

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.

lapo-luchini avatar Jan 31 '22 21:01 lapo-luchini