git-stack-cli 2.5.3 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "git-stack-cli",
3
- "version": "2.5.3",
3
+ "version": "2.6.1",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",
@@ -36,7 +36,7 @@
36
36
  "test": "bun test",
37
37
  "test:watch": "pnpm run test --watch",
38
38
  "test:types": "tsc",
39
- "test:all": "pnpm run prettier:check && pnpm run lint:check && pnpm run test:types",
39
+ "test:all": "pnpm run prettier:check && pnpm run lint:check && pnpm run test:types && pnpm run test",
40
40
  "prepublishOnly": "bun run scripts/npm-prepublishOnly.ts"
41
41
  },
42
42
  "dependencies": {
@@ -111,6 +111,11 @@ if (!WATCH) {
111
111
  continue;
112
112
  }
113
113
 
114
+ // ignore bun build files
115
+ if (filename.includes(".bun-build")) {
116
+ continue;
117
+ }
118
+
114
119
  log(`⚠️ Change ${filename}`);
115
120
 
116
121
  if (VERBOSE) {
package/src/app/App.tsx CHANGED
@@ -14,6 +14,7 @@ import { Main } from "~/app/Main";
14
14
  import { Output } from "~/app/Output";
15
15
  import { Providers } from "~/app/Providers";
16
16
  import { RebaseCheck } from "~/app/RebaseCheck";
17
+ import { RequireBranch } from "~/app/RequireBranch";
17
18
  import { Store } from "~/app/Store";
18
19
  import { VerboseDebugInfo } from "~/app/VerboseDebugInfo";
19
20
  import { Fixup } from "~/commands/Fixup";
@@ -112,11 +113,13 @@ function MaybeMain() {
112
113
  <DependencyCheck>
113
114
  <DirtyCheck>
114
115
  <GatherMetadata>
115
- <LocalCommitStatus>
116
- <DetectInitialPR>
117
- <Main />
118
- </DetectInitialPR>
119
- </LocalCommitStatus>
116
+ <RequireBranch>
117
+ <LocalCommitStatus>
118
+ <DetectInitialPR>
119
+ <Main />
120
+ </DetectInitialPR>
121
+ </LocalCommitStatus>
122
+ </RequireBranch>
120
123
  </GatherMetadata>
121
124
  </DirtyCheck>
122
125
  </DependencyCheck>
@@ -6,6 +6,7 @@ import { Brackets } from "~/app/Brackets";
6
6
  import { Command } from "~/app/Command";
7
7
  import { FormatText } from "~/app/FormatText";
8
8
  import { YesNoPrompt } from "~/app/YesNoPrompt";
9
+ import { assertNever } from "~/core/assertNever";
9
10
  import { cli } from "~/core/cli";
10
11
  import { colors } from "~/core/colors";
11
12
  import { fetch_json } from "~/core/fetch_json";
@@ -28,7 +29,7 @@ type State = {
28
29
  error: null | Error;
29
30
  local_version: null | string;
30
31
  latest_version: null | string;
31
- status: "init" | "prompt" | "install" | "done" | "exit";
32
+ status: "init" | "prompt" | "install" | "done";
32
33
  is_brew_bun_standalone: boolean;
33
34
  };
34
35
 
@@ -61,7 +62,24 @@ export function AutoUpdate(props: Props) {
61
62
  }
62
63
 
63
64
  React.useEffect(() => {
64
- let status: State["status"] = "done";
65
+ switch (state.status) {
66
+ case "init":
67
+ case "prompt":
68
+ case "install":
69
+ break;
70
+
71
+ case "done": {
72
+ props.onDone?.();
73
+ break;
74
+ }
75
+
76
+ default:
77
+ assertNever(state.status);
78
+ }
79
+ }, [state.status]);
80
+
81
+ React.useEffect(() => {
82
+ let status: State["status"] = "init";
65
83
  let latest_version: string | null = null;
66
84
  let is_brew_bun_standalone = false;
67
85
 
@@ -73,17 +91,13 @@ export function AutoUpdate(props: Props) {
73
91
  throw new Error("Auto update requires process.env.CLI_VERSION to be set");
74
92
  }
75
93
 
76
- if (is_output) {
77
- handle_output(<Ink.Text key="init">Checking for latest version...</Ink.Text>);
78
- }
79
-
80
94
  const timeout_ms = is_finite_value(props.timeoutMs) ? props.timeoutMs : 2 * 1000;
81
95
 
82
96
  const npm_json = await Promise.race([
83
97
  fetch_json(`https://registry.npmjs.org/${props.name}`),
84
98
 
85
99
  sleep(timeout_ms).then(() => {
86
- throw new Error("Timeout");
100
+ throw new Error("AutoUpdate timeout");
87
101
  }),
88
102
  ]);
89
103
 
@@ -126,8 +140,13 @@ export function AutoUpdate(props: Props) {
126
140
  }
127
141
 
128
142
  const semver_result = semver_compare(latest_version, local_version);
143
+ if (props_ref.current.verbose) {
144
+ handle_output(<Ink.Text dimColor>{JSON.stringify({ semver_result })}</Ink.Text>);
145
+ }
129
146
 
130
147
  if (semver_result === 0) {
148
+ status = "done";
149
+
131
150
  if (is_output) {
132
151
  handle_output(
133
152
  <Ink.Text>
@@ -138,15 +157,12 @@ export function AutoUpdate(props: Props) {
138
157
  return;
139
158
  }
140
159
 
141
- if (semver_result === -1) {
142
- // latest version is less than or equal to local version, skip auto update
143
- throw new Error(
144
- `latest version < local_version, skipping auto update [${latest_version} < ${local_version}]`,
145
- );
160
+ if (semver_result === 1) {
161
+ // trigger yes no prompt
162
+ status = "prompt";
146
163
  }
147
164
 
148
- // trigger yes no prompt
149
- status = "prompt";
165
+ throw new Error("AutoUpdate failed");
150
166
  }
151
167
 
152
168
  const onError = props_ref.current.onError || (() => {});
@@ -156,9 +172,6 @@ export function AutoUpdate(props: Props) {
156
172
  patch({ status, local_version, latest_version, is_brew_bun_standalone });
157
173
  })
158
174
  .catch((error) => {
159
- patch({ status, error, local_version, latest_version, is_brew_bun_standalone });
160
- onError(error);
161
-
162
175
  if (props_ref.current.verbose) {
163
176
  handle_output(
164
177
  <Ink.Text key="error" color={colors.red}>
@@ -166,9 +179,11 @@ export function AutoUpdate(props: Props) {
166
179
  </Ink.Text>,
167
180
  );
168
181
  }
169
- })
170
- .finally(() => {
171
- props.onDone?.();
182
+
183
+ // ensure we always exit
184
+ status = "done";
185
+ patch({ status, error, local_version, latest_version, is_brew_bun_standalone });
186
+ onError(error);
172
187
  });
173
188
  }, []);
174
189
 
@@ -180,54 +195,60 @@ export function AutoUpdate(props: Props) {
180
195
  case "prompt": {
181
196
  let install_command = "";
182
197
  if (state.is_brew_bun_standalone) {
183
- install_command = `npm install -g ${props.name}@latest`;
198
+ install_command = "brew install magus/git-stack/git-stack";
184
199
  } else {
185
- install_command = "brew upgrade magus/git-stack/git-stack";
200
+ install_command = `npm install -g ${props.name}@latest`;
186
201
  }
187
202
 
188
203
  return (
189
204
  <YesNoPrompt
190
205
  message={
191
206
  <Ink.Box flexDirection="column">
192
- <Ink.Text color={colors.yellow}>
207
+ <Ink.Box flexDirection="column">
208
+ <Ink.Text color={colors.yellow}>
209
+ <FormatText
210
+ wrapper={<Ink.Text />}
211
+ message="New version available {latest_version}"
212
+ values={{
213
+ latest_version: <Brackets>{state.latest_version}</Brackets>,
214
+ }}
215
+ />
216
+ ,
217
+ </Ink.Text>
218
+ <Ink.Text> </Ink.Text>
219
+ <Command>{install_command}</Command>
220
+ <Ink.Text> </Ink.Text>
221
+ </Ink.Box>
222
+ <Ink.Box>
193
223
  <FormatText
194
- wrapper={<Ink.Text />}
195
- message="New version available {latest_version}, would you like to update?"
196
- values={{
197
- latest_version: <Brackets>{state.latest_version}</Brackets>,
198
- }}
224
+ wrapper={<Ink.Text color={colors.yellow} />}
225
+ message="Would you like to run the above command to update?"
199
226
  />
200
- ,
201
- </Ink.Text>
202
- <Ink.Text> </Ink.Text>
203
- <Command>{install_command}</Command>
204
- <Ink.Text> </Ink.Text>
205
- <FormatText
206
- wrapper={<Ink.Text color={colors.yellow} />}
207
- message="Would you like to run the above command to update?"
208
- />
227
+ </Ink.Box>
209
228
  </Ink.Box>
210
229
  }
211
230
  onYes={async () => {
212
- handle_output(
213
- <FormatText
214
- key="install"
215
- wrapper={<Ink.Text />}
216
- message="Installing {name}@{version}..."
217
- values={{
218
- name: <Ink.Text color={colors.yellow}>{props.name}</Ink.Text>,
219
- version: <Ink.Text color={colors.blue}>{state.latest_version}</Ink.Text>,
220
- }}
221
- />,
222
- );
231
+ handle_output(<Command>{install_command}</Command>);
223
232
 
224
233
  patch({ status: "install" });
225
234
 
226
- await cli(install_command);
235
+ await cli(install_command, {
236
+ env: {
237
+ ...process.env,
238
+ HOMEBREW_COLOR: "1",
239
+ },
240
+ onOutput: (data: string) => {
241
+ handle_output(<Ink.Text>{data}</Ink.Text>);
242
+ },
243
+ });
227
244
 
228
- patch({ status: "exit" });
245
+ handle_output(
246
+ <Ink.Text key="done">
247
+ ✅ Installed <Brackets>{state.latest_version}</Brackets>
248
+ </Ink.Text>,
249
+ );
229
250
 
230
- handle_output(<Ink.Text key="done">Auto update done.</Ink.Text>);
251
+ patch({ status: "done" });
231
252
  }}
232
253
  onNo={() => {
233
254
  patch({ status: "done" });
@@ -239,9 +260,6 @@ export function AutoUpdate(props: Props) {
239
260
  case "install":
240
261
  return null;
241
262
 
242
- case "exit":
243
- return null;
244
-
245
263
  case "done":
246
264
  return props.children;
247
265
  }
@@ -67,33 +67,10 @@ async function run() {
67
67
 
68
68
  actions.debug(`master_branch = ${master_branch}`);
69
69
 
70
- const branch_name = (await cli("git rev-parse --abbrev-ref HEAD")).stdout;
71
-
72
- // handle detahed head state
73
- if (branch_name === "HEAD") {
74
- actions.error("Must run within a branch.");
75
- actions.exit(0);
76
- return;
77
- }
78
-
79
- // handle when there are no detected changes
80
- if (`origin/${branch_name}` === master_branch) {
81
- actions.error("Must run within a branch.");
82
- actions.exit(0);
83
- return;
84
- }
85
-
86
70
  const head = (await cli("git rev-parse HEAD")).stdout;
71
+ const branch_name = (await cli("git rev-parse --abbrev-ref HEAD")).stdout;
87
72
  const merge_base = (await cli(`git merge-base HEAD ${master_branch}`)).stdout;
88
73
 
89
- // handle when there are no detected changes
90
- if (head === merge_base) {
91
- actions.newline();
92
- actions.output(<Ink.Text color={colors.gray}>No changes detected.</Ink.Text>);
93
- actions.exit(0);
94
- return;
95
- }
96
-
97
74
  // git@github.com:magus/git-multi-diff-playground.git
98
75
  // https://github.com/magus/git-multi-diff-playground.git
99
76
  const origin_url = (await cli(`git config --get remote.origin.url`)).stdout;
@@ -107,6 +84,7 @@ async function run() {
107
84
  state.master_branch = master_branch;
108
85
  state.head = head;
109
86
  state.branch_name = branch_name;
87
+ state.merge_base = merge_base;
110
88
  });
111
89
  } catch (err) {
112
90
  actions.error("Unable to gather git metadata.");
package/src/app/Main.tsx CHANGED
@@ -6,7 +6,6 @@ import { ManualRebase } from "~/app/ManualRebase";
6
6
  import { PostRebaseStatus } from "~/app/PostRebaseStatus";
7
7
  import { PreLocalMergeRebase } from "~/app/PreLocalMergeRebase";
8
8
  import { PreManualRebase } from "~/app/PreManualRebase";
9
- import { PreSelectCommitRanges } from "~/app/PreSelectCommitRanges";
10
9
  import { SelectCommitRanges } from "~/app/SelectCommitRanges";
11
10
  import { Status } from "~/app/Status";
12
11
  import { Store } from "~/app/Store";
@@ -32,9 +31,6 @@ export function Main() {
32
31
  case "pre-local-merge-rebase":
33
32
  return <PreLocalMergeRebase />;
34
33
 
35
- case "pre-select-commit-ranges":
36
- return <PreSelectCommitRanges />;
37
-
38
34
  case "select-commit-ranges":
39
35
  return <SelectCommitRanges />;
40
36
 
@@ -59,6 +59,11 @@ async function run() {
59
59
  commit.title = group_from_map.title;
60
60
  }
61
61
 
62
+ // // capture commit_range for GitReviseTodo test
63
+ // // doc-link capture-git-revise-todo
64
+ // console.debug(JSON.stringify(commit_range, null, 2));
65
+ // throw new Error("STOP");
66
+
62
67
  await GitReviseTodo.execute({
63
68
  rebase_group_index: 0,
64
69
  rebase_merge_base: merge_base,
@@ -14,6 +14,7 @@ type Props<T> = {
14
14
  disabled?: boolean;
15
15
  disableSelect?: boolean;
16
16
  maxWidth?: number;
17
+ startIndex?: number;
17
18
  };
18
19
 
19
20
  type Item<T> = {
@@ -67,11 +68,13 @@ export function MultiSelect<T>(props: Props<T>) {
67
68
  for (let i = props.items.length - 1; i >= 0; i--) {
68
69
  const item = props.items[i];
69
70
 
70
- if (!item.disabled) {
71
- last_enabled = i;
71
+ if (item.disabled) {
72
+ continue;
72
73
  }
73
74
 
74
- if (!item.selected && !item.disabled) {
75
+ last_enabled = i;
76
+
77
+ if (!item.selected) {
75
78
  return i;
76
79
  }
77
80
  }
@@ -80,7 +83,7 @@ export function MultiSelect<T>(props: Props<T>) {
80
83
  return last_enabled;
81
84
  }
82
85
 
83
- return 0;
86
+ return props.startIndex || 0;
84
87
  },
85
88
  );
86
89
 
@@ -188,7 +191,6 @@ type ItemRowProps = {
188
191
 
189
192
  function ItemRow(props: ItemRowProps) {
190
193
  let color;
191
- let bold;
192
194
  let underline;
193
195
  let dimColor;
194
196
 
@@ -197,14 +199,8 @@ function ItemRow(props: ItemRowProps) {
197
199
  underline = true;
198
200
  }
199
201
 
200
- if (props.selected) {
201
- // color = "";
202
- bold = true;
203
- }
204
-
205
202
  if (props.disabled) {
206
203
  color = "";
207
- bold = false;
208
204
  underline = false;
209
205
  dimColor = true;
210
206
  }
@@ -215,7 +211,7 @@ function ItemRow(props: ItemRowProps) {
215
211
 
216
212
  <Ink.Box width={props.maxWidth}>
217
213
  <Ink.Text
218
- bold={bold}
214
+ // force line break
219
215
  underline={underline}
220
216
  color={color}
221
217
  dimColor={dimColor}
@@ -0,0 +1,67 @@
1
+ import * as React from "react";
2
+
3
+ import * as Ink from "ink-cjs";
4
+
5
+ import { Await } from "~/app/Await";
6
+ import { Store } from "~/app/Store";
7
+ import { colors } from "~/core/colors";
8
+ import { invariant } from "~/core/invariant";
9
+
10
+ type Props = {
11
+ children: React.ReactNode;
12
+ };
13
+
14
+ export function RequireBranch(props: Props) {
15
+ const fallback = <Ink.Text color={colors.yellow}>Gathering local git information…</Ink.Text>;
16
+
17
+ return (
18
+ <Await fallback={fallback} function={run}>
19
+ {props.children}
20
+ </Await>
21
+ );
22
+ }
23
+
24
+ async function run() {
25
+ const state = Store.getState();
26
+ const actions = Store.getState().actions;
27
+ const master_branch = state.master_branch;
28
+ const head = state.head;
29
+ const branch_name = state.branch_name;
30
+ const merge_base = state.merge_base;
31
+
32
+ invariant(head, "head must exist");
33
+ invariant(branch_name, "branch_name must exist");
34
+ invariant(merge_base, "merge_base must exist");
35
+
36
+ try {
37
+ // handle detahed head state
38
+ if (branch_name === "HEAD") {
39
+ actions.error("Must run within a branch.");
40
+ actions.exit(0);
41
+ return;
42
+ }
43
+
44
+ // handle when there are no detected changes
45
+ if (`origin/${branch_name}` === master_branch) {
46
+ actions.error("Must run within a branch.");
47
+ actions.exit(0);
48
+ return;
49
+ }
50
+
51
+ // handle when there are no detected changes
52
+ if (head === merge_base) {
53
+ actions.newline();
54
+ actions.output(<Ink.Text color={colors.gray}>No changes detected.</Ink.Text>);
55
+ actions.exit(0);
56
+ return;
57
+ }
58
+ } catch (err) {
59
+ actions.error("Unable to detect branch changes.");
60
+
61
+ if (err instanceof Error) {
62
+ actions.error(err.message);
63
+ }
64
+
65
+ actions.exit(17);
66
+ }
67
+ }