@@ -4,7 +4,7 @@ import path from "path";
44import Git from "nodegit" ;
55import { combineRewrittenLists } from "./git-reconcile-rewritten-list/combineRewrittenLists" ;
66
7- import { createQuestion } from "./util/createQuestion" ;
7+ import { question } from "./util/createQuestion" ;
88import { isDirEmptySync } from "./util/fs" ;
99
1010import { filenames } from "./filenames" ;
@@ -93,46 +93,47 @@ export async function applyIfNeedsToApply({
9393 return {
9494 neededToApply : false ,
9595 } ;
96- } else {
97- if ( ! autoApplyIfNeeded ) {
98- const question = createQuestion ( ) ;
99-
100- const answerRaw : string = await question ( "\nneed to --apply before continuing. proceed? [Y/n/(a)lways] " ) ;
101- console . log ( { answerRaw } ) ;
102-
103- const answer : string = answerRaw . trim ( ) . toLowerCase ( ) ;
104-
105- const userAllowedToApply : boolean = [ "y" , "yes" , "" ] . includes ( answer ) ;
106- console . log ( { userAllowedToApply } ) ;
107-
108- const userAllowedToApplyAlways : boolean = [ "a" , "always" ] . includes ( answer ) ;
109-
110- if ( ! userAllowedToApply && ! userAllowedToApplyAlways ) {
111- return {
112- neededToApply : true ,
113- userAllowedToApplyAndWeApplied : false ,
114- } ;
115- }
116-
117- if ( userAllowedToApplyAlways ) {
118- await config . setBool ( configKeys . autoApplyIfNeeded , 1 ) ;
119- }
120- }
96+ }
12197
122- await apply ( {
123- repo ,
124- pathToStackedRebaseTodoFile ,
125- pathToStackedRebaseDirInsideDotGit , //
126- ... rest ,
127- } ) ;
98+ const allowedToApply = autoApplyIfNeeded || ( await askIfCanApply ( config ) ) ;
99+ if ( ! allowedToApply ) {
100+ return {
101+ neededToApply : true ,
102+ userAllowedToApplyAndWeApplied : false ,
103+ } ;
128104 }
129105
106+ await apply ( {
107+ repo,
108+ pathToStackedRebaseTodoFile,
109+ pathToStackedRebaseDirInsideDotGit, //
110+ ...rest ,
111+ } ) ;
112+
130113 return {
131114 neededToApply : true ,
132115 userAllowedToApplyAndWeApplied : true , //
133116 } ;
134117}
135118
119+ const askIfCanApply = async ( config : Git . Config ) : Promise < boolean > => {
120+ const answer = await question (
121+ "need to --apply before continuing. proceed? [Y/n/(a)lways] " , //
122+ ( ans ) => ans . trim ( ) . toLowerCase ( )
123+ ) ;
124+
125+ const userAllowedToApply : boolean = [ "y" , "yes" , "" ] . includes ( answer ) ;
126+ const userAllowedToApplyAlways : boolean = [ "a" , "always" ] . includes ( answer ) ;
127+
128+ if ( userAllowedToApplyAlways ) {
129+ await config . setBool ( configKeys . autoApplyIfNeeded , 1 ) ;
130+ }
131+
132+ const canApply = userAllowedToApply || userAllowedToApplyAlways ;
133+
134+ return canApply ;
135+ } ;
136+
136137const getPaths = (
137138 pathToStackedRebaseDirInsideDotGit : string //
138139) =>
0 commit comments