git-stack-cli 1.8.3 → 1.9.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.
@@ -61,7 +61,10 @@ export function GitReviseTodo(args: Args): string {
61
61
  commit.full_message,
62
62
  metadata
63
63
  );
64
- const message_with_id = unsafe_message_with_id.replace(/"/g, '\\"');
64
+
65
+ let message_with_id = unsafe_message_with_id;
66
+
67
+ message_with_id = message_with_id.replace(/[^\\]"/g, '\\"');
65
68
 
66
69
  // get first 12 characters of commit sha
67
70
  const sha = commit.sha.slice(0, 12);
@@ -52,6 +52,91 @@ test("write handles bulleted lists", () => {
52
52
  );
53
53
  });
54
54
 
55
+ test("read handles slashes in branch name", () => {
56
+ const body = [
57
+ "[fix] slash in branch name",
58
+ "",
59
+ "git-stack-id: dev/noah/fix-slash-branch",
60
+ "git-stack-title: fix slash branch",
61
+ ].join("\n");
62
+
63
+ const metadata = Metadata.read(body);
64
+
65
+ expect(metadata).toEqual({
66
+ id: "dev/noah/fix-slash-branch",
67
+ title: "fix slash branch",
68
+ });
69
+ });
70
+
71
+ test("write handles bulleted lists", () => {
72
+ const body = [
73
+ "[feat] implement various features",
74
+ "",
75
+ "- keyboard modality escape key",
76
+ "- centralize settings",
77
+ "- move logic inside if branch",
78
+ "",
79
+ "git-stack-id: DdKIFyufW",
80
+ ].join("\n");
81
+
82
+ const metadata = {
83
+ id: "fix-slash-branch",
84
+ title: "fix slash branch",
85
+ };
86
+
87
+ expect(Metadata.write(body, metadata)).toEqual(
88
+ [
89
+ "[feat] implement various features",
90
+ "",
91
+ "- keyboard modality escape key",
92
+ "- centralize settings",
93
+ "- move logic inside if branch",
94
+ "",
95
+ "git-stack-id: fix-slash-branch",
96
+ "git-stack-title: fix slash branch",
97
+ ].join("\n")
98
+ );
99
+ });
100
+
101
+ test("read handles double quotes", () => {
102
+ const body = [
103
+ 'Revert "[abc / 123] subject (#1234)"',
104
+ "",
105
+ "git-stack-id: dev/noah/fix-slash-branch",
106
+ 'git-stack-title: Revert \\"[abc / 123] subject (#1234)\\"',
107
+ ].join("\n");
108
+
109
+ const metadata = Metadata.read(body);
110
+
111
+ expect(metadata).toEqual({
112
+ id: "dev/noah/fix-slash-branch",
113
+ title: 'Revert \\"[abc / 123] subject (#1234)\\"',
114
+ });
115
+ });
116
+
117
+ test("write handles double quotes", () => {
118
+ const body = [
119
+ // force line break
120
+ 'Revert "[abc / 123] subject (#1234)"',
121
+ "",
122
+ ].join("\n");
123
+
124
+ const metadata = {
125
+ id: "abc123",
126
+ title: 'Revert "[abc / 123] subject (#1234)"',
127
+ };
128
+
129
+ expect(Metadata.write(body, metadata)).toEqual(
130
+ [
131
+ // force line break
132
+ 'Revert \\"[abc / 123] subject (#1234)\\"',
133
+ "",
134
+ "git-stack-id: abc123",
135
+ 'git-stack-title: Revert \\"[abc / 123] subject (#1234)\\"',
136
+ ].join("\n")
137
+ );
138
+ });
139
+
55
140
  test("removes metadata", () => {
56
141
  const body = [
57
142
  "[feat] implement various features",
@@ -14,9 +14,6 @@ type OutputMetadataValues = {
14
14
  export function write(message: string, values: InputMetadataValues) {
15
15
  let result = message;
16
16
 
17
- // escape double-quote for cli
18
- result = safe_quote(result);
19
-
20
17
  // remove any previous metadata lines
21
18
  result = remove(result);
22
19
 
@@ -26,7 +23,9 @@ export function write(message: string, values: InputMetadataValues) {
26
23
  line_list.push(TEMPLATE.group_title(values.title));
27
24
  }
28
25
 
29
- const new_message = line_list.join("\n");
26
+ let new_message = line_list.join("\n");
27
+
28
+ new_message = safe_quote(new_message);
30
29
 
31
30
  return new_message;
32
31
  }
@@ -73,6 +72,7 @@ const TEMPLATE = {
73
72
  };
74
73
 
75
74
  const RE = {
76
- stack_id: new RegExp(TEMPLATE.stack_id("(?<id>[a-z0-9-+=]+)"), "i"),
75
+ // https://regex101.com/r/wLmGVq/1
76
+ stack_id: new RegExp(`${TEMPLATE.stack_id("(?<id>[^\\s]+)")}`, "i"),
77
77
  group_title: new RegExp(TEMPLATE.group_title("(?<title>[^\\n^\\r]+)"), "i"),
78
78
  };
package/src/index.tsx CHANGED
@@ -14,6 +14,7 @@ command()
14
14
 
15
15
  Store.setState((state) => {
16
16
  state.ink = ink;
17
+ state.process_argv = process.argv;
17
18
  state.argv = argv;
18
19
  state.cwd = process.cwd();
19
20
  });