Skip to main content

git_policy_cli/
command_checkout_table.rs

1//! What:
2//!  The complete option tables of `git checkout` and `git switch` in Git 2.56.0.
3//! Why:
4//!  Both commands create branches explicitly (`-b`,
5//!  `-c`,
6//!  `--orphan`,
7//!  `--track`) and
8//!      implicitly (a name that matches one remote branch).
9//!  The tables are assembled as
10//!      Git assembles them:
11//!  the command's own rows,
12//!  then the shared groups
13//!      (builtin/checkout.c:1786-1847,
14//!  2118-2129,
15//!  2170-2179).
16//!
17//! In TS you'd write (pseudocode):
18//! ```ts
19//! // export const CHECKOUT_TABLE: readonly OptionSpec[] = [ ... ];
20//! ```
21
22/// What:
23///  Bring the row type,
24///  its builder and the arity names into this file.
25///  `UNREAD` is the
26///       identifier of rows no branch-creation fact reads.
27/// Why:
28///   The tables are data for the shared tokenizer.
29///
30/// In TS you'd write (pseudocode):
31/// ```ts
32/// import { Arity, type OptionSpec, row, UNREAD } from './command_options.ts';
33/// ```
34use super::command_options::{Arity, OptionSpec, UNREAD, row};
35
36/// `checkout -b <branch>`,
37///  `switch -c`/`--create <branch>`.
38pub const NEW_BRANCH: u16 = 1;
39/// `checkout -B <branch>`,
40///  `switch -C`/`--force-create <branch>`.
41pub const NEW_BRANCH_FORCE: u16 = 2;
42/// `--orphan <new-branch>`.
43pub const ORPHAN: u16 = 3;
44/// `-t`,
45///  `--track[=(direct|inherit)]`;
46///  `--no-track` writes the same variable.
47pub const TRACK: u16 = 4;
48/// `--guess`,
49///  `--no-guess`.
50pub const GUESS: u16 = 5;
51/// `-d`,
52///  `--detach`.
53pub const DETACH: u16 = 6;
54/// `checkout -p`/`--patch`.
55pub const PATCH: u16 = 7;
56/// `checkout -2`/`--ours` and `-3`/`--theirs`.
57pub const STAGE: u16 = 8;
58/// `checkout --overlay`,
59///  `--no-overlay`.
60pub const OVERLAY: u16 = 9;
61
62/// What:
63///  `git checkout`:
64///  `checkout_options`,
65///  then the common,
66///  switch-branch and
67///       checkout-path groups.
68///  `Some(b'b')` with `None` is an option that has only a letter.
69/// Why:
70///   `-b` and `-B` take the branch name as a value;
71///  `--track` and
72///       `--recurse-submodules` take an attached value only.
73///
74/// In TS you'd write (pseudocode):
75/// ```ts
76/// export const CHECKOUT_TABLE = [row(NEW_BRANCH, 'b', undefined, 'required', true), /* ... */] as const;
77/// ```
78pub const CHECKOUT_TABLE: &[OptionSpec] = &[
79    row(NEW_BRANCH, Some(b'b'), None, Arity::Required, true),
80    row(NEW_BRANCH_FORCE, Some(b'B'), None, Arity::Required, true),
81    row(UNREAD, Some(b'l'), None, Arity::None, true),
82    row(GUESS, None, Some("guess"), Arity::None, true),
83    row(OVERLAY, None, Some("overlay"), Arity::None, true),
84    row(UNREAD, None, Some("auto-advance"), Arity::None, true),
85    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
86    row(
87        UNREAD,
88        None,
89        Some("recurse-submodules"),
90        Arity::Optional,
91        true,
92    ),
93    row(UNREAD, None, Some("progress"), Arity::None, true),
94    row(UNREAD, Some(b'm'), Some("merge"), Arity::None, true),
95    row(UNREAD, None, Some("conflict"), Arity::Required, true),
96    row(DETACH, Some(b'd'), Some("detach"), Arity::None, true),
97    row(TRACK, Some(b't'), Some("track"), Arity::Optional, true),
98    row(UNREAD, Some(b'f'), Some("force"), Arity::None, true),
99    row(ORPHAN, None, Some("orphan"), Arity::Required, true),
100    row(UNREAD, None, Some("overwrite-ignore"), Arity::None, true),
101    row(
102        UNREAD,
103        None,
104        Some("ignore-other-worktrees"),
105        Arity::None,
106        true,
107    ),
108    row(STAGE, Some(b'2'), Some("ours"), Arity::None, false),
109    row(STAGE, Some(b'3'), Some("theirs"), Arity::None, false),
110    row(PATCH, Some(b'p'), Some("patch"), Arity::None, true),
111    row(UNREAD, Some(b'U'), Some("unified"), Arity::Required, false),
112    row(
113        UNREAD,
114        None,
115        Some("inter-hunk-context"),
116        Arity::Required,
117        false,
118    ),
119    row(
120        UNREAD,
121        None,
122        Some("ignore-skip-worktree-bits"),
123        Arity::None,
124        true,
125    ),
126    row(
127        UNREAD,
128        None,
129        Some("pathspec-from-file"),
130        Arity::Required,
131        true,
132    ),
133    row(UNREAD, None, Some("pathspec-file-nul"), Arity::None, true),
134];
135
136/// What:
137///  `git switch`:
138///  `switch_options`,
139///  then the common and switch-branch groups.
140/// Why:
141///   `switch` has no path options;
142///  `-c` and `-C` have long names and can be negated.
143///
144/// In TS you'd write (pseudocode):
145/// ```ts
146/// export const SWITCH_TABLE = [row(NEW_BRANCH, 'c', 'create', 'required', true), /* ... */] as const;
147/// ```
148pub const SWITCH_TABLE: &[OptionSpec] = &[
149    row(
150        NEW_BRANCH,
151        Some(b'c'),
152        Some("create"),
153        Arity::Required,
154        true,
155    ),
156    row(
157        NEW_BRANCH_FORCE,
158        Some(b'C'),
159        Some("force-create"),
160        Arity::Required,
161        true,
162    ),
163    row(GUESS, None, Some("guess"), Arity::None, true),
164    row(UNREAD, None, Some("discard-changes"), Arity::None, true),
165    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
166    row(
167        UNREAD,
168        None,
169        Some("recurse-submodules"),
170        Arity::Optional,
171        true,
172    ),
173    row(UNREAD, None, Some("progress"), Arity::None, true),
174    row(UNREAD, Some(b'm'), Some("merge"), Arity::None, true),
175    row(UNREAD, None, Some("conflict"), Arity::Required, true),
176    row(DETACH, Some(b'd'), Some("detach"), Arity::None, true),
177    row(TRACK, Some(b't'), Some("track"), Arity::Optional, true),
178    row(UNREAD, Some(b'f'), Some("force"), Arity::None, true),
179    row(ORPHAN, None, Some("orphan"), Arity::Required, true),
180    row(UNREAD, None, Some("overwrite-ignore"), Arity::None, true),
181    row(
182        UNREAD,
183        None,
184        Some("ignore-other-worktrees"),
185        Arity::None,
186        true,
187    ),
188];