|
| 1 | +import { $ } from 'bun' |
| 2 | +import { existsSync } from 'fs' |
| 3 | + |
| 4 | +import { logger, setExitCode } from '../context' |
| 5 | +import { string } from '../strings' |
| 6 | + |
| 7 | +export const execute = async () => { |
| 8 | + const mode = StuckModes.find(([_, file]) => existsSync(file)) |
| 9 | + |
| 10 | + if (!mode) { |
| 11 | + setExitCode(1) |
| 12 | + logger.error(string('command.abort.notStuck')) |
| 13 | + return |
| 14 | + } |
| 15 | + |
| 16 | + logger.info(string(`command.abort.action.${mode[0] as StuckMode}`)) |
| 17 | + logger.newline() |
| 18 | + |
| 19 | + await $`git ${mode[2]}`.quiet() |
| 20 | +} |
| 21 | + |
| 22 | +export const description = string('command.abort.description') |
| 23 | + |
| 24 | +export const aliases = ['ab'] |
| 25 | + |
| 26 | +export const usages = [''] |
| 27 | + |
| 28 | +type StuckMode = (typeof StuckModes)[number][0] |
| 29 | + |
| 30 | +const StuckModes = [ |
| 31 | + ['merge', '.git/MERGE_HEAD', ['merge', '--abort']], |
| 32 | + ['rebase', '.git/rebase-merge', ['rebase', '--abort']], |
| 33 | + ['cherryPick', '.git/CHERRY_PICK_HEAD', ['cherry-pick', '--abort']], |
| 34 | + ['revert', '.git/REVERT_HEAD', ['revert', '--abort']], |
| 35 | + ['bisect', '.git/BISECT_LOG', ['bisect', 'reset']], |
| 36 | + ['applyPatch', '.git/rebase-apply', ['am', '--abort']], |
| 37 | +] as const satisfies [mode: string, file: string, args: string[]][] |
0 commit comments