<commit_before>import { getCurrentBranchName, getRemotes } from '../../lib/git.ts';

import log from '../../dependencies/log.ts';
import { promptConfirm } from '../../dependencies/cliffy.ts';
import { exec, OutputMode } from '../../dependencies/exec.ts';

interface Args {
  noPull: boolean,
  force: boolean,

  // Test thingies
  isTestRun: boolean,
}

export const command = 'yield';
export const aliases = [ 'y' ];
export const describe = 'Fetches from git server';

export async function builder (yargs: any) {
  const forceArgument = 'force';
  const noPullArgument = 'no-pull';
  return yargs.usage(`usage: gut ${command} [options]`)
    .option(noPullArgument, {
      alias: 'p',
      describe: 'Do not pull the changes to the current branch',
      type: 'boolean',
      default: false,
    })
    .option(forceArgument, {
      alias: 'f',
      describe: 'Whether the pulling of a branch should be forced or not',
      type: 'boolean',
      default: false,
    })
    .check((args: Args) => {
      if (args.force && !args.noPull) {
        throw Error(`Arguments --${forceArgument} & --${noPullArgument} are mutually exclusive`);
      }

      return true;
    });
}

export async function handler (args: Args) {
  const { noPull, force } = args;

  const remotes = await getRemotes();
  const currentBranchName = await getCurrentBranchName();
  const remote = remotes[ 0 ]; // TODO: prompt user when there are multiple remotes

  await log(Deno.stdout, `Fetching ${remote}`);
  await exec(`git fetch ${remote}`, { output: OutputMode.StdOut });

  if (noPull) { return; }

  if (force) {
    const shouldForcePull = await promptConfirm({});

    if (!shouldForcePull) {
      await log(Deno.stdout, 'Operation aborted');
      return;
    }
    await exec(`git reset --hard "${remote}/${currentBranchName}"`);
    return;
  }

  await exec(`git rebase "${remote}/${currentBranchName}"`);
}

export const test = {};<commit_msg>:bug: Fix yield command with force pull<commit_after>import { getCurrentBranchName, getRemotes } from '../../lib/git.ts';

import log from '../../dependencies/log.ts';
import { promptConfirm } from '../../dependencies/cliffy.ts';
import { exec, OutputMode } from '../../dependencies/exec.ts';

interface Args {
  noPull: boolean,
  force: boolean,

  // Test thingies
  isTestRun: boolean,
}

export const command = 'yield';
export const aliases = [ 'y' ];
export const describe = 'Fetches from git server';

export async function builder (yargs: any) {
  const forceArgument = 'force';
  const noPullArgument = 'no-pull';
  return yargs.usage(`usage: gut ${command} [options]`)
    .option(noPullArgument, {
      alias: 'p',
      describe: 'Do not pull the changes to the current branch',
      type: 'boolean',
      default: false,
    })
    .option(forceArgument, {
      alias: 'f',
      describe: 'Whether the pulling of a branch should be forced or not',
      type: 'boolean',
      default: false,
    })
    .check((args: Args) => {
      if (args.force && !args.noPull) {
        throw Error(`Arguments --${forceArgument} & --${noPullArgument} are mutually exclusive`);
      }

      return true;
    });
}

export async function handler (args: Args) {
  const { noPull, force } = args;

  const remotes = await getRemotes();
  const currentBranchName = await getCurrentBranchName();
  const remote = remotes[ 0 ]; // TODO: prompt user when there are multiple remotes

  await log(Deno.stdout, `Fetching ${remote}`);
  await exec(`git fetch ${remote}`, { output: OutputMode.StdOut });

  if (noPull) { return; }

  if (force) {
    const shouldForcePull = await promptConfirm({
      message: 'Do you want to overwrite your local branch ?',
      default: false,
    });

    if (!shouldForcePull) {
      await log(Deno.stdout, 'Operation aborted');
      return;
    }
    await exec(`git reset --hard "${remote}/${currentBranchName}"`);
    return;
  }

  await exec(`git rebase "${remote}/${currentBranchName}"`);
}

export const test = {};
{'fraction_non_alphanumeric': 0.1481018981018981, 'fraction_numerical': 0.0004995004995004995, 'mean_word_length': 3.1893305439330546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6932623', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1206, 'n_words': 375}