Excluded git message files from file detection

This commit is contained in:
Abdelilah El Aissaoui 2023-07-14 18:27:06 +02:00
parent 11ca59eed9
commit a951d9ccd1
No known key found for this signature in database
GPG Key ID: 7587FC860F594869
2 changed files with 18 additions and 4 deletions

View File

@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.isActive
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.eclipse.jgit.lib.Constants
import org.eclipse.jgit.lib.Repository
import uniffi.gitnuro.WatchDirectoryNotifier
import uniffi.gitnuro.watchDirectory
@ -28,6 +29,12 @@ class FileChangesWatcher @Inject constructor(
pathStr: String
) = withContext(Dispatchers.IO) {
var ignoreRules = getIgnoreRulesUseCase(repository)
val gitDirIgnoredFiles = listOf(
Constants.COMMIT_EDITMSG,
Constants.MERGE_MSG,
Constants.SQUASH_MSG,
)
val checker = object : WatchDirectoryNotifier {
override fun shouldKeepLooping(): Boolean {
return isActive
@ -41,12 +48,19 @@ class FileChangesWatcher @Inject constructor(
}
val areAllPathsIgnored = paths.all { path ->
ignoreRules.any { rule ->
val matchesAnyRule = ignoreRules.any { rule ->
rule.isMatch(path, Files.isDirectory(Paths.get(path)))
}
val isGitIgnoredFile = gitDirIgnoredFiles.any { ignoredFile ->
"$pathStr/.git/$ignoredFile" == path
}
val hasGitDirChanged = paths.any { it == "$pathStr$systemSeparator.git" }
matchesAnyRule || isGitIgnoredFile
}
val hasGitDirChanged = paths.any { it.startsWith("$pathStr$systemSeparator.git%$systemSeparator") }
if (!areAllPathsIgnored) {
_changesNotifier.emit(hasGitDirChanged)

View File

@ -279,11 +279,11 @@ class TabViewModel @Inject constructor(
suspend fun updateApp(hasGitDirChanged: Boolean) {
if (hasGitDirChanged) {
printDebug(TAG, "Changes detected in git directory, full refresh")
printLog(TAG, "Changes detected in git directory, full refresh")
refreshRepositoryInfo()
} else {
printDebug(TAG, "Changes detected, partial refresh")
printLog(TAG, "Changes detected, partial refresh")
checkUncommitedChanges()
}