Fixed repo refreshing when detecting changes in message files

This commit is contained in:
Abdelilah El Aissaoui 2022-06-09 03:11:31 +02:00
parent 8f2598d866
commit e32498d0c7

View File

@ -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"
}
}