-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat; implement branch change prompt
Signed-off-by: Hunter Achieng ([email protected]) Signed-off-by: Hunter Achieng <[email protected]>
- Loading branch information
1 parent
5108c25
commit c5da855
Showing
4 changed files
with
167 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { execSync } from 'node:child_process'; | ||
import inquirer from 'inquirer'; | ||
|
||
const checkIfBranchExists = (branchName: string): boolean => { | ||
try { | ||
execSync(`git rev-parse --verify ${branchName}`); | ||
return true; | ||
} catch (error) { | ||
return false; | ||
} | ||
}; | ||
|
||
const promptForBranchChange = async (adaptorName: string) => { | ||
const currentBranch = execSync('git branch --show-current').toString().trim(); | ||
|
||
if (currentBranch === 'main') { | ||
const branchExists = checkIfBranchExists(adaptorName); | ||
|
||
if (branchExists) { | ||
console.log(`Branch "${adaptorName}" already exists.`); | ||
} else { | ||
const answers = await inquirer.prompt([ | ||
{ | ||
type: 'confirm', | ||
name: 'createBranch', | ||
message: `You are on the main branch. Would you like to create and switch to a new branch named "${adaptorName}"?`, | ||
default: true, | ||
}, | ||
]); | ||
|
||
if (answers.createBranch) { | ||
execSync(`git checkout -b ${adaptorName}`); | ||
console.log(`Switched to new branch: ${adaptorName}`); | ||
} | ||
} | ||
} | ||
}; | ||
|
||
export default promptForBranchChange; |