@@ -3,11 +3,13 @@ import * as React from "react";
33import * as Ink from "ink-cjs" ;
44
55import { Await } from "~/app/Await" ;
6+ import { Command } from "~/app/Command" ;
67import { FormatText } from "~/app/FormatText" ;
78import { Parens } from "~/app/Parens" ;
89import { Store } from "~/app/Store" ;
910import { cli } from "~/core/cli" ;
1011import { colors } from "~/core/colors" ;
12+ import { is_finite_value } from "~/core/is_finite_value" ;
1113
1214export function Fixup ( ) {
1315 return (
@@ -25,27 +27,48 @@ async function run() {
2527
2628 const relative_number = argv . commit ;
2729
28- if ( ! relative_number ) {
30+ if ( ! is_finite_value ( relative_number ) ) {
2931 actions . output (
30- < Ink . Text color = { colors . red } > ❗️ Usage: git fixup { "<relative-commit-number>" } </ Ink . Text > ,
32+ < Ink . Box flexDirection = "column" >
33+ < Ink . Text color = { colors . red } > ❗️ Usage: git fixup { "<relative-commit-number>" } </ Ink . Text >
34+ < Ink . Text color = { colors . gray } >
35+ Automates the process of adding staged changes to a previous commit.
36+ </ Ink . Text >
37+ < FormatText
38+ wrapper = { < Ink . Text color = { colors . gray } /> }
39+ message = "You can use {git_stack_log} to get the relative commit number."
40+ values = { { git_stack_log : < Command > git stack log</ Command > } }
41+ />
42+ < Ink . Box height = { 1 } />
43+ < FormatText
44+ message = " {prompt} git stack log"
45+ values = { { prompt : < Ink . Text color = { colors . green } > ❯</ Ink . Text > } }
46+ />
47+ < FormatText
48+ message = " 0 * {sha} 18 hours ago noah homebrew-git-stack 2.9.9"
49+ values = { { sha : < Ink . Text color = { colors . green } > e329794</ Ink . Text > } }
50+ />
51+ < FormatText
52+ message = " 1 * {sha} 18 hours ago noah 2.9.9"
53+ values = { { sha : < Ink . Text color = { colors . green } > c7e4065</ Ink . Text > } }
54+ />
55+ < FormatText
56+ message = " 2 * {sha} 18 hours ago noah command: --label + github add labels"
57+ values = { { sha : < Ink . Text color = { colors . green } > f82ac73</ Ink . Text > } }
58+ />
59+ < Ink . Box height = { 1 } />
60+ < FormatText
61+ wrapper = { < Ink . Text color = { colors . gray } /> }
62+ message = "To target {sha} above, use {command}"
63+ values = { {
64+ sha : < Ink . Text color = { colors . green } > 838e878</ Ink . Text > ,
65+ command : < Command > git stack fixup 2</ Command > ,
66+ } }
67+ />
68+ </ Ink . Box > ,
3169 ) ;
70+
3271 actions . output ( "" ) ;
33- actions . output ( "This script automates the process of adding staged changes as a fixup commit" ) ;
34- actions . output (
35- "and the subsequent git rebase to flatten the commits based on relative commit number" ,
36- ) ;
37- actions . output ( "You can use a `git log` like below to get the relative commit number" ) ;
38- actions . output ( "" ) ;
39- actions . output ( " ❯ git stack log" ) ;
40- actions . output (
41- " 1\te329794d5f881cbf0fc3f26d2108cf6f3fdebabe enable drop_error_subtask test param" ,
42- ) ;
43- actions . output (
44- " 2\t57f43b596e5c6b97bc47e2a591f82ccc81651156 test drop_error_subtask baseline" ,
45- ) ;
46- actions . output ( " 3\t838e878d483c6a2d5393063fc59baf2407225c6d ErrorSubtask test baseline" ) ;
47- actions . output ( "" ) ;
48- actions . output ( "To target `838e87` above, you would call `fixup 3`" ) ;
4972
5073 actions . exit ( 0 ) ;
5174 }
@@ -64,11 +87,8 @@ async function run() {
6487 // );
6588 }
6689
67- // Calculate commit SHA based on the relative commit number
68- const adjusted_number = Number ( relative_number ) - 1 ;
69-
7090 // get the commit SHA of the target commit
71- const commit_sha = ( await cli ( `git rev-parse HEAD~${ adjusted_number } ` ) ) . stdout ;
91+ const commit_sha = ( await cli ( `git rev-parse HEAD~${ relative_number } ` ) ) . stdout ;
7292
7393 actions . output (
7494 < FormatText
@@ -104,7 +124,7 @@ async function run() {
104124
105125 try {
106126 // rebase target needs to account for new commit created above
107- const rebase_target = Number ( relative_number ) + 1 ;
127+ const rebase_target = Number ( relative_number ) + 2 ;
108128
109129 await cli ( `git rebase -i --autosquash HEAD~${ rebase_target } ` , {
110130 env : {
0 commit comments