Skip to content

Commit 9119964

Browse files
committed
feat(commands): add abort
1 parent fa72a56 commit 9119964

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

src/commands/abort.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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[]][]

src/strings.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ const STRINGS = {
1414
},
1515
},
1616
command: {
17+
abort: {
18+
description: `What ya mom should've done years ago. Aborts a stuck process.`,
19+
action: {
20+
merge: 'Aborted the merge. Conflicts much?',
21+
rebase: 'Aborted the rebase. I guess the conflicts were too much for you, hah.',
22+
cherryPick: 'Aborted the cherry-pick. Did you pick the wrong cherry?',
23+
revert: 'Aborted the revert. Revert of a revert... Do you have commitment issues?',
24+
bisect: 'Reset the bisect. What were you bisecting?',
25+
applyPatch: "Aborted the apply-patch. Guess the patch didn't work?",
26+
},
27+
notStuck: "You ain't stuck. What are you trying to abort?",
28+
},
1729
discard: {
1830
description: "Wasted time on something that didn't work?",
1931
action: [

0 commit comments

Comments
 (0)