-
Notifications
You must be signed in to change notification settings - Fork 19
added support for relative branch change #40
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
Open
royKarseboom
wants to merge
2
commits into
realyze:master
Choose a base branch
from
royKarseboom:feature/relative_branch_change
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -148,14 +148,19 @@ function getCombinedBranch(branchConfig) { | |||||||||||||||||||||
| return branchName; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| async function handleSwitchToBranchCommand(sg, sortedBranches, combinedBranch) { | ||||||||||||||||||||||
| async function handleSwitchToBranchCommand(sg, currentBranch, sortedBranches, combinedBranch) { | ||||||||||||||||||||||
| const switchToBranchIndex = program.args[0]; | ||||||||||||||||||||||
| if (typeof switchToBranchIndex === 'undefined') { | ||||||||||||||||||||||
| return; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| let targetBranch; | ||||||||||||||||||||||
| let currentBranchIndex = sortedBranches.indexOf(currentBranch) | ||||||||||||||||||||||
| if (switchToBranchIndex === 'combined') { | ||||||||||||||||||||||
| targetBranch = combinedBranch; | ||||||||||||||||||||||
| } else if (switchToBranchIndex.startsWith("+")) { | ||||||||||||||||||||||
| targetBranch = sortedBranches[currentBranchIndex + parseInt(switchToBranchIndex.slice(1))] | ||||||||||||||||||||||
| } else if (switchToBranchIndex.startsWith("-")) { | ||||||||||||||||||||||
| targetBranch = sortedBranches[currentBranchIndex - parseInt(switchToBranchIndex.slice(1))] | ||||||||||||||||||||||
|
Comment on lines
+160
to
+163
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have not accounted for index out of bounds errors because the provided argument is larger than the number of branches in the chain.
Suggested change
|
||||||||||||||||||||||
| } else { | ||||||||||||||||||||||
| targetBranch = sortedBranches[switchToBranchIndex]; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
@@ -238,8 +243,10 @@ async function main() { | |||||||||||||||||||||
| console.log(' Switching branches:'); | ||||||||||||||||||||||
| console.log(''); | ||||||||||||||||||||||
| console.log( | ||||||||||||||||||||||
| ' $ `git pr-train <index>` will switch to branch with index <index> (e.g. 0 or 5). ' + | ||||||||||||||||||||||
| 'If <index> is "combined", it will switch to the combined branch.' | ||||||||||||||||||||||
| ' $ `git pr-train <index>` will switch to branch with index <index> (e.g. 0 or 5).\n' + | ||||||||||||||||||||||
| ' $ `git pr-train [+-]<index>` will switch to branch with index bigger or smaller by <index>\n' + | ||||||||||||||||||||||
| ' relative to the current one branch index.\n' + | ||||||||||||||||||||||
| ' If <index> is "combined", it will switch to the combined branch.\n' | ||||||||||||||||||||||
| ); | ||||||||||||||||||||||
| console.log(''); | ||||||||||||||||||||||
| console.log(' Creating GitHub PRs:'); | ||||||||||||||||||||||
|
|
@@ -277,7 +284,7 @@ async function main() { | |||||||||||||||||||||
| await sg.raw(['branch', combinedTrainBranch, lastBranchBeforeCombined]); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| await handleSwitchToBranchCommand(sg, sortedTrainBranches, combinedTrainBranch); | ||||||||||||||||||||||
| await handleSwitchToBranchCommand(sg, currentBranch, sortedTrainBranches, combinedTrainBranch); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| console.log(`I've found these partial branches:`); | ||||||||||||||||||||||
| const branchesToPrint = sortedTrainBranches.map((b, idx) => { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
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.
When contributing to another repository, it is important to maintain the existing style. You are free to adopt whatever style you like in your own repos.
In this case, the repo uses semicolons, so all your changes should do the same.