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