From 3fb77f1c531bcdc925823ac052d798ee00289139 Mon Sep 17 00:00:00 2001 From: Kipras Melnikovas Date: Mon, 3 Apr 2023 12:35:30 +0300 Subject: [PATCH] in between, will have conflicts -- apply fixes to take in question Signed-off-by: Kipras Melnikovas --- apply.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/apply.ts b/apply.ts index 2c6596a9..17fc022c 100644 --- a/apply.ts +++ b/apply.ts @@ -4,7 +4,7 @@ import path from "path"; import Git from "nodegit"; import { combineRewrittenLists } from "./git-reconcile-rewritten-list/combineRewrittenLists"; -import { question } from "./util/createQuestion"; +import { AskQuestion, question, Questions } from "./util/createQuestion"; import { isDirEmptySync } from "./util/fs"; import { Termination } from "./util/error"; @@ -71,6 +71,7 @@ export async function applyIfNeedsToApply({ autoApplyIfNeeded, isMandatoryIfMarkedAsNeeded, config, + askQuestion = question, ...rest }: BranchSequencerArgsBase & { /** @@ -88,6 +89,7 @@ export async function applyIfNeedsToApply({ autoApplyIfNeeded: boolean; // config: Git.Config; + askQuestion: AskQuestion; }): Promise { const needsToApply: boolean = doesNeedToApply(pathToStackedRebaseDirInsideDotGit); if (!needsToApply) { @@ -99,7 +101,7 @@ export async function applyIfNeedsToApply({ * is marked as needed to apply, * and is mandatory -- try to get a confirmation that it is ok to apply. */ - const userAllowedToApply = autoApplyIfNeeded || (await askIfCanApply(config)); + const userAllowedToApply = autoApplyIfNeeded || (await askIfCanApply(config, askQuestion)); if (!userAllowedToApply) { const msg = "\ncannot continue without mandatory --apply. Exiting.\n"; @@ -139,9 +141,9 @@ export async function applyIfNeedsToApply({ } } -const askIfCanApply = async (config: Git.Config): Promise => { - const answer = await question( - "need to --apply before continuing. proceed? [Y/n/(a)lways] ", // +const askIfCanApply = async (config: Git.Config, askQuestion: AskQuestion = question): Promise => { + const answer = await askQuestion( + Questions.need_to_apply_before_continuing, // (ans) => ans.trim().toLowerCase() );