From 692bdc596fe6c96dd5bdd8131e2532d631888979 Mon Sep 17 00:00:00 2001 From: Vladislav Ermolin Date: Mon, 29 Dec 2025 22:38:49 +0200 Subject: [PATCH 1/2] Normalize Git-Relative paths to Project-Relative paths. Addresses regression from https://github.com/dropbox/AffectedModuleDetector/pull/270. Makes paths resolve correctly in repositories, where root project dir and Git rood dir do not match. This fixes https://github.com/dropbox/AffectedModuleDetector/issues/292 --- .../AffectedModuleDetector.kt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt index aac4a48..eacae0d 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt @@ -658,8 +658,17 @@ class AffectedModuleDetectorImpl( } private fun findContainingProject(filePath: String): ProjectPath? { - return projectGraph.findContainingProject(filePath, logger).also { - logger?.info("search result for $filePath resulted in ${it?.path}") + // Normalize the file path from git-relative to project-relative + val rootProjectDir = if (config.baseDir != null) { + File(config.baseDir!!) + } else { + File(projectGraph.getRootProjectPath()!!.path) + } + val pathSections = filePath.toPathSections(rootProjectDir, gitRoot) + val projectRelativePath = pathSections.joinToString(File.separatorChar.toString()) + + return projectGraph.findContainingProject(projectRelativePath, logger).also { + logger?.info("search result for $filePath (normalized to $projectRelativePath) resulted in ${it?.path}") } } } From 75903f23d95ac514adb12cc8d9aef20155bdca4a Mon Sep 17 00:00:00 2001 From: Vladislav Ermolin Date: Mon, 29 Dec 2025 22:56:09 +0200 Subject: [PATCH 2/2] Reduce code duplication --- .../AffectedModuleDetector.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt index eacae0d..5f891ed 100644 --- a/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt +++ b/affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt @@ -646,11 +646,9 @@ class AffectedModuleDetectorImpl( } private fun affectsAllModules(relativeFilePath: String): Boolean { - val rootProjectDir = if (config.baseDir != null) { - File(config.baseDir!!) - } else { - File(projectGraph.getRootProjectPath()!!.path) - } + val rootProjectDir = getRootProjectDir() + + // Normalize the file path from git-relative to project-relative val pathSections = relativeFilePath.toPathSections(rootProjectDir, gitRoot) val projectRelativePath = pathSections.joinToString(File.separatorChar.toString()) @@ -658,12 +656,9 @@ class AffectedModuleDetectorImpl( } private fun findContainingProject(filePath: String): ProjectPath? { + val rootProjectDir = getRootProjectDir() + // Normalize the file path from git-relative to project-relative - val rootProjectDir = if (config.baseDir != null) { - File(config.baseDir!!) - } else { - File(projectGraph.getRootProjectPath()!!.path) - } val pathSections = filePath.toPathSections(rootProjectDir, gitRoot) val projectRelativePath = pathSections.joinToString(File.separatorChar.toString()) @@ -671,6 +666,14 @@ class AffectedModuleDetectorImpl( logger?.info("search result for $filePath (normalized to $projectRelativePath) resulted in ${it?.path}") } } + + private fun getRootProjectDir(): File { + return if (config.baseDir != null) { + File(config.baseDir!!) + } else { + File(projectGraph.getRootProjectPath()!!.path) + } + } } val Project.isRoot get() = this == rootProject