From e6d9c99766f02c8904bdb4a95d23416ccf2c4f37 Mon Sep 17 00:00:00 2001 From: Roy Karseboom <> Date: Fri, 25 Mar 2022 00:13:37 +0200 Subject: [PATCH 1/2] added logic --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 866bd34..a88e8eb 100755 --- a/index.js +++ b/index.js @@ -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))] } else { targetBranch = sortedBranches[switchToBranchIndex]; } @@ -277,7 +282,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) => { From 30a08a967507fa90acffe2a70a811eb40ebd49fb Mon Sep 17 00:00:00 2001 From: Roy Karseboom <> Date: Fri, 25 Mar 2022 00:29:11 +0200 Subject: [PATCH 2/2] added new feature to -h --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a88e8eb..9801176 100755 --- a/index.js +++ b/index.js @@ -243,8 +243,10 @@ async function main() { console.log(' Switching branches:'); console.log(''); console.log( - ' $ `git pr-train ` will switch to branch with index (e.g. 0 or 5). ' + - 'If is "combined", it will switch to the combined branch.' + ' $ `git pr-train ` will switch to branch with index (e.g. 0 or 5).\n' + + ' $ `git pr-train [+-]` will switch to branch with index bigger or smaller by \n' + + ' relative to the current one branch index.\n' + + ' If is "combined", it will switch to the combined branch.\n' ); console.log(''); console.log(' Creating GitHub PRs:');