Skip to main content



      Home
Home » Eclipse Projects » EGit / JGit » [solved] jgit returns incorrect status
[solved] jgit returns incorrect status [message #1862653] Mon, 18 December 2023 09:45 Go to next message
Eclipse UserFriend
I use `git.status().call().hasUncommittedChanges()` to check checks for uncommitted changes in a repo.
It started returning `false` even though my repo status was clean (checked via `git status` command in the terminal), so I added some debugging info to the function:

```kotlin
override val hasUncommittedChanges: () -> Boolean = {
println(git.repository.workTree)
val status = git.status().call()
System.out.println("Added: " + status.getAdded())
System.out.println("Changed: " + status.getChanged())
System.out.println("Conflicting: " + status.getConflicting())
System.out.println("ConflictingStageState: " + status.getConflictingStageState())
System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex())
System.out.println("Missing: " + status.getMissing())
System.out.println("Modified: " + status.getModified())
System.out.println("Removed: " + status.getRemoved())
System.out.println("Untracked: " + status.getUntracked())
System.out.println("UntrackedFolders: " + status.getUntrackedFolders())

ProcessBuilder()
.directory(git.repository.workTree)
.command("git", "status")
.start()
.also {
it.waitFor(30, TimeUnit.SECONDS)
val ist = it.inputStream
val r1 = BufferedReader(InputStreamReader(ist))
println(r1.readText())
}

git.status().call().hasUncommittedChanges()
}
```

And what I see is that status returns a lot of `missing` and some `untracked` files. This is the output I'm getting in the project from running the above code:

```
2023-12-18T15:20:51.738+0100 [QUIET] [system.out] /home/sergio/Projects/personal/personal/semver.kt
2023-12-18T15:20:51.754+0100 [QUIET] [system.out] Added: []
2023-12-18T15:20:51.754+0100 [QUIET] [system.out] Changed: []
2023-12-18T15:20:51.754+0100 [QUIET] [system.out] Conflicting: []
2023-12-18T15:20:51.754+0100 [QUIET] [system.out] ConflictingStageState: {}
2023-12-18T15:20:51.754+0100 [QUIET] [system.out] IgnoredNotInIndex: [.gradle, .idea]
2023-12-18T15:20:51.755+0100 [QUIET] [system.out] Missing: [release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/ConfigurationProvider.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/configuration/DslConfigurationTest.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/Increment.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/configuration/DefaultConfigurationTest.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/MonorepoConfig.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/repo/RepositoryTest.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/Configuration.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/configuration/PropertiesConfigurationTest.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/GitTagConfig.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/repo/Repository.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/repo/Extensions.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/GitMessageConfig.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/VersionConfig.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/GitConfig.kt, release/README.md, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/DslConfiguration.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/repo/Commit.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/repo/GitRepository.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/TestFixtures.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/repo/ExtensionsTest.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/SemverReleaseTest.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/SemverRelease.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/configuration/GitRepoConfig.kt, release/src/main/kotlin/io/github/serpro69/semverkt/release/ext/CollectionExtensions.kt, release/src/test/kotlin/io/github/serpro69/semverkt/release/configuration/JsonConfigurationTest.kt, release/build.gradle.kts, release/src/test/kotlin/io/github/serpro69/semverkt/release/repo/GitRepositoryTest.kt]
2023-12-18T15:20:51.755+0100 [QUIET] [system.out] Modified: []
2023-12-18T15:20:51.755+0100 [QUIET] [system.out] Removed: []
2023-12-18T15:20:51.755+0100 [QUIET] [system.out] Untracked: [release]
2023-12-18T15:20:51.755+0100 [QUIET] [system.out] UntrackedFolders: []
...
2023-12-18T15:20:51.760+0100 [QUIET] [system.out] On branch master
2023-12-18T15:20:51.760+0100 [QUIET] [system.out] Your branch is ahead of 'origin/master' by 3 commits.
2023-12-18T15:20:51.760+0100 [QUIET] [system.out] (use "git push" to publish your local commits)
2023-12-18T15:20:51.760+0100 [QUIET] [system.out]
2023-12-18T15:20:51.760+0100 [QUIET] [system.out] nothing to commit, working tree clean
2023-12-18T15:20:51.760+0100 [QUIET] [system.out]
```

(Note that the last part of the output is the result of running native `git status` command in the same git working tree)

I'm not entirely sure why this happens.
I also noticed that on a fresh clone of a repo everything works just fine:
```
2023-12-18T15:35:03.537+0100 [QUIET] [system.out] /tmp/tmp.YbYBsYnAw7
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Added: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Changed: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Conflicting: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] ConflictingStageState: {}
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] IgnoredNotInIndex: [.gradle]
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Missing: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Modified: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Removed: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] Untracked: []
2023-12-18T15:35:03.545+0100 [QUIET] [system.out] UntrackedFolders: []
2023-12-18T15:35:03.550+0100 [QUIET] [system.out] On branch master
2023-12-18T15:35:03.550+0100 [QUIET] [system.out] Your branch is ahead of 'origin/master' by 1 commit.
2023-12-18T15:35:03.550+0100 [QUIET] [system.out] (use "git push" to publish your local commits)
2023-12-18T15:35:03.550+0100 [QUIET] [system.out]
2023-12-18T15:35:03.550+0100 [QUIET] [system.out] nothing to commit, working tree clean
2023-12-18T15:35:03.550+0100 [QUIET] [system.out]

```

But after awhile something is getting cached or IDK what, and then it starts reporting wrong status.
I think this happens after I'm running the tests in the repo (at least this is what I noticed now on a freshly cloned repo instance), so it must be some cache or smth similar.

I'm not sure how to debug this further, or what could be causing this. Would appreciate any help.

This is the code that checks for status (w/o the debugging println bits): https://github.com/serpro69/semver.kt/blob/5c950f30a0e75915a4a720887d4b9f03704beb9d/release/src/main/kotlin/io/github/serpro69/semverkt/release/repo/GitRepository.kt#L74
(not sure if this is useful though)

[Updated on: Tue, 19 December 2023 02:18] by Moderator

Re: jgit returns incorrect status [message #1862654 is a reply to message #1862653] Tue, 19 December 2023 02:17 Go to previous message
Eclipse UserFriend
So I have narrowed it down to a test that was doing `Git.init().setGitDir(tempDir)` instead of `...setDirectory(tempDir)` .
Even though that was incorrect, I'm not entirely sure how doing that from a test against a temp directory would affect the git status of another repo.

[Updated on: Tue, 19 December 2023 02:19] by Moderator

Previous Topic:ssh password dialog on each git interaction since eclipse 2023-09
Next Topic:"Clean" Included Tracked Files
Goto Forum:
  


Current Time: Fri May 16 18:10:46 EDT 2025

Powered by FUDForum. Page generated in 0.04057 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top