From e32498d0c7b060409792656a3a01852b98ecadc0 Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Thu, 9 Jun 2022 03:11:31 +0200 Subject: [PATCH] Fixed repo refreshing when detecting changes in message files --- src/main/kotlin/app/git/FileChangesWatcher.kt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/kotlin/app/git/FileChangesWatcher.kt b/src/main/kotlin/app/git/FileChangesWatcher.kt index c286132..a4956a2 100644 --- a/src/main/kotlin/app/git/FileChangesWatcher.kt +++ b/src/main/kotlin/app/git/FileChangesWatcher.kt @@ -58,6 +58,15 @@ class FileChangesWatcher @Inject constructor() { val hasGitDirectoryChanged = dir.startsWith("$pathStr$systemSeparator.git$systemSeparator") + if(events.count() == 1) { + val fileChanged = events.first().context().toString() + val fullPathOfFileChanged = "$pathStr$systemSeparator.git$systemSeparator$fileChanged" + + // Ignore COMMIT_EDITMSG changes + if(isGitMessageFile(pathStr, fullPathOfFileChanged)) + return@withContext + } + println("Has git dir changed: $hasGitDirectoryChanged") _changesNotifier.emit(hasGitDirectoryChanged) @@ -86,4 +95,10 @@ class FileChangesWatcher @Inject constructor() { key.reset() } } + + private fun isGitMessageFile(repoPath: String, fullPathOfFileChanged: String): Boolean { + val gitDir = "$repoPath$systemSeparator.git${systemSeparator}" + return fullPathOfFileChanged == "${gitDir}COMMIT_EDITMSG" || + fullPathOfFileChanged == "${gitDir}MERGE_MSG" + } } \ No newline at end of file