Skip to content

Commit

Permalink
in between, will have conflicts -- apply fixes to take in question
Browse files Browse the repository at this point in the history
Signed-off-by: Kipras Melnikovas <[email protected]>
  • Loading branch information
kiprasmel committed Apr 3, 2023
1 parent a31814c commit 3fb77f1
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -71,6 +71,7 @@ export async function applyIfNeedsToApply({
autoApplyIfNeeded,
isMandatoryIfMarkedAsNeeded,
config,
askQuestion = question,
...rest
}: BranchSequencerArgsBase & {
/**
Expand All @@ -88,6 +89,7 @@ export async function applyIfNeedsToApply({

autoApplyIfNeeded: boolean; //
config: Git.Config;
askQuestion: AskQuestion;
}): Promise<void> {
const needsToApply: boolean = doesNeedToApply(pathToStackedRebaseDirInsideDotGit);
if (!needsToApply) {
Expand All @@ -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";
Expand Down Expand Up @@ -139,9 +141,9 @@ export async function applyIfNeedsToApply({
}
}

const askIfCanApply = async (config: Git.Config): Promise<boolean> => {
const answer = await question(
"need to --apply before continuing. proceed? [Y/n/(a)lways] ", //
const askIfCanApply = async (config: Git.Config, askQuestion: AskQuestion = question): Promise<boolean> => {
const answer = await askQuestion(
Questions.need_to_apply_before_continuing, //
(ans) => ans.trim().toLowerCase()
);

Expand Down

0 comments on commit 3fb77f1

Please sign in to comment.