Skip to content

Commit

Permalink
added SpecifiedBranchCommit with git-merge command
Browse files Browse the repository at this point in the history
  • Loading branch information
Evleaps committed Aug 28, 2022
1 parent e09ed5b commit 55ace64
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ affectedModuleDetector {
- `compareFrom`: A commit to compare the branch changes against. Can be either:
- PreviousCommit: compare against the previous commit
- ForkCommit: compare against the commit the branch was forked from
- SpecifiedBranchCommit: specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
- SpecifiedBranchCommit: compare against the last commit of `$specifiedBranch` using `git rev-parse` approach.
- SpecifiedBranchCommit2: compare against the nearest ancestors with `$specifiedBranch` using `git merge base` approach.

**Note:** specify the branch to compare changes against using the `specifiedBranch` configuration before the `compareFrom` configuration
- `excludedModules`: A list of modules that will be excluded from the build process
- `includeUncommitted`: If uncommitted files should be considered affected
- `top`: The top of the git log to use. Must be used in combination with configuration `includeUncommitted = false`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha

interface CommitShaProvider {

fun get(commandRunner: GitClient.CommandRunner): Sha

companion object {
Expand All @@ -17,9 +18,14 @@ interface CommitShaProvider {
}
SpecifiedBranchCommit(specifiedBranch)
}
"SpecifiedBranchCommit2" -> {
requireNotNull(specifiedBranch) {
"Specified branch must be defined"
}
SpecifiedBranchCommit2(specifiedBranch)
}
else -> throw IllegalArgumentException("Unsupported compareFrom type")
}
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.dropbox.affectedmoduledetector.commitshaproviders

import com.dropbox.affectedmoduledetector.GitClient
import com.dropbox.affectedmoduledetector.Sha

class SpecifiedBranchCommit2(private val branch: String) : CommitShaProvider {

override fun get(commandRunner: GitClient.CommandRunner): Sha {
val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD)
return commandRunner.executeAndParseFirst("git merge-base $currentBranch $branch")
}

companion object {

const val CURRENT_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD"
}
}

0 comments on commit 55ace64

Please sign in to comment.