<commit_before>/* @flow */

const execa = require('execa');

const tasks = [
  {
    title: 'check current branch',
    skip: () => process.env.ANY_BRANCH === '1',
    task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
      if (!branch === 'master') {
        throw {
            cmd: 'not on a `master` branch',
            stderr: 'use ANY_BRANCH=1 to publish anyway',
        }
      }
    }),
  },
  {
    title: 'check local working tree',
    task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
      if (status !== '') {
        throw {
          cmd: 'unclean working tree',
          stderr: 'commit or stash changes first',
        }
      }
    }),
  },
  {
    title: 'check git tag existence',
    task: () => execa('git', ['fetch'])
    .then(() => execa.stdout('git', ['rev-parse', '--quiet', '--verify', `refs/tags/v${process.env.NEXT_VERSION}`]))
    .then(
      output => {
        if (output) {
          throw {
            cmd: `git tag \`v${process.env.NEXT_VERSION}\` already exists.`,
            stderr: 'delete tag or try again with a new version'
          }
        }
      },
      err => {
        // Command fails with code 1 and no output if the tag does not exist,
        // even though `--quiet` is provided
        // https://github.com/sindresorhus/np/pull/73#discussion_r72385685
        if (err.stdout !== '' || err.stderr !== '') {
          throw err;
        }
      }
    ),
  },
  {
    title: 'check remote history',
    task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
      if (result !== '0') {
        throw {
          cmd: 'remote history differs',
          stderr: 'please pull changes',
        }
      }
    }),
  },
];

module.exports = tasks;
<commit_msg>:bug: fix preflight git tag check<commit_after>/* @flow weak */

const execa = require('execa');

const tasks = [
  {
    title: 'check current branch',
    skip: () => process.env.ANY_BRANCH === '1',
    task: () => execa.stdout('git', ['symbolic-ref', '--short', 'HEAD']).then(branch => {
      if (!branch === 'master') {
        throw {
            cmd: 'not on a `master` branch',
            stderr: 'use ANY_BRANCH=1 to publish anyway',
        }
      }
    }),
  },
  {
    title: 'check local working tree',
    task: () => execa.stdout('git', ['status', '--porcelain']).then(status => {
      if (status !== '') {
        throw {
          cmd: 'unclean working tree',
          stderr: 'commit or stash changes first',
        }
      }
    }),
  },
  {
    title: 'check git tag existence',
    task: ctx => execa('git', ['fetch'])
    .then(() => execa.stdout('git', ['rev-parse', '--quiet', '--verify', `refs/tags/v${ctx.version}`]))
    .then(
      output => {
        if (output) {
          throw {
            cmd: `git tag \`v${ctx.version}\` already exists.`,
            stderr: 'delete tag or try again with a new version'
          }
        }
      },
      err => {
        // Command fails with code 1 and no output if the tag does not exist,
        // even though `--quiet` is provided
        // https://github.com/sindresorhus/np/pull/73#discussion_r72385685
        if (err.stdout !== '' || err.stderr !== '') {
          throw err;
        }
      }
    ),
  },
  {
    title: 'check remote history',
    task: () => execa.stdout('git', ['rev-list', '--count', '--left-only', '@{u}...HEAD']).then(result => {
      if (result !== '0') {
        throw {
          cmd: 'remote history differs',
          stderr: 'please pull changes',
        }
      }
    }),
  },
];

module.exports = tasks;

{'fraction_non_alphanumeric': 0.19310722100656455, 'fraction_numerical': 0.007658643326039387, 'mean_word_length': 1.8727415553809899, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '6716092', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1156, 'n_words': 291}