git-stack-cli 2.5.2 → 2.6.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.
@@ -10,6 +10,7 @@ type Props = {
10
10
  value?: string;
11
11
  onChange?: (value: string) => void;
12
12
  onSubmit?: (value: string) => void;
13
+ onCancel?: () => void;
13
14
  };
14
15
 
15
16
  export function TextInput(props: Props) {
@@ -44,7 +45,13 @@ export function TextInput(props: Props) {
44
45
 
45
46
  // console.debug("[useInput]", { input, key });
46
47
 
47
- if (key.backspace || key.delete) {
48
+ if (key.escape) {
49
+ if (value === "") {
50
+ props.onCancel?.();
51
+ } else {
52
+ next_value = "";
53
+ }
54
+ } else if (key.backspace || key.delete) {
48
55
  next_value = value.slice(0, -1);
49
56
  } else if (key.return) {
50
57
  props.onSubmit?.(next_value);
package/src/command.ts CHANGED
@@ -30,6 +30,12 @@ export async function command() {
30
30
  (yargs) => yargs,
31
31
  )
32
32
 
33
+ .command(
34
+ ["update", "upgrade"],
35
+ "Check and install the latest version of git stack",
36
+ (yargs) => yargs,
37
+ )
38
+
33
39
  .option("verbose", GlobalOptions.verbose)
34
40
 
35
41
  // yargs default wraps to 80 columns
@@ -86,13 +92,6 @@ const DefaultOptions = {
86
92
  ].join("\n"),
87
93
  },
88
94
 
89
- "update": {
90
- type: "boolean",
91
- alias: ["u", "upgrade"],
92
- default: false,
93
- description: "Check and install the latest version",
94
- },
95
-
96
95
  "branch": {
97
96
  type: "string",
98
97
  alias: ["b"],
@@ -0,0 +1,15 @@
1
+ import * as React from "react";
2
+
3
+ import { Await } from "~/app/Await";
4
+ import { Store } from "~/app/Store";
5
+
6
+ export function Update() {
7
+ return <Await fallback={null} function={run} />;
8
+ }
9
+
10
+ async function run() {
11
+ const state = Store.getState();
12
+ const actions = state.actions;
13
+
14
+ actions.exit(0);
15
+ }
@@ -39,6 +39,8 @@ export async function range(commit_group_map?: CommitGroupMap) {
39
39
  let id = commit.branch_id;
40
40
  let title = commit.title || id;
41
41
 
42
+ // console.debug({ commit, id });
43
+
42
44
  // use commit map if provided (via select commit ranges)
43
45
  if (commit_group_map) {
44
46
  const group = commit_group_map[commit.sha];
@@ -50,7 +52,7 @@ export async function range(commit_group_map?: CommitGroupMap) {
50
52
  }
51
53
 
52
54
  if (!id) {
53
- // console.debug("INVALID", "MISSING ID", commit.message);
55
+ // console.debug("INVALID", "MISSING ID");
54
56
  invalid = true;
55
57
  }
56
58
 
@@ -61,13 +63,12 @@ export async function range(commit_group_map?: CommitGroupMap) {
61
63
  if (group_map.has(id) && last_key !== id) {
62
64
  // if we've seen this id before and it's not
63
65
  // the last added key then we are out of order
64
- // console.debug("INVALID", "OUT OF ORDER", commit.message, id);
66
+ // console.debug("INVALID", "OUT OF ORDER");
65
67
  invalid = true;
66
68
  }
67
69
  } else {
68
- // console.debug("INVALID", "NEW COMMIT", { commit });
70
+ // console.debug("INVALID", "NEW COMMIT");
69
71
  invalid = true;
70
-
71
72
  id = UNASSIGNED;
72
73
  }
73
74
 
@@ -231,4 +232,4 @@ function lines(value: string) {
231
232
  return value.split("\n");
232
233
  }
233
234
 
234
- const UNASSIGNED = "unassigned";
235
+ export const UNASSIGNED = "unassigned";
@@ -67,14 +67,67 @@ test("git-revise-todo handles double quotes in commit message", () => {
67
67
  [
68
68
  //force line break
69
69
  "++ pick f143d03c723c",
70
- '[new] invalid \\"by me\\" quotes',
70
+ '[new] invalid "by me" quotes',
71
71
  "",
72
72
  "git-stack-id: 6Ak-qn+5Z",
73
- 'git-stack-title: [new] invalid \\"by me\\" quotes',
73
+ 'git-stack-title: [new] invalid "by me" quotes',
74
74
  ].join("\n"),
75
75
  );
76
76
  });
77
77
 
78
+ test("git-revise-todo from commit range with single new commit", () => {
79
+ const rebase_group_index = 0;
80
+ const commit_range = SYNC_WITH_UNASSIGNED;
81
+
82
+ const git_revise_todo = GitReviseTodo({ rebase_group_index, commit_range });
83
+
84
+ const expected = [
85
+ "++ pick 55771391b49e",
86
+ "head~7",
87
+ "",
88
+ "git-stack-id: gs---4gvxa-5v-2mx26",
89
+ "git-stack-title: pr-title",
90
+ "",
91
+ "++ pick 391476bbfc6b",
92
+ "head~6",
93
+ "",
94
+ "git-stack-id: gs---4gvxa-5v-2mx26",
95
+ "git-stack-title: pr-title",
96
+ "",
97
+ "++ pick 5a98cf8f0406",
98
+ "head~5",
99
+ "",
100
+ "git-stack-id: gs---4gvxa-5v-2mx26",
101
+ "git-stack-title: pr-title",
102
+ "",
103
+ "++ pick e820018cb370",
104
+ "head~4",
105
+ "",
106
+ "git-stack-id: gs---4gvxa-5v-2mx26",
107
+ "git-stack-title: pr-title",
108
+ "",
109
+ "++ pick e6d1dfc7ec00",
110
+ "head~3",
111
+ "",
112
+ "git-stack-id: gs---4gvxa-5v-2mx26",
113
+ "git-stack-title: pr-title",
114
+ "",
115
+ "++ pick a26f21025a55",
116
+ "head~2",
117
+ "",
118
+ "git-stack-id: gs---4gvxa-5v-2mx26",
119
+ "git-stack-title: pr-title",
120
+ "",
121
+ "++ pick 90667fe97e05",
122
+ "head~1",
123
+ "",
124
+ "++ pick b61c5b09a4b7",
125
+ "head",
126
+ ].join("\n");
127
+
128
+ expect(git_revise_todo).toBe(expected);
129
+ });
130
+
78
131
  const SINGLE_COMMIT_EXISTING_GROUP: CommitMetadata.CommitRange = {
79
132
  invalid: false,
80
133
  group_list: [
@@ -654,3 +707,145 @@ const COMMIT_MESSAGE_WITH_QUOTES: CommitMetadata.CommitRange = {
654
707
  pr_lookup: {},
655
708
  UNASSIGNED: "unassigned",
656
709
  };
710
+
711
+ // capture via `throw new Error` in `ManualRebase`
712
+ // doc-link capture-git-revise-todo
713
+ const SYNC_WITH_UNASSIGNED: CommitMetadata.CommitRange = {
714
+ invalid: false,
715
+ group_list: [
716
+ {
717
+ id: "gs---4gvxa-5v-2mx26",
718
+ title: "pr-title",
719
+ pr: null,
720
+ base: "master",
721
+ dirty: true,
722
+ commits: [
723
+ {
724
+ sha: "55771391b49e301f51b22cbc2b745e8d3e4a357a",
725
+ full_message: "head~7",
726
+ subject_line: "head~7",
727
+ branch_id: "gs---4gvxa-5v-2mx26",
728
+ title: "pr-title",
729
+ },
730
+ {
731
+ sha: "391476bbfc6b77b60a3ef7fa97155496a9f8f27f",
732
+ full_message: "head~6",
733
+ subject_line: "head~6",
734
+ branch_id: "gs---4gvxa-5v-2mx26",
735
+ title: "pr-title",
736
+ },
737
+ {
738
+ sha: "5a98cf8f0406712405d41af07c3a012f72ad36fa",
739
+ full_message: "head~5",
740
+ subject_line: "head~5",
741
+ branch_id: "gs---4gvxa-5v-2mx26",
742
+ title: "pr-title",
743
+ },
744
+ {
745
+ sha: "e820018cb370bb6cda118dc649e841c75d797188",
746
+ full_message: "head~4",
747
+ subject_line: "head~4",
748
+ branch_id: "gs---4gvxa-5v-2mx26",
749
+ title: "pr-title",
750
+ },
751
+ {
752
+ sha: "e6d1dfc7ec007468712bfc015884cc22bfa79e1d",
753
+ full_message: "head~3",
754
+ subject_line: "head~3",
755
+ branch_id: "gs---4gvxa-5v-2mx26",
756
+ title: "pr-title",
757
+ },
758
+ {
759
+ sha: "a26f21025a558968554c439ab9b942d5fe84bccb",
760
+ full_message: "head~2",
761
+ subject_line: "head~2",
762
+ branch_id: "gs---4gvxa-5v-2mx26",
763
+ title: "pr-title",
764
+ },
765
+ ],
766
+ },
767
+ {
768
+ id: "unassigned",
769
+ title: "allow_unassigned",
770
+ pr: null,
771
+ base: null,
772
+ dirty: true,
773
+ commits: [
774
+ {
775
+ sha: "90667fe97e059e8285e070d6268f2b4035b2ebd4",
776
+ full_message: "head~1",
777
+ subject_line: "head~1",
778
+ branch_id: "unassigned",
779
+ title: "allow_unassigned",
780
+ },
781
+ {
782
+ sha: "b61c5b09a4b7c9dcff9a9071386b134997569a01",
783
+ full_message: "head",
784
+ subject_line: "head",
785
+ branch_id: "unassigned",
786
+ title: "allow_unassigned",
787
+ },
788
+ ],
789
+ },
790
+ ],
791
+ commit_list: [
792
+ {
793
+ sha: "55771391b49e301f51b22cbc2b745e8d3e4a357a",
794
+ full_message: "head~7",
795
+ subject_line: "head~7",
796
+ branch_id: "gs---4gvxa-5v-2mx26",
797
+ title: "pr-title",
798
+ },
799
+ {
800
+ sha: "391476bbfc6b77b60a3ef7fa97155496a9f8f27f",
801
+ full_message: "head~6",
802
+ subject_line: "head~6",
803
+ branch_id: "gs---4gvxa-5v-2mx26",
804
+ title: "pr-title",
805
+ },
806
+ {
807
+ sha: "5a98cf8f0406712405d41af07c3a012f72ad36fa",
808
+ full_message: "head~5",
809
+ subject_line: "head~5",
810
+ branch_id: "gs---4gvxa-5v-2mx26",
811
+ title: "pr-title",
812
+ },
813
+ {
814
+ sha: "e820018cb370bb6cda118dc649e841c75d797188",
815
+ full_message: "head~4",
816
+ subject_line: "head~4",
817
+ branch_id: "gs---4gvxa-5v-2mx26",
818
+ title: "pr-title",
819
+ },
820
+ {
821
+ sha: "e6d1dfc7ec007468712bfc015884cc22bfa79e1d",
822
+ full_message: "head~3",
823
+ subject_line: "head~3",
824
+ branch_id: "gs---4gvxa-5v-2mx26",
825
+ title: "pr-title",
826
+ },
827
+ {
828
+ sha: "a26f21025a558968554c439ab9b942d5fe84bccb",
829
+ full_message: "head~2",
830
+ subject_line: "head~2",
831
+ branch_id: "gs---4gvxa-5v-2mx26",
832
+ title: "pr-title",
833
+ },
834
+ {
835
+ sha: "90667fe97e059e8285e070d6268f2b4035b2ebd4",
836
+ full_message: "head~1",
837
+ subject_line: "head~1",
838
+ branch_id: "unassigned",
839
+ title: "allow_unassigned",
840
+ },
841
+ {
842
+ sha: "b61c5b09a4b7c9dcff9a9071386b134997569a01",
843
+ full_message: "head",
844
+ subject_line: "head",
845
+ branch_id: "unassigned",
846
+ title: "allow_unassigned",
847
+ },
848
+ ],
849
+ pr_lookup: {},
850
+ UNASSIGNED: "unassigned",
851
+ };
@@ -2,14 +2,13 @@ import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
3
 
4
4
  import { Store } from "~/app/Store";
5
+ import * as CommitMetadata from "~/core/CommitMetadata";
5
6
  import * as Metadata from "~/core/Metadata";
6
7
  import { cli } from "~/core/cli";
7
8
  import { get_tmp_dir } from "~/core/get_tmp_dir";
8
9
  import { invariant } from "~/core/invariant";
9
10
  import { safe_rm } from "~/core/safe_rm";
10
11
 
11
- import type * as CommitMetadata from "~/core/CommitMetadata";
12
-
13
12
  // https://git-revise.readthedocs.io/en/latest/man.html#interactive-mode
14
13
  //
15
14
  // # Interactive Revise Todos(4 commands)
@@ -58,6 +57,7 @@ export function GitReviseTodo(args: Args): string {
58
57
  const commit_list = [];
59
58
 
60
59
  const group_list = args.commit_range.group_list;
60
+ // console.debug({ group_list });
61
61
 
62
62
  for (let i = args.rebase_group_index; i < group_list.length; i++) {
63
63
  const group = group_list[i];
@@ -67,6 +67,7 @@ export function GitReviseTodo(args: Args): string {
67
67
  }
68
68
  }
69
69
 
70
+ // console.debug({ commit_list });
70
71
  const todo = GitReviseTodo.todo({ commit_list });
71
72
  return todo;
72
73
  }
@@ -79,26 +80,28 @@ GitReviseTodo.todo = function todo(args: CommitListArgs) {
79
80
  const entry_list = [];
80
81
 
81
82
  for (const commit of args.commit_list) {
82
- // update git commit message with stack id
83
- const id = commit.branch_id;
84
- const title = commit.title;
85
-
86
- invariant(id, "commit.branch_id must exist");
87
- invariant(title, "commit.title must exist");
88
-
89
- const metadata = { id, title };
90
-
91
- const unsafe_message_with_id = Metadata.write(commit.full_message, metadata);
92
-
93
- let message_with_id = unsafe_message_with_id;
94
-
95
83
  // get first 12 characters of commit sha
96
84
  const sha = commit.sha.slice(0, 12);
97
85
 
98
86
  // generate git revise entry
99
- const entry_lines = [`++ pick ${sha}`, message_with_id];
100
- const entry = entry_lines.join("\n");
87
+ const entry_lines = [`++ pick ${sha}`];
101
88
 
89
+ // update git commit message with stack id
90
+ const id = commit.branch_id;
91
+ if (id == null || id === CommitMetadata.UNASSIGNED) {
92
+ entry_lines.push(commit.full_message);
93
+ } else {
94
+ // console.debug({ commit });
95
+ const title = commit.title;
96
+ invariant(title, "commit.title must exist");
97
+
98
+ const metadata = { id, title };
99
+ const unsafe_message_with_id = Metadata.write(commit.full_message, metadata);
100
+ const message_with_id = unsafe_message_with_id;
101
+ entry_lines.push(message_with_id);
102
+ }
103
+
104
+ const entry = entry_lines.join("\n");
102
105
  entry_list.push(entry);
103
106
  }
104
107
 
@@ -129,10 +129,10 @@ test("write handles double quotes", () => {
129
129
  expect(Metadata.write(body, metadata)).toEqual(
130
130
  [
131
131
  // force line break
132
- 'Revert \\"[abc / 123] subject (#1234)\\"',
132
+ 'Revert "[abc / 123] subject (#1234)"',
133
133
  "",
134
134
  "git-stack-id: abc123",
135
- 'git-stack-title: Revert \\"[abc / 123] subject (#1234)\\"',
135
+ 'git-stack-title: Revert "[abc / 123] subject (#1234)"',
136
136
  ].join("\n"),
137
137
  );
138
138
  });