<commit_before>import {getActionPipelineManager} from './action-pipeline';
import {GitError} from './git-shell-out-strategy';

export default function(controller, {confirm, notificationManager}) {
  const pipelineManager = getActionPipelineManager();
  const pushPipeline = pipelineManager.getPipeline(pipelineManager.actionKeys.PUSH);
  pushPipeline.addMiddleware('confirm-force-push', (next, repository, branchName, options) => {
    if (options.force) {
      const choice = confirm({
        message: 'Are you sure you want to force push?',
        detailedMessage: 'This operation could result in losing data on the remote.',
        buttons: ['Force Push', 'Cancel Push'],
      });
      if (choice !== 0) { return null; } else { return next(); }
    } else {
      return next();
    }
  });
  pushPipeline.addMiddleware('set-push-in-progress', async (next, repository, branchName, options) => {
    repository.setOperationProgressState('push', true);
    await next();
    repository.setOperationProgressState('push', false);
  });
  pushPipeline.addMiddleware('failed-to-push-error', async (next, repository, branchName, options) => {
    try {
      const result = await next();
      return result;
    } catch (error) {
      if (!(error instanceof GitError)) { throw error; }
      if (/rejected[\s\S]*failed to push/.test(error.stdErr)) {
        notificationManager.addError('Push rejected', {
          description: 'The tip of your current branch is behind its remote counterpart.' +
            ' Try pulling before pushing again. Or, to force push, hold `cmd` or `ctrl` while clicking.',
          dismissable: true,
        });
      } else {
        console.error(error);
        notificationManager.addError('Unable to push', {
          description: `<pre>${error.stdErr}</pre>`,
          dismissable: true,<commit_msg>Make 'confirm-force-push' middleware return a promise<commit_after>import {getActionPipelineManager} from './action-pipeline';
import {GitError} from './git-shell-out-strategy';

export default function(controller, {confirm, notificationManager}) {
  const pipelineManager = getActionPipelineManager();
  const pushPipeline = pipelineManager.getPipeline(pipelineManager.actionKeys.PUSH);
  pushPipeline.addMiddleware('confirm-force-push', async (next, repository, branchName, options) => {
    if (options.force) {
      const choice = confirm({
        message: 'Are you sure you want to force push?',
        detailedMessage: 'This operation could result in losing data on the remote.',
        buttons: ['Force Push', 'Cancel Push'],
      });
      if (choice !== 0) { /* do nothing */ } else { await next(); }
    } else {
      await next();
    }
  });
  pushPipeline.addMiddleware('set-push-in-progress', async (next, repository, branchName, options) => {
    repository.setOperationProgressState('push', true);
    await next();
    repository.setOperationProgressState('push', false);
  });
  pushPipeline.addMiddleware('failed-to-push-error', async (next, repository, branchName, options) => {
    try {
      const result = await next();
      return result;
    } catch (error) {
      if (!(error instanceof GitError)) { throw error; }
      if (/rejected[\s\S]*failed to push/.test(error.stdErr)) {
        notificationManager.addError('Push rejected', {
          description: 'The tip of your current branch is behind its remote counterpart.' +
            ' Try pulling before pushing again. Or, to force push, hold `cmd` or `ctrl` while clicking.',
          dismissable: true,
        });
      } else {
        console.error(error);
        notificationManager.addError('Unable to push', {
          description: `<pre>${error.stdErr}</pre>`,
          dismissable: true,
{'fraction_non_alphanumeric': 0.1319593147751606, 'fraction_numerical': 0.0005353319057815846, 'mean_word_length': 3.3202312138728325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 13, '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': '3934438', 'n_tokens_mistral': 985, 'n_tokens_neox': 987, 'n_words': 289}