From a951d9ccd13ab4a71b2e6d41969c9c4e4ccb6f52 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Fri, 14 Jul 2023 18:27:06 +0200 Subject: [PATCH] Excluded git message files from file detection --- .../gitnuro/git/FileChangesWatcher.kt | 18 ++++++++++++++++-- .../gitnuro/viewmodels/TabViewModel.kt | 4 ++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt index 3c3494f..c2f9491 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt @@ -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 + } + + matchesAnyRule || isGitIgnoredFile } - val hasGitDirChanged = paths.any { it == "$pathStr$systemSeparator.git" } + + val hasGitDirChanged = paths.any { it.startsWith("$pathStr$systemSeparator.git%$systemSeparator") } if (!areAllPathsIgnored) { _changesNotifier.emit(hasGitDirChanged) diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt index c947a83..345b5d9 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -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() }