- Notifications
You must be signed in to change notification settings - Fork 49
Feature/new specified branch commit #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
joshafeinberg merged 7 commits into dropbox:main from Evleaps:feature/new-specified-branch-commit Nov 1, 2022
Merged
Changes from 4 commits
Commits
Show all changes
7 commits Select commit Hold shift + click to select a range
55ace64 added SpecifiedBranchCommit with git-merge command
Evleaps cbf13ea added explanation in readme
Evleaps 30842e4 Merge branch 'main' into feature/new-specified-branch-commit
Evleaps 476fe77 added tests
Evleaps dd7eff4 deleted extra mock
Evleaps 0f16ade Merge branch 'main' into feature/new-specified-branch-commit
Evleaps 06b84e0 rename SpecifiedBranchCommit2 to SpecifiedBranchCommitMergeBase
Evleaps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 ...in/kotlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit2.kt
This file contains hidden or 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 SpecifiedBranchCommit2(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 hidden or 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 hidden or 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 hidden or 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 ...otlin/com/dropbox/affectedmoduledetector/commitshaproviders/SpecifiedBranchCommit2Test.kt
This file contains hidden or 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 SpecifiedBranchCommit2Test { | ||
| | ||
| @Rule | ||
| @JvmField | ||
| val attachLogsRule = AttachLogsTestRule() | ||
| private val logger = attachLogsRule.logger | ||
| private val commandRunner = MockCommandRunner(logger) | ||
| private val previousCommit = SpecifiedBranchCommit2(SPECIFIED_BRANCH) | ||
| | ||
| @Test | ||
| fun `WHEN CURRENT_BRANCH_CMD THEN command returned`() { | ||
| Truth.assertThat(SpecifiedBranchCommit2.CURRENT_BRANCH_CMD).isEqualTo("git rev-parse --abbrev-ref HEAD") | ||
| } | ||
| | ||
| @Test | ||
| fun `WHEN get commit sha THEN return sha`() { | ||
| | ||
| commandRunner.addReply(SpecifiedBranchCommit2.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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please try to think of a better name for this? I understand naming is hard but adding
2to the end doesn't explain much and makes it a bit confusingUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I really agree with u. I thought about it but can't make it better.
I considered
SpecifiedBranchCommitMergeBaseandSpecifiedBranchCommit2plus explanation in
readme.mdin both cases.What do u think about
SpecifiedBranchCommitMergeBase? Or, maybe can u suggest another name?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SpecifiedBranchCommitMergeBase works for me