@@ -101,6 +101,68 @@ export type ReturnOfApplyIfNeedsToApply = {
101101 userAllowedToApplyAndWeApplied : true ;
102102 }
103103) ;
104+ export async function applyIfNeedsToApply ( {
105+ repo,
106+ pathToStackedRebaseTodoFile,
107+ pathToStackedRebaseDirInsideDotGit, //
108+ autoApplyIfNeeded,
109+ config,
110+ ...rest
111+ } : BranchSequencerArgsBase & {
112+ autoApplyIfNeeded : boolean ; //
113+ config : Git . Config ;
114+ } ) : Promise < ReturnOfApplyIfNeedsToApply > {
115+ const needsToApply : boolean = doesNeedToApply ( pathToStackedRebaseDirInsideDotGit ) ;
116+ const _markThatNeedsToApply = ( ) : void => markThatNeedsToApply ( pathToStackedRebaseDirInsideDotGit ) ;
117+
118+ if ( ! needsToApply ) {
119+ return {
120+ neededToApply : false ,
121+ markThatNeedsToApply : _markThatNeedsToApply ,
122+ } ;
123+ }
124+
125+ if ( needsToApply ) {
126+ if ( ! autoApplyIfNeeded ) {
127+ const question = createQuestion ( ) ;
128+
129+ const answerRaw : string = await question ( "\nneed to --apply before continuing. proceed? [Y/n/(a)lways] " ) ;
130+ console . log ( { answerRaw } ) ;
131+
132+ const answer : string = answerRaw . trim ( ) . toLowerCase ( ) ;
133+
134+ const userAllowedToApply : boolean = [ "y" , "yes" , "" ] . includes ( answer ) ;
135+ console . log ( { userAllowedToApply } ) ;
136+
137+ const userAllowedToApplyAlways : boolean = [ "a" , "always" ] . includes ( answer ) ;
138+
139+ if ( ! userAllowedToApply && ! userAllowedToApplyAlways ) {
140+ return {
141+ neededToApply : true ,
142+ userAllowedToApplyAndWeApplied : false ,
143+ markThatNeedsToApply : _markThatNeedsToApply ,
144+ } ;
145+ }
146+
147+ if ( userAllowedToApplyAlways ) {
148+ await config . setBool ( configKeys . autoApplyIfNeeded , 1 ) ;
149+ }
150+ }
151+
152+ await apply ( {
153+ repo,
154+ pathToStackedRebaseTodoFile,
155+ pathToStackedRebaseDirInsideDotGit, //
156+ ...rest ,
157+ } ) ;
158+ }
159+
160+ return {
161+ neededToApply : true ,
162+ userAllowedToApplyAndWeApplied : true , //
163+ markThatNeedsToApply : _markThatNeedsToApply ,
164+ } ;
165+ }
104166
105167const getPaths = (
106168 pathToStackedRebaseDirInsideDotGit : string //
@@ -197,66 +259,3 @@ export function readRewrittenListNotAppliedOrAppliedOrError(
197259 combinedRewrittenListLines : combinedRewrittenList . split ( "\n" ) . filter ( ( line ) => ! ! line ) ,
198260 } ;
199261}
200-
201- export async function applyIfNeedsToApply ( {
202- repo,
203- pathToStackedRebaseTodoFile,
204- pathToStackedRebaseDirInsideDotGit, //
205- autoApplyIfNeeded,
206- config,
207- ...rest
208- } : BranchSequencerArgsBase & {
209- autoApplyIfNeeded : boolean ; //
210- config : Git . Config ;
211- } ) : Promise < ReturnOfApplyIfNeedsToApply > {
212- const needsToApply : boolean = doesNeedToApply ( pathToStackedRebaseDirInsideDotGit ) ;
213- const _markThatNeedsToApply = ( ) : void => markThatNeedsToApply ( pathToStackedRebaseDirInsideDotGit ) ;
214-
215- if ( ! needsToApply ) {
216- return {
217- neededToApply : false ,
218- markThatNeedsToApply : _markThatNeedsToApply ,
219- } ;
220- }
221-
222- if ( needsToApply ) {
223- if ( ! autoApplyIfNeeded ) {
224- const question = createQuestion ( ) ;
225-
226- const answerRaw : string = await question ( "\nneed to --apply before continuing. proceed? [Y/n/(a)lways] " ) ;
227- console . log ( { answerRaw } ) ;
228-
229- const answer : string = answerRaw . trim ( ) . toLowerCase ( ) ;
230-
231- const userAllowedToApply : boolean = [ "y" , "yes" , "" ] . includes ( answer ) ;
232- console . log ( { userAllowedToApply } ) ;
233-
234- const userAllowedToApplyAlways : boolean = [ "a" , "always" ] . includes ( answer ) ;
235-
236- if ( ! userAllowedToApply && ! userAllowedToApplyAlways ) {
237- return {
238- neededToApply : true ,
239- userAllowedToApplyAndWeApplied : false ,
240- markThatNeedsToApply : _markThatNeedsToApply ,
241- } ;
242- }
243-
244- if ( userAllowedToApplyAlways ) {
245- await config . setBool ( configKeys . autoApplyIfNeeded , 1 ) ;
246- }
247- }
248-
249- await apply ( {
250- repo,
251- pathToStackedRebaseTodoFile,
252- pathToStackedRebaseDirInsideDotGit, //
253- ...rest ,
254- } ) ;
255- }
256-
257- return {
258- neededToApply : true ,
259- userAllowedToApplyAndWeApplied : true , //
260- markThatNeedsToApply : _markThatNeedsToApply ,
261- } ;
262- }
0 commit comments