@@ -19,8 +19,8 @@ import { createExecSyncInRepo } from "./util/execSyncInRepo";
1919import { noop } from "./util/noop" ;
2020import { uniq } from "./util/uniq" ;
2121import { parseTodoOfStackedRebase } from "./parse-todo-of-stacked-rebase/parseTodoOfStackedRebase" ;
22- import { processWriteAndOrExit , fail , EitherExitFinal } from "./util/Exitable " ;
23- import { namesOfRebaseCommandsThatMakeRebaseExitToPause } from "./parse-todo-of-stacked-rebase/validator" ;
22+ import { Termination } from "./util/error " ;
23+ import { GoodCommand , namesOfRebaseCommandsThatMakeRebaseExitToPause } from "./parse-todo-of-stacked-rebase/validator" ;
2424
2525// console.log = () => {};
2626
@@ -84,7 +84,7 @@ function areOptionsIncompetible(
8484export const gitStackedRebase = async (
8585 nameOfInitialBranch : string ,
8686 specifiedOptions : SomeOptionsForGitStackedRebase = { }
87- ) : Promise < EitherExitFinal > => {
87+ ) : Promise < void > => {
8888 try {
8989 const options : OptionsForGitStackedRebase = {
9090 ...getDefaultOptions ( ) , //
@@ -95,7 +95,7 @@ export const gitStackedRebase = async (
9595 const reasonsWhatWhyIncompatible : string [ ] = [ ] ;
9696
9797 if ( areOptionsIncompetible ( options , reasonsWhatWhyIncompatible ) ) {
98- return fail (
98+ throw new Termination (
9999 "\n" +
100100 bullets (
101101 "error - incompatible options:" , //
@@ -195,7 +195,7 @@ export const gitStackedRebase = async (
195195
196196 if ( options . push ) {
197197 if ( ! options . forcePush ) {
198- return fail ( "\npush without --force will fail (since git rebase overrides history).\n\n" ) ;
198+ throw new Termination ( "\npush without --force will fail (since git rebase overrides history).\n\n" ) ;
199199 }
200200
201201 return await forcePush ( {
@@ -225,7 +225,7 @@ export const gitStackedRebase = async (
225225 * to branchSequencer later.
226226 */
227227
228- return fail ( "\n--branch-sequencer (without --exec) - nothing to do?\n\n" ) ;
228+ throw new Termination ( "\n--branch-sequencer (without --exec) - nothing to do?\n\n" ) ;
229229 }
230230 }
231231
@@ -273,8 +273,7 @@ export const gitStackedRebase = async (
273273
274274 const regularRebaseTodoLines : string [ ] = [ ] ;
275275
276- const [ exit , goodCommands ] = parseTodoOfStackedRebase ( pathToStackedRebaseTodoFile ) ;
277- if ( ! goodCommands ) return fail ( exit ) ;
276+ const goodCommands : GoodCommand [ ] = parseTodoOfStackedRebase ( pathToStackedRebaseTodoFile ) ;
278277
279278 const proms : Promise < void > [ ] = goodCommands . map ( async ( cmd ) => {
280279 if ( cmd . rebaseKind === "regular" ) {
@@ -646,8 +645,7 @@ cat "$REWRITTEN_LIST_FILE_PATH" > "$REWRITTEN_LIST_BACKUP_FILE_PATH"
646645
647646 return ;
648647 } catch ( e ) {
649- console . error ( e ) ;
650- return fail ( e ) ;
648+ throw e ; // TODO FIXME - no try/catch at all?
651649 }
652650} ;
653651
@@ -949,7 +947,7 @@ async function getCommitOfBranch(repo: Git.Repository, branchReference: Git.Refe
949947/**
950948 * the CLI
951949 */
952- export async function git_stacked_rebase ( ) : Promise < EitherExitFinal > {
950+ export async function git_stacked_rebase ( ) : Promise < void > {
953951 const pkgFromSrc = path . join ( __dirname , "package.json" ) ;
954952 const pkgFromDist = path . join ( __dirname , "../" , "package.json" ) ;
955953 let pkg ;
@@ -1058,7 +1056,9 @@ git-stacked-rebase ${gitStackedRebaseVersionStr}
10581056 console . log ( { "process.argv after non-positional" : process . argv } ) ;
10591057
10601058 const nameOfInitialBranch : string | undefined = eatNextArg ( ) ;
1061- if ( ! nameOfInitialBranch ) return fail ( helpMsg ) ;
1059+ if ( ! nameOfInitialBranch ) {
1060+ throw new Termination ( helpMsg ) ;
1061+ }
10621062
10631063 /**
10641064 * TODO: improve arg parsing, lmao
@@ -1112,17 +1112,19 @@ git-stacked-rebase ${gitStackedRebaseVersionStr}
11121112 const fourth = eatNextArg ( ) ;
11131113 branchSequencerExec = fourth ? fourth : false ;
11141114 } else {
1115- return fail ( `\n--branch-sequencer can only (for now) be followed by ${ execNames . join ( "|" ) } \n\n` ) ;
1115+ throw new Termination (
1116+ `\n--branch-sequencer can only (for now) be followed by ${ execNames . join ( "|" ) } \n\n`
1117+ ) ;
11161118 }
11171119 }
11181120
11191121 if ( ! isForcePush && ! branchSequencerExec ) {
1120- return fail ( `\nunrecognized 3th option (got "${ third } ")\n\n` ) ;
1122+ throw new Termination ( `\nunrecognized 3th option (got "${ third } ")\n\n` ) ;
11211123 }
11221124 }
11231125
11241126 if ( process . argv . length ) {
1125- return fail (
1127+ throw new Termination (
11261128 "" + //
11271129 "\n" +
11281130 bullets ( "\nerror - leftover arguments: " , process . argv , " " ) +
@@ -1146,5 +1148,15 @@ git-stacked-rebase ${gitStackedRebaseVersionStr}
11461148
11471149if ( ! module . parent ) {
11481150 git_stacked_rebase ( ) //
1149- . then ( processWriteAndOrExit ) ;
1151+ . then ( ( ) => process . exit ( 0 ) )
1152+ . catch ( ( e ) => {
1153+ if ( e instanceof Termination ) {
1154+ process . stderr . write ( e . message ) ;
1155+ process . exit ( 1 ) ;
1156+ } else {
1157+ console . error ( e ) ;
1158+ process . exit ( 1 ) ;
1159+ // throw e;
1160+ }
1161+ } ) ;
11501162}
0 commit comments