git-stack-cli 2.2.7 → 2.3.0

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.2.7",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "author": "magus",
6
6
  "license": "MIT",
@@ -66,6 +66,8 @@ const re_token = (name: string) => new RegExp(`{{ ${name} }}`, "g");
66
66
  process.chdir(HOMEBREW_DIR);
67
67
  await spawn.sync(`git reset --hard`);
68
68
  await spawn.sync(`git checkout master`);
69
+ await spawn.sync("git fetch --prune");
70
+ await spawn.sync("git reset --hard origin/master");
69
71
 
70
72
  // homebrew tap formula (binaries)
71
73
 
@@ -73,18 +73,19 @@ export function CherryPickCheck(props: Props) {
73
73
  const git_dir = (await cli(`git rev-parse --absolute-git-dir`)).stdout;
74
74
 
75
75
  const cherry_pick_file = path.join(git_dir, "CHERRY_PICK_HEAD");
76
- const is_cherry_pick = await safe_exists(cherry_pick_file);
76
+ if (await safe_exists(cherry_pick_file)) {
77
+ return patch({ status: "prompt" });
78
+ }
77
79
 
78
- const status = is_cherry_pick ? "prompt" : "done";
80
+ const git_sequencer_dir = (await cli(`git rev-parse --git-path sequencer`)).stdout;
81
+ if (await safe_exists(git_sequencer_dir)) {
82
+ return patch({ status: "prompt" });
83
+ }
79
84
 
80
- patch({ status });
85
+ patch({ status: "done" });
81
86
  } catch (err) {
82
- actions.error("Must be run from within a git repository.");
83
-
84
87
  if (err instanceof Error) {
85
- if (actions.isDebug()) {
86
- actions.error(err.message);
87
- }
88
+ actions.error(err.message);
88
89
  }
89
90
 
90
91
  actions.exit(11);
@@ -130,12 +130,8 @@ export function DetectInitialPR(props: Props) {
130
130
 
131
131
  patch({ status: "done" });
132
132
  } catch (err) {
133
- actions.error("Must be run from within a git repository.");
134
-
135
133
  if (err instanceof Error) {
136
- if (actions.isDebug()) {
137
- actions.error(err.message);
138
- }
134
+ actions.error(err.message);
139
135
  }
140
136
 
141
137
  actions.exit(9);
@@ -112,12 +112,8 @@ export function DirtyCheck(props: Props) {
112
112
  patch({ status: "prompt" });
113
113
  }
114
114
  } catch (err) {
115
- actions.error("Must be run from within a git repository.");
116
-
117
115
  if (err instanceof Error) {
118
- if (actions.isDebug()) {
119
- actions.error(err.message);
120
- }
116
+ actions.error(err.message);
121
117
  }
122
118
 
123
119
  actions.exit(12);
@@ -112,9 +112,7 @@ async function run() {
112
112
  actions.error("Unable to gather git metadata.");
113
113
 
114
114
  if (err instanceof Error) {
115
- if (actions.isDebug()) {
116
- actions.error(err.message);
117
- }
115
+ actions.error(err.message);
118
116
  }
119
117
 
120
118
  actions.exit(7);
@@ -57,9 +57,7 @@ async function run() {
57
57
  actions.error("Unable to retrieve local commit status.");
58
58
 
59
59
  if (err instanceof Error) {
60
- if (actions.isDebug()) {
61
- actions.error(err.message);
62
- }
60
+ actions.error(err.message);
63
61
  }
64
62
  }
65
63
  }
@@ -136,7 +136,6 @@ async function run() {
136
136
  actions.error("Try again with `--verbose` to see more information.");
137
137
  }
138
138
 
139
- handle_exit();
140
139
  actions.exit(16);
141
140
  }
142
141
 
@@ -79,12 +79,8 @@ export function RebaseCheck(props: Props) {
79
79
  const status = is_rebase ? "prompt" : "done";
80
80
  patch({ status });
81
81
  } catch (err) {
82
- actions.error("Must be run from within a git repository.");
83
-
84
82
  if (err instanceof Error) {
85
- if (actions.isDebug()) {
86
- actions.error(err.message);
87
- }
83
+ actions.error(err.message);
88
84
  }
89
85
 
90
86
  actions.exit(13);
@@ -142,7 +142,6 @@ async function run() {
142
142
  actions.error("Try again with `--verbose` to see more information.");
143
143
  }
144
144
 
145
- handle_exit();
146
145
  actions.exit(18);
147
146
  }
148
147
 
@@ -34,9 +34,7 @@ async function run() {
34
34
  actions.error("Unable to log verbose debug information.");
35
35
 
36
36
  if (err instanceof Error) {
37
- if (actions.isDebug()) {
38
- actions.error(err.message);
39
- }
37
+ actions.error(err.message);
40
38
  }
41
39
 
42
40
  actions.exit(14);
package/src/command.ts CHANGED
@@ -9,6 +9,7 @@ export async function command() {
9
9
  // https://yargs.js.org/docs/#api-reference-optionkey-opt
10
10
  return (
11
11
  yargs(hideBin(process.argv))
12
+ .scriptName("git stack")
12
13
  .usage("Usage: git stack [command] [options]")
13
14
 
14
15
  .command("$0", "Sync commit ranges to Github", (yargs) => yargs.options(DefaultOptions))
@@ -7,7 +7,7 @@ import * as Ink from "ink-cjs";
7
7
  import { Await } from "~/app/Await";
8
8
  import { Brackets } from "~/app/Brackets";
9
9
  import { FormatText } from "~/app/FormatText";
10
- import { Parens } from "~/app/Parens";
10
+ import { Status } from "~/app/Status";
11
11
  import { Store } from "~/app/Store";
12
12
  import * as CommitMetadata from "~/core/CommitMetadata";
13
13
  import { cli } from "~/core/cli";
@@ -71,36 +71,33 @@ Rebase.run = async function run() {
71
71
 
72
72
  // drop commits that are in groups of merged PRs
73
73
  const merged_pr = commit_pr?.state === "MERGED";
74
+ const commit_message = <Ink.Text color={colors.blue}>{commit.subject_line}</Ink.Text>;
74
75
 
75
76
  if (merged_pr) {
76
- if (actions.isDebug()) {
77
- actions.output(
78
- <FormatText
79
- wrapper={<Ink.Text color={colors.yellow} wrap="truncate-end" />}
80
- message="Dropping {commit_message} {pr_status}"
81
- values={{
82
- commit_message: <Brackets>{commit.subject_line}</Brackets>,
83
- pr_status: <Parens>MERGED</Parens>,
84
- }}
85
- />,
86
- );
87
- }
88
-
89
- continue;
90
- }
91
-
92
- if (actions.isDebug()) {
93
77
  actions.output(
94
78
  <FormatText
95
79
  wrapper={<Ink.Text color={colors.yellow} wrap="truncate-end" />}
96
- message="Picking {commit_message}"
80
+ message="Dropping {pr_status} {commit_message}"
97
81
  values={{
98
- commit_message: <Brackets>{commit.subject_line}</Brackets>,
82
+ pr_status: <Ink.Text color={colors.purple}>MERGED</Ink.Text>,
83
+ commit_message,
99
84
  }}
100
85
  />,
101
86
  );
87
+
88
+ continue;
102
89
  }
103
90
 
91
+ actions.output(
92
+ <FormatText
93
+ wrapper={<Ink.Text color={colors.yellow} wrap="truncate-end" />}
94
+ message="Picking {commit_message}"
95
+ values={{
96
+ commit_message,
97
+ }}
98
+ />,
99
+ );
100
+
104
101
  picked_commit_list.push(commit);
105
102
  }
106
103
 
@@ -120,38 +117,38 @@ Rebase.run = async function run() {
120
117
 
121
118
  restore_git();
122
119
 
123
- const next_commit_range = await CommitMetadata.range();
124
-
125
- actions.output(
126
- <FormatText
127
- wrapper={<Ink.Text color={colors.green} />}
128
- message="✅ {branch_name} in sync with {origin_branch}"
129
- values={{
130
- branch_name: <Brackets>{branch_name}</Brackets>,
131
- origin_branch: <Brackets>{`origin/${master_branch}`}</Brackets>,
132
- }}
133
- />,
134
- );
135
-
136
120
  actions.unregister_abort_handler();
137
-
138
- actions.set((state) => {
139
- state.commit_range = next_commit_range;
140
- state.step = "status";
141
- });
142
121
  } catch (err) {
143
122
  actions.error("Unable to rebase.");
144
123
 
145
124
  if (err instanceof Error) {
146
- if (actions.isDebug()) {
147
- actions.error(err.message);
148
- }
125
+ actions.error(err.message);
149
126
  }
150
127
 
151
- handle_exit();
152
128
  actions.exit(20);
153
129
  }
154
130
 
131
+ const next_commit_range = await CommitMetadata.range();
132
+
133
+ actions.output(
134
+ <FormatText
135
+ wrapper={<Ink.Text color={colors.green} />}
136
+ message="✅ {branch_name} in sync with {origin_branch}"
137
+ values={{
138
+ branch_name: <Brackets>{branch_name}</Brackets>,
139
+ origin_branch: <Brackets>{master_branch}</Brackets>,
140
+ }}
141
+ />,
142
+ );
143
+
144
+ actions.set((state) => {
145
+ state.commit_range = next_commit_range;
146
+ });
147
+
148
+ actions.output(<Status />);
149
+
150
+ actions.exit(0);
151
+
155
152
  // cleanup git operations if cancelled during manual rebase
156
153
  function restore_git() {
157
154
  // signint handler MUST run synchronously
package/src/core/cli.ts CHANGED
@@ -82,6 +82,7 @@ export async function cli(
82
82
  state.actions.debug(log.output(result));
83
83
 
84
84
  if (!options.ignoreExitCode && result.code !== 0) {
85
+ state.actions.debug(log.non_zero_exit(result));
85
86
  reject(new Error(log.error(result)));
86
87
  } else {
87
88
  resolve(result);
@@ -133,6 +134,7 @@ cli.sync = function cli_sync(
133
134
  state.actions.debug(log.output(result));
134
135
 
135
136
  if (!options.ignoreExitCode && result.code !== 0) {
137
+ state.actions.debug(log.non_zero_exit(result));
136
138
  throw new Error(log.error(result));
137
139
  }
138
140
 
@@ -157,8 +159,13 @@ const log = {
157
159
  return `${result.output}\n`;
158
160
  },
159
161
 
160
- error(result: Return) {
162
+ non_zero_exit(result: Return) {
161
163
  const { command, code, duration } = result;
162
164
  return `${command} (exit_code=${code} duration=${duration})`;
163
165
  },
166
+
167
+ error(result: Return) {
168
+ const lines = [result.output, this.non_zero_exit(result)];
169
+ return lines.join("\n");
170
+ },
164
171
  };