Skip to content

Commit 55ace64

Browse files
committed
added SpecifiedBranchCommit with git-merge command
1 parent e09ed5b commit 55ace64

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ affectedModuleDetector {
112112
- `compareFrom`: A commit to compare the branch changes against. Can be either:
113113
- PreviousCommit: compare against the previous commit
114114
- ForkCommit: compare against the commit the branch was forked from
115-
- SpecifiedBranchCommit: specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
115+
- SpecifiedBranchCommit: compare against the last commit of `$specifiedBranch` using `git rev-parse` approach.
116+
- SpecifiedBranchCommit2: compare against the nearest ancestors with `$specifiedBranch` using `git merge base` approach.
117+
118+
**Note:** specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
116119
- `excludedModules`: A list of modules that will be excluded from the build process
117120
- `includeUncommitted`: If uncommitted files should be considered affected
118121
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/CommitShaProvider.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.dropbox.affectedmoduledetector.GitClient
44
import com.dropbox.affectedmoduledetector.Sha
55

66
interface CommitShaProvider {
7+
78
fun get(commandRunner: GitClient.CommandRunner): Sha
89

910
companion object {
@@ -17,9 +18,14 @@ interface CommitShaProvider {
1718
}
1819
SpecifiedBranchCommit(specifiedBranch)
1920
}
21+
"SpecifiedBranchCommit2" -> {
22+
requireNotNull(specifiedBranch) {
23+
"Specified branch must be defined"
24+
}
25+
SpecifiedBranchCommit2(specifiedBranch)
26+
}
2027
else -> throw IllegalArgumentException("Unsupported compareFrom type")
2128
}
2229
}
2330
}
2431
}
25-
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.dropbox.affectedmoduledetector.commitshaproviders
2+
3+
import com.dropbox.affectedmoduledetector.GitClient
4+
import com.dropbox.affectedmoduledetector.Sha
5+
6+
class SpecifiedBranchCommit2(private val branch: String) : CommitShaProvider {
7+
8+
override fun get(commandRunner: GitClient.CommandRunner): Sha {
9+
val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD)
10+
return commandRunner.executeAndParseFirst("git merge-base $currentBranch $branch")
11+
}
12+
13+
companion object {
14+
15+
const val CURRENT_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD"
16+
}
17+
}

0 commit comments

Comments
 (0)