old_contents: /* @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;
  
new_contents: /* @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;
  
subject: fix preflight git tag check