From 7e6ccbe8104e8db27b3bc187f9cec9bfa80b0593 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Wed, 27 Sep 2023 12:45:48 +0200 Subject: [PATCH] Fixed .git dir changes not being detected properly and added rule to ignore .proble files in git dir --- rs/src/watch_directory.rs | 2 +- .../com/jetpackduba/gitnuro/git/FileChangesWatcher.kt | 11 +++++++---- .../jetpackduba/gitnuro/viewmodels/TabViewModel.kt | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rs/src/watch_directory.rs b/rs/src/watch_directory.rs index 34b8452..81850a4 100644 --- a/rs/src/watch_directory.rs +++ b/rs/src/watch_directory.rs @@ -36,7 +36,7 @@ pub fn watch_directory( } Err(e) => { if e != RecvTimeoutError::Timeout { - println!("Watch error: {:?}", e) + println!("Watch error: {:?}", e); } } } diff --git a/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt b/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt index 1793dbd..e359d8b 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/git/FileChangesWatcher.kt @@ -48,18 +48,21 @@ class FileChangesWatcher @Inject constructor( } val areAllPathsIgnored = paths.all { path -> - val matchesAnyRule = ignoreRules.any { rule -> + val matchesAnyIgnoreRule = ignoreRules.any { rule -> rule.isMatch(path, Files.isDirectory(Paths.get(path))) } val isGitIgnoredFile = gitDirIgnoredFiles.any { ignoredFile -> - "$pathStr/.git/$ignoredFile" == path + "$pathStr$systemSeparator.git$systemSeparator$ignoredFile" == path } - matchesAnyRule || isGitIgnoredFile + // JGit may create .probe-UUID files for its internal stuff, we should not care about it + val onlyProbeFiles = paths.all { it.contains("$systemSeparator.git$systemSeparator.probe-") } + + matchesAnyIgnoreRule || isGitIgnoredFile || onlyProbeFiles } - val hasGitDirChanged = paths.any { it.startsWith("$pathStr$systemSeparator.git%$systemSeparator") } + 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 06b4bea..3c0e8ed 100644 --- a/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt +++ b/src/main/kotlin/com/jetpackduba/gitnuro/viewmodels/TabViewModel.kt @@ -279,7 +279,7 @@ class TabViewModel @Inject constructor( } } - suspend fun updateApp(hasGitDirChanged: Boolean) { + private suspend fun updateApp(hasGitDirChanged: Boolean) { if (hasGitDirChanged) { printLog(TAG, "Changes detected in git directory, full refresh")