git-stack-cli 0.8.7 → 1.0.2

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.
Files changed (105) hide show
  1. package/README.md +32 -3
  2. package/dist/cjs/index.cjs +34770 -0
  3. package/package.json +21 -7
  4. package/dist/__fixtures__/metadata.js +0 -666
  5. package/dist/__fixtures__/metadata.json +0 -186
  6. package/dist/app/App copy.js +0 -30
  7. package/dist/app/App.js +0 -42
  8. package/dist/app/ArgCheck.js +0 -21
  9. package/dist/app/AutoUpdate.js +0 -128
  10. package/dist/app/Await.js +0 -45
  11. package/dist/app/Brackets copy.js +0 -10
  12. package/dist/app/Brackets.js +0 -11
  13. package/dist/app/Command.js +0 -7
  14. package/dist/app/Counter.js +0 -19
  15. package/dist/app/Debug.js +0 -33
  16. package/dist/app/DependencyCheck.js +0 -89
  17. package/dist/app/Exit.js +0 -14
  18. package/dist/app/FormatText.js +0 -9
  19. package/dist/app/GatherMetadata copy.js +0 -91
  20. package/dist/app/GatherMetadata.js +0 -100
  21. package/dist/app/GithubApiError.js +0 -50
  22. package/dist/app/InitMetadata.js +0 -14
  23. package/dist/app/Input.js +0 -15
  24. package/dist/app/KeepAlive.js +0 -11
  25. package/dist/app/LocalCommitStatus.js +0 -43
  26. package/dist/app/LocalMergeRebase.js +0 -157
  27. package/dist/app/Main copy.js +0 -200
  28. package/dist/app/ManualRebase copy.js +0 -127
  29. package/dist/app/ManualRebase.js +0 -220
  30. package/dist/app/MultiSelect copy.js +0 -76
  31. package/dist/app/MultiSelect.js +0 -143
  32. package/dist/app/NPMAutoUpdate.js +0 -34
  33. package/dist/app/Output.js +0 -19
  34. package/dist/app/Parens copy.js +0 -9
  35. package/dist/app/Parens.js +0 -10
  36. package/dist/app/PostRebaseStatus copy.js +0 -23
  37. package/dist/app/PostRebaseStatus.js +0 -23
  38. package/dist/app/PreLocalMergeRebase.js +0 -21
  39. package/dist/app/PreSelectCommitRanges copy.js +0 -21
  40. package/dist/app/PreSelectCommitRanges.js +0 -21
  41. package/dist/app/Providers.js +0 -5
  42. package/dist/app/RebaseCheck.js +0 -56
  43. package/dist/app/SelectCommitRange.js +0 -1
  44. package/dist/app/SelectCommitRanges.js +0 -207
  45. package/dist/app/Status copy.js +0 -46
  46. package/dist/app/Status.js +0 -61
  47. package/dist/app/StatusTable.js +0 -115
  48. package/dist/app/Store.js +0 -136
  49. package/dist/app/Table.js +0 -65
  50. package/dist/app/TextInput.js +0 -51
  51. package/dist/app/Url copy.js +0 -6
  52. package/dist/app/Url.js +0 -6
  53. package/dist/app/Waterfall.js +0 -20
  54. package/dist/app/YesNoPrompt copy.js +0 -24
  55. package/dist/app/YesNoPrompt.js +0 -40
  56. package/dist/app/main.js +0 -39
  57. package/dist/cli.js +0 -9
  58. package/dist/command.js +0 -60
  59. package/dist/core/CommitMetadata.js +0 -159
  60. package/dist/core/Metadata copy.js +0 -37
  61. package/dist/core/Metadata.js +0 -36
  62. package/dist/core/Metadata.test.js +0 -34
  63. package/dist/core/StackSummaryTable.js +0 -86
  64. package/dist/core/StackSummaryTable.test.js +0 -134
  65. package/dist/core/StackTable.js +0 -38
  66. package/dist/core/SummaryTable.js +0 -38
  67. package/dist/core/ZustandStore.js +0 -23
  68. package/dist/core/assertNever.js +0 -4
  69. package/dist/core/cache.js +0 -39
  70. package/dist/core/capitalize.js +0 -5
  71. package/dist/core/chalk.js +0 -83
  72. package/dist/core/clamp.js +0 -6
  73. package/dist/core/cli copy.js +0 -44
  74. package/dist/core/cli.js +0 -86
  75. package/dist/core/color.js +0 -83
  76. package/dist/core/colors.js +0 -15
  77. package/dist/core/date.js +0 -18
  78. package/dist/core/dependency_check.js +0 -27
  79. package/dist/core/env.js +0 -4
  80. package/dist/core/exit.js +0 -4
  81. package/dist/core/fetch_json.js +0 -24
  82. package/dist/core/get_commit_metadata.js +0 -61
  83. package/dist/core/github.js +0 -118
  84. package/dist/core/id.js +0 -61
  85. package/dist/core/invariant copy.js +0 -5
  86. package/dist/core/invariant.js +0 -5
  87. package/dist/core/isFiniteValue.js +0 -3
  88. package/dist/core/is_command_available.js +0 -15
  89. package/dist/core/is_dev.js +0 -1
  90. package/dist/core/is_finite_value.js +0 -3
  91. package/dist/core/json.js +0 -35
  92. package/dist/core/match_group.js +0 -9
  93. package/dist/core/readJson.js +0 -3
  94. package/dist/core/read_json.js +0 -12
  95. package/dist/core/safe_quote.js +0 -9
  96. package/dist/core/semver_compare.js +0 -26
  97. package/dist/core/serialize_json.js +0 -17
  98. package/dist/core/short_id.js +0 -60
  99. package/dist/core/sleep copy.js +0 -3
  100. package/dist/core/sleep.js +0 -3
  101. package/dist/core/wrap_index.js +0 -10
  102. package/dist/index.js +0 -13
  103. package/dist/main copy.js +0 -266
  104. package/dist/main.backup.js +0 -266
  105. package/dist/main.js +0 -265
@@ -1,91 +0,0 @@
1
- import * as React from "react";
2
- import * as Ink from "ink";
3
- import { cli } from "../core/cli.js";
4
- import { colors } from "../core/colors.js";
5
- import { invariant } from "../core/invariant.js";
6
- import { match_group } from "../core/match_group.js";
7
- import { Await } from "./Await.js";
8
- import { Brackets } from "./Brackets.js";
9
- import { FormatText } from "./FormatText.js";
10
- import { Store } from "./Store.js";
11
- export function GatherMetadata(props) {
12
- const argv = Store.useState((state) => state.argv);
13
- invariant(argv, "argv must exist");
14
- const fallback = (React.createElement(Ink.Text, { color: colors.yellow }, "Gathering local git information..."));
15
- return (React.createElement(Await, { fallback: fallback, function: gather_metadata }, props.children));
16
- }
17
- async function gather_metadata() {
18
- const actions = Store.getState().actions;
19
- const argv = Store.getState().argv;
20
- invariant(argv, "argv must exist");
21
- try {
22
- // default to master branch, fallback to main
23
- let master_branch;
24
- if (argv.branch) {
25
- actions.debug(React.createElement(FormatText, { message: "Setting master branch to {branch}", values: {
26
- branch: React.createElement(Brackets, null, argv.branch),
27
- } }));
28
- master_branch = argv.branch;
29
- }
30
- else {
31
- const detect_master = await cli(`git branch --list "${BRANCH.master}" --color=never`);
32
- if (detect_master.stdout !== "") {
33
- master_branch = BRANCH.master;
34
- }
35
- else {
36
- actions.debug(React.createElement(FormatText, { message: "Could not find {master} branch, falling back to {main}", values: {
37
- master: React.createElement(Brackets, null, BRANCH.master),
38
- main: React.createElement(Brackets, null, BRANCH.main),
39
- } }));
40
- master_branch = BRANCH.main;
41
- }
42
- }
43
- const branch_name = (await cli("git rev-parse --abbrev-ref HEAD")).stdout;
44
- // handle when there are no detected changes
45
- if (branch_name === master_branch) {
46
- actions.newline();
47
- actions.error("Must run within a branch.");
48
- actions.exit(0);
49
- return;
50
- }
51
- const head = (await cli("git rev-parse HEAD")).stdout;
52
- const merge_base = (await cli(`git merge-base HEAD ${master_branch}`))
53
- .stdout;
54
- // handle when there are no detected changes
55
- if (head === merge_base) {
56
- actions.newline();
57
- actions.output(React.createElement(Ink.Text, { color: colors.gray }, "No changes detected."));
58
- actions.exit(0);
59
- return;
60
- }
61
- // git@github.com:magus/git-multi-diff-playground.git
62
- // https://github.com/magus/git-multi-diff-playground.git
63
- const origin_url = (await cli(`git config --get remote.origin.url`)).stdout;
64
- const repo_path = match_group(origin_url, RE.repo_path, "repo_path");
65
- Store.setState((state) => {
66
- state.repo_path = repo_path;
67
- state.master_branch = master_branch;
68
- state.head = head;
69
- state.merge_base = merge_base;
70
- state.branch_name = branch_name;
71
- });
72
- }
73
- catch (err) {
74
- actions.error("Unable to gather git metadata.");
75
- if (err instanceof Error) {
76
- if (actions.isDebug()) {
77
- actions.error(err.message);
78
- }
79
- }
80
- actions.exit(7);
81
- }
82
- }
83
- const RE = {
84
- // git@github.com:magus/git-multi-diff-playground.git
85
- // https://github.com/magus/git-multi-diff-playground.git
86
- repo_path: /(?<repo_path>[^:^/]+\/[^/]+)\.git/,
87
- };
88
- const BRANCH = {
89
- master: "master",
90
- main: "main",
91
- };
@@ -1,100 +0,0 @@
1
- import * as React from "react";
2
- import * as Ink from "ink";
3
- import { cli } from "../core/cli.js";
4
- import { colors } from "../core/colors.js";
5
- import { invariant } from "../core/invariant.js";
6
- import { match_group } from "../core/match_group.js";
7
- import { Await } from "./Await.js";
8
- import { Brackets } from "./Brackets.js";
9
- import { FormatText } from "./FormatText.js";
10
- import { Store } from "./Store.js";
11
- export function GatherMetadata(props) {
12
- const argv = Store.useState((state) => state.argv);
13
- invariant(argv, "argv must exist");
14
- const fallback = (React.createElement(Ink.Text, { color: colors.yellow }, "Gathering local git information..."));
15
- return (React.createElement(Await, { fallback: fallback, function: gather_metadata }, props.children));
16
- }
17
- async function gather_metadata() {
18
- const actions = Store.getState().actions;
19
- const argv = Store.getState().argv;
20
- invariant(argv, "argv must exist");
21
- try {
22
- // default to master branch, fallback to main
23
- let master_branch;
24
- if (argv.branch) {
25
- actions.debug(React.createElement(FormatText, { message: "Setting master branch to {branch}", values: {
26
- branch: React.createElement(Brackets, null, argv.branch),
27
- } }));
28
- master_branch = argv.branch;
29
- }
30
- else {
31
- const detect_master = await cli(`git branch --list "${BRANCH.master}" --color=never`);
32
- if (detect_master.stdout !== "") {
33
- master_branch = BRANCH.master;
34
- }
35
- else {
36
- actions.debug(React.createElement(FormatText, { message: "Could not find {master} branch, falling back to {main}", values: {
37
- master: React.createElement(Brackets, null, BRANCH.master),
38
- main: React.createElement(Brackets, null, BRANCH.main),
39
- } }));
40
- master_branch = BRANCH.main;
41
- }
42
- }
43
- const branch_name = (await cli("git rev-parse --abbrev-ref HEAD")).stdout;
44
- // handle detahed head state
45
- if (branch_name === "HEAD") {
46
- actions.newline();
47
- actions.error("Must run within a branch.");
48
- actions.exit(0);
49
- return;
50
- }
51
- // handle when there are no detected changes
52
- if (branch_name === master_branch) {
53
- actions.newline();
54
- actions.error("Must run within a branch.");
55
- actions.exit(0);
56
- return;
57
- }
58
- const head = (await cli("git rev-parse HEAD")).stdout;
59
- const merge_base = (await cli(`git merge-base HEAD ${master_branch}`))
60
- .stdout;
61
- // handle when there are no detected changes
62
- if (head === merge_base) {
63
- actions.newline();
64
- actions.output(React.createElement(Ink.Text, { color: colors.gray }, "No changes detected."));
65
- actions.exit(0);
66
- return;
67
- }
68
- // git@github.com:magus/git-multi-diff-playground.git
69
- // https://github.com/magus/git-multi-diff-playground.git
70
- const origin_url = (await cli(`git config --get remote.origin.url`)).stdout;
71
- const repo_path = match_group(origin_url, RE.repo_path, "repo_path");
72
- const repo_root = (await cli(`git rev-parse --show-toplevel`)).stdout;
73
- Store.setState((state) => {
74
- state.repo_path = repo_path;
75
- state.repo_root = repo_root;
76
- state.master_branch = master_branch;
77
- state.head = head;
78
- state.merge_base = merge_base;
79
- state.branch_name = branch_name;
80
- });
81
- }
82
- catch (err) {
83
- actions.error("Unable to gather git metadata.");
84
- if (err instanceof Error) {
85
- if (actions.isDebug()) {
86
- actions.error(err.message);
87
- }
88
- }
89
- actions.exit(7);
90
- }
91
- }
92
- const RE = {
93
- // git@github.com:magus/git-multi-diff-playground.git
94
- // https://github.com/magus/git-multi-diff-playground.git
95
- repo_path: /(?<repo_path>[^:^/]+\/[^/]+)\.git/,
96
- };
97
- const BRANCH = {
98
- master: "master",
99
- main: "main",
100
- };
@@ -1,50 +0,0 @@
1
- import * as React from "react";
2
- import * as Ink from "ink";
3
- import { cli } from "../core/cli.js";
4
- import { colors } from "../core/colors.js";
5
- import * as date from "../core/date.js";
6
- import { invariant } from "../core/invariant.js";
7
- import { Await } from "./Await.js";
8
- import { Brackets } from "./Brackets.js";
9
- import { Parens } from "./Parens.js";
10
- import { Store } from "./Store.js";
11
- export function GithubApiError() {
12
- const argv = Store.useState((state) => state.argv);
13
- invariant(argv, "argv must exist");
14
- return React.createElement(Await, { fallback: null, function: run });
15
- }
16
- async function run() {
17
- const actions = Store.getState().actions;
18
- const res = await cli(`gh api https://api.github.com/rate_limit`);
19
- const res_json = JSON.parse(res.stdout);
20
- const resources_graphql = res_json.resources.graphql;
21
- const used = resources_graphql.used;
22
- const limit = resources_graphql.limit;
23
- const reset_date = new Date(resources_graphql.reset * 1000);
24
- // calculate the time remaining in minutes
25
- const now = new Date();
26
- const diff_seconds = (reset_date.getTime() - now.getTime()) / 1000;
27
- const diff_minutes = Math.round(diff_seconds / 60);
28
- const reset_time = date.format_time(reset_date);
29
- let time_until;
30
- if (diff_minutes < 0) {
31
- time_until = `${diff_seconds} seconds`;
32
- }
33
- else {
34
- time_until = `${diff_minutes} minutes`;
35
- }
36
- actions.output(React.createElement(Ink.Text, { dimColor: true },
37
- React.createElement(Ink.Text, null, "Github "),
38
- React.createElement(Brackets, null, "graphql"),
39
- React.createElement(Ink.Text, null, " API rate limit "),
40
- React.createElement(Brackets, null,
41
- React.createElement(Ink.Text, null, used),
42
- React.createElement(Ink.Text, null, "/"),
43
- React.createElement(Ink.Text, null, limit)),
44
- React.createElement(Ink.Text, null, " will reset at "),
45
- React.createElement(Ink.Text, { bold: true, color: colors.yellow }, reset_time),
46
- React.createElement(Ink.Text, null, " "),
47
- React.createElement(Parens, null,
48
- React.createElement(Ink.Text, null, "in "),
49
- React.createElement(Ink.Text, { bold: true, color: colors.yellow }, time_until))));
50
- }
@@ -1,14 +0,0 @@
1
- import * as React from "react";
2
- import { cli } from "../core/cli.js";
3
- import { Await } from "./Await.js";
4
- import { Store } from "./Store.js";
5
- export function InitMetadata() {
6
- return (React.createElement(Await, { function: async () => {
7
- const head = (await cli("git rev-parse HEAD")).stdout;
8
- const merge_base = (await cli("git merge-base HEAD master")).stdout;
9
- Store.setState((state) => {
10
- state.head = head;
11
- state.merge_base = merge_base;
12
- });
13
- } }));
14
- }
package/dist/app/Input.js DELETED
@@ -1,15 +0,0 @@
1
- import * as React from "react";
2
- import * as Ink from "ink";
3
- export function Input(props) {
4
- const [value, set_value] = React.useState(props.value || "");
5
- Ink.useInput((input, key) => {
6
- if (key.backspace) {
7
- set_value((value) => value.slice(0, -1));
8
- }
9
- else {
10
- set_value((value) => `${value}${input}`);
11
- }
12
- });
13
- return (React.createElement(Ink.Box, { borderStyle: "single" },
14
- React.createElement(Ink.Text, null, value)));
15
- }
@@ -1,11 +0,0 @@
1
- import React from "react";
2
- export function KeepAlive() {
3
- // Exit the app after 5 seconds
4
- React.useEffect(() => {
5
- const timer = setInterval(() => { }, 5 * 1000);
6
- return function cleanup() {
7
- clearInterval(timer);
8
- };
9
- }, []);
10
- return null;
11
- }
@@ -1,43 +0,0 @@
1
- import * as React from "react";
2
- import * as Ink from "ink";
3
- import * as CommitMetadata from "../core/CommitMetadata.js";
4
- import { colors } from "../core/colors.js";
5
- import { invariant } from "../core/invariant.js";
6
- import * as json from "../core/json.js";
7
- import { Await } from "./Await.js";
8
- import { Store } from "./Store.js";
9
- export function LocalCommitStatus(props) {
10
- const argv = Store.useState((state) => state.argv);
11
- invariant(argv, "argv must exist");
12
- const fallback = (React.createElement(Ink.Text, { color: colors.yellow }, "Fetching PR status from Github..."));
13
- if (argv["mock-metadata"]) {
14
- return (React.createElement(Await, { fallback: fallback, function: mock_metadata }, props.children));
15
- }
16
- return (React.createElement(Await, { fallback: fallback, function: gather_metadata }, props.children));
17
- }
18
- async function mock_metadata() {
19
- const module = await import("../__fixtures__/metadata.js");
20
- const deserialized = json.deserialize(module.METADATA);
21
- Store.setState((state) => {
22
- Object.assign(state, deserialized);
23
- state.step = "status";
24
- });
25
- }
26
- async function gather_metadata() {
27
- const actions = Store.getState().actions;
28
- try {
29
- const commit_range = await CommitMetadata.range();
30
- Store.setState((state) => {
31
- state.commit_range = commit_range;
32
- state.step = "status";
33
- });
34
- }
35
- catch (err) {
36
- actions.error("Unable to retrieve local commit status.");
37
- if (err instanceof Error) {
38
- if (actions.isDebug()) {
39
- actions.error(err.message);
40
- }
41
- }
42
- }
43
- }
@@ -1,157 +0,0 @@
1
- import * as React from "react";
2
- import fs from "node:fs";
3
- import * as Ink from "ink";
4
- import * as CommitMetadata from "../core/CommitMetadata.js";
5
- import * as Metadata from "../core/Metadata.js";
6
- import { cli } from "../core/cli.js";
7
- import { colors } from "../core/colors.js";
8
- import { invariant } from "../core/invariant.js";
9
- import { short_id } from "../core/short_id.js";
10
- import { Await } from "./Await.js";
11
- import { Brackets } from "./Brackets.js";
12
- import { FormatText } from "./FormatText.js";
13
- import { Parens } from "./Parens.js";
14
- import { Store } from "./Store.js";
15
- export function LocalMergeRebase() {
16
- return (React.createElement(Await, { fallback: React.createElement(Ink.Text, { color: colors.yellow }, "Rebasing commits..."), function: run }));
17
- }
18
- async function run() {
19
- const state = Store.getState();
20
- const actions = state.actions;
21
- const argv = state.argv;
22
- const branch_name = state.branch_name;
23
- const commit_range = state.commit_range;
24
- const master_branch = state.master_branch;
25
- const cwd = state.cwd;
26
- const repo_root = state.repo_root;
27
- invariant(argv, "argv must exist");
28
- invariant(branch_name, "branch_name must exist");
29
- invariant(commit_range, "commit_range must exist");
30
- invariant(cwd, "cwd must exist");
31
- invariant(repo_root, "repo_root must exist");
32
- // always listen for SIGINT event and restore git state
33
- process.once("SIGINT", handle_exit);
34
- const temp_branch_name = `${branch_name}_${short_id()}`;
35
- try {
36
- // must perform rebase from repo root for applying git patch
37
- process.chdir(repo_root);
38
- await cli(`pwd`);
39
- await cli(`git fetch --no-tags -v origin ${master_branch}:${master_branch}`);
40
- const master_sha = (await cli(`git rev-parse ${master_branch}`)).stdout;
41
- const rebase_merge_base = master_sha;
42
- // create temporary branch based on merge base
43
- await cli(`git checkout -b ${temp_branch_name} ${rebase_merge_base}`);
44
- for (let i = 0; i < commit_range.commit_list.length; i++) {
45
- const commit = commit_range.commit_list[i];
46
- const commit_pr = commit_range.pr_lookup[commit.branch_id || ""];
47
- // drop commits that are in groups of merged PRs
48
- const merged_pr = commit_pr?.state === "MERGED";
49
- if (merged_pr) {
50
- if (actions.isDebug()) {
51
- actions.output(React.createElement(FormatText, { wrapper: React.createElement(Ink.Text, { color: colors.yellow, wrap: "truncate-end" }), message: "Dropping {commit_message} {pr_status}", values: {
52
- commit_message: React.createElement(Brackets, null, commit.subject_line),
53
- pr_status: React.createElement(Parens, null, "MERGED"),
54
- } }));
55
- }
56
- continue;
57
- }
58
- // cherry-pick and amend commits one by one
59
- if (actions.isDebug()) {
60
- actions.output(React.createElement(FormatText, { wrapper: React.createElement(Ink.Text, { color: colors.yellow, wrap: "truncate-end" }), message: "Picking {commit_message}", values: {
61
- commit_message: React.createElement(Brackets, null, commit.subject_line),
62
- } }));
63
- }
64
- // ensure clean base to avoid conflicts when applying patch
65
- await cli(`git clean -fd`);
66
- // create, apply and cleanup patch
67
- await cli(`git format-patch -1 ${commit.sha} --stdout > ${PATCH_FILE}`);
68
- await cli(`git apply ${PATCH_FILE}`);
69
- await cli(`rm ${PATCH_FILE}`);
70
- // add all changes to stage
71
- await cli(`git add --all`);
72
- let new_message;
73
- if (commit.branch_id) {
74
- new_message = await Metadata.write(commit.full_message, commit.branch_id);
75
- }
76
- else {
77
- new_message = commit.full_message;
78
- }
79
- const git_commit_comand = [`git commit -m "${new_message}"`];
80
- if (argv.verify === false) {
81
- git_commit_comand.push("--no-verify");
82
- }
83
- await cli(git_commit_comand);
84
- if (commit.branch_id && !commit_pr) {
85
- if (actions.isDebug()) {
86
- actions.output(React.createElement(FormatText, { wrapper: React.createElement(Ink.Text, { color: colors.yellow, wrap: "truncate-end" }), message: "Cleaning up unused group {group}", values: {
87
- group: React.createElement(Brackets, null, commit.branch_id),
88
- } }));
89
- }
90
- // missing PR, clear branch id from commit
91
- const new_message = await Metadata.remove(commit.full_message);
92
- await cli(`git commit --amend -m "${new_message}"`);
93
- }
94
- }
95
- // after all commits have been cherry-picked and amended
96
- // move the branch pointer to the newly created temporary branch
97
- // now we are in locally in sync with github and on the original branch
98
- await cli(`git branch -f ${branch_name} ${temp_branch_name}`);
99
- restore_git();
100
- const next_commit_range = await CommitMetadata.range();
101
- actions.set((state) => {
102
- state.commit_range = next_commit_range;
103
- state.step = "status";
104
- });
105
- }
106
- catch (err) {
107
- actions.error("Unable to rebase.");
108
- if (err instanceof Error) {
109
- if (actions.isDebug()) {
110
- actions.error(err.message);
111
- }
112
- }
113
- handle_exit();
114
- }
115
- // cleanup git operations if cancelled during manual rebase
116
- function restore_git() {
117
- // signint handler MUST run synchronously
118
- // trying to use `await cli(...)` here will silently fail since
119
- // all children processes receive the SIGINT signal
120
- const spawn_options = { ignoreExitCode: true };
121
- // always clean up any patch files
122
- cli.sync(`rm ${PATCH_FILE}`, spawn_options);
123
- // always hard reset and clean to allow subsequent checkout
124
- // if there are files checkout will fail and cascade fail subsequent commands
125
- cli.sync(`git reset --hard`, spawn_options);
126
- cli.sync(`git clean -df`, spawn_options);
127
- // always put self back in original branch
128
- cli.sync(`git checkout ${branch_name}`, spawn_options);
129
- // ...and cleanup temporary branch
130
- cli.sync(`git branch -D ${temp_branch_name}`, spawn_options);
131
- if (commit_range) {
132
- // ...and cleanup pr group branches
133
- for (const group of commit_range.group_list) {
134
- cli.sync(`git branch -D ${group.id}`, spawn_options);
135
- }
136
- }
137
- // restore back to original dir
138
- invariant(cwd, "cwd must exist");
139
- if (fs.existsSync(cwd)) {
140
- process.chdir(cwd);
141
- }
142
- cli.sync(`pwd`, spawn_options);
143
- }
144
- function handle_exit() {
145
- actions.output(React.createElement(Ink.Text, { color: colors.yellow },
146
- "Restoring ",
147
- React.createElement(Brackets, null, branch_name),
148
- "..."));
149
- restore_git();
150
- actions.output(React.createElement(Ink.Text, { color: colors.yellow },
151
- "Restored ",
152
- React.createElement(Brackets, null, branch_name),
153
- "."));
154
- actions.exit(6);
155
- }
156
- }
157
- const PATCH_FILE = "git-stack-cli-patch.patch";