-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from Evleaps/feature/new-specified-branch-commit
Feature/new specified branch commit
- Loading branch information
Showing
9 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...n/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitMergeBase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 SpecifiedBranchCommitMergeBase(private val specifiedBranch: String) : CommitShaProvider { | ||
|
||
override fun get(commandRunner: GitClient.CommandRunner): Sha { | ||
val currentBranch = commandRunner.executeAndParseFirst(CURRENT_BRANCH_CMD) | ||
return commandRunner.executeAndParseFirst("git merge-base $currentBranch $specifiedBranch") | ||
} | ||
|
||
companion object { | ||
|
||
const val CURRENT_BRANCH_CMD = "git rev-parse --abbrev-ref HEAD" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...m/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommitMergeBaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.dropbox.affectedmoduledetector.commitshaproviders | ||
|
||
import com.dropbox.affectedmoduledetector.AttachLogsTestRule | ||
import com.dropbox.affectedmoduledetector.mocks.MockCommandRunner | ||
import com.google.common.truth.Truth | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
|
||
@RunWith(JUnit4::class) | ||
class SpecifiedBranchCommitMergeBaseTest { | ||
|
||
@Rule | ||
@JvmField | ||
val attachLogsRule = AttachLogsTestRule() | ||
private val logger = attachLogsRule.logger | ||
private val commandRunner = MockCommandRunner(logger) | ||
private val previousCommit = SpecifiedBranchCommitMergeBase(SPECIFIED_BRANCH) | ||
|
||
@Test | ||
fun `WHEN CURRENT_BRANCH_CMD THEN command returned`() { | ||
Truth.assertThat(SpecifiedBranchCommitMergeBase.CURRENT_BRANCH_CMD).isEqualTo("git rev-parse --abbrev-ref HEAD") | ||
} | ||
|
||
@Test | ||
fun `WHEN get commit sha THEN return sha`() { | ||
|
||
commandRunner.addReply(SpecifiedBranchCommitMergeBase.CURRENT_BRANCH_CMD, NEW_FEATURE_BRANCH) | ||
commandRunner.addReply("git merge-base $NEW_FEATURE_BRANCH $SPECIFIED_BRANCH", "commit-sha") | ||
|
||
val actual = previousCommit.get(commandRunner) | ||
|
||
Truth.assertThat(actual).isEqualTo("commit-sha") | ||
} | ||
|
||
private companion object { | ||
|
||
const val SPECIFIED_BRANCH = "origin/dev" | ||
const val NEW_FEATURE_BRANCH = "newFeatureBranch" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.