grgit icon indicating copy to clipboard operation
grgit copied to clipboard

status.isClean() always return false on Mac OS

Open aaboyd opened this issue 8 years ago • 5 comments

I call status.isClean() to check if a build is "dirty" or not and I append that in the version if it is. On Mac OS X I get dirty even when the git status command says that everything is clean.

I have the following in my build.gradle

buildscript {
   ... 
   dependencies {
        classpath 'org.ajoberstar:grgit:2.+'
    }
}

def retrieveGitVersion() {
    def git = Grgit.open(dir: rootProject.rootDir)

    String gitHash = "${git.head().getAbbreviatedId()}"
    logger.info("${gitHash} was the hash from git")
    return gitHash + ((!git.status().isClean()) ? ".dirty" : "")
}

Here is the output of git status before the build is run.

On branch dev
Your branch is up to date with 'origin/dev'.

nothing to commit, working tree clean

Whenever retrieveGitVersion is called on Linux or Windows it behaves accordingly, but on Mac OS X it comes back dirty. I was wondering if there is some bad assumption I am making or if there are some tips on what git commands might let me know what isn't actually clean.

Thanks in advance!

aaboyd avatar Nov 14 '17 19:11 aaboyd

I'd probably start by printing the git.status() out to see which files it's confused about.

task printStatus {
  doLast {
    def git = Grgit.open(dir: rootProject.rootDir)
    println git.status()
  }
}

I know there have been some issues with submodules due to JGit's mixed support for them. Not sure if that applies in your case.

ajoberstar avatar Nov 16 '17 03:11 ajoberstar

OK, I did that and noticed that .DS_Store was coming up in the changes.

Does jgit not take into account the global ignore file in git?

aaboyd avatar Nov 16 '17 21:11 aaboyd

Their source seems to imply that they look at core.excludesfile. If you're relying on something else for a global ignore file, I'm not sure if that's supported.

ajoberstar avatar Nov 17 '17 01:11 ajoberstar

Hmm, it looks like they do look at core.excludesfile, however unlike in c-git it doesn't have a default value in JGit (should be $XDG_CONFIG_HOME/git/ignore or $HOME/.config/git/ignore if XDG_CONFIG_HOME is unset).

There's a relevant bug report.

gimoh avatar Dec 23 '17 15:12 gimoh

Also https://github.com/eclipse/jgit/blob/2345cc88d0ed7b6d639ba7a1874f2200f3b21df1/org.eclipse.jgit/src/org/eclipse/jgit/util/SystemReader.java#L106 (current master) shows that it only reads ~/.gitconfig but not $XDG_CONFIG_HOME/git/config/$HOME/.config/git/config.

grossws avatar Apr 04 '21 05:04 grossws