import { getCurrentBranchName, getRemotes } from '../../lib/git.ts';
import { exec, OutputMode } from '../../dependencies/exec.ts';
import { getBranchRemote } from '../../lib/git/getBranchRemote.ts';

interface Args {
  force: boolean,

  // Test thingies
  isTestRun: boolean,
}

export const command = 'thrust';
export const aliases = [ 't' ];
export const describe = 'Pushes local changes to a remote';

export async function builder (yargs: any) {
  return yargs.usage('usage: gut thrust [options]')
    .option('force', {
      alias: 'f',
      describe: 'Force the push. This erases concurrent server-modifications',
      type: 'boolean',
    });
}

export async function handler ({ force, isTestRun }: Args) {
  const remotes = await getRemotes();
  const remoteOfTrackedBranch = await getBranchRemote();
  const currentBranchName = await getCurrentBranchName();
  const remote = remotes[ 0 ]; // TODO: prompt user when there are multiple remotes

  const forceArg = force ? '--force-with-lease' : '';
  const setUpstreamArg = remoteOfTrackedBranch ? `--set-upstream ${remote}` : '';
  const outputMode = isTestRun ? OutputMode.Capture : OutputMode.StdOut;
  return exec(`git push ${forceArg} ${setUpstreamArg} ${currentBranchName}`, { output: outputMode });
}

export const test = {};

import { getCurrentBranchName, getRemotes } from '../../lib/git.ts';
import { exec, OutputMode } from '../../dependencies/exec.ts';
import { getBranchRemote } from '../../lib/git/getBranchRemote.ts';

interface Args {
  force: boolean,

  // Test thingies
  isTestRun: boolean,
}

export const command = 'thrust';
export const aliases = [ 't' ];
export const describe = 'Pushes local changes to a remote';

export async function builder (yargs: any) {
  return yargs.usage('usage: gut thrust [options]')
    .option('force', {
      alias: 'f',
      describe: 'Force the push. This erases concurrent server-modifications',
      type: 'boolean',
    });
}

export async function handler ({ force, isTestRun }: Args) {
  const remotes = await getRemotes();
  const remoteOfTrackedBranch = await getBranchRemote();
  const currentBranchName = await getCurrentBranchName();
  const remote = remotes[ 0 ]; // TODO: prompt user when there are multiple remotes

  const forceArg = force ? '--force-with-lease' : '';
  const setUpstreamArg = remoteOfTrackedBranch ? '' : `--set-upstream ${remote}`;
  const outputMode = isTestRun ? OutputMode.Capture : OutputMode.StdOut;
  return exec(`git push ${forceArg} ${setUpstreamArg} ${currentBranchName}`, { output: outputMode });
}

export const test = {};

Fix set upstream conditional inversion
:bug: Fix set upstream conditional inversion
