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/// `-f`/`--force`: throw away local changes.
62pub const FORCE: u16 = 10;
63/// `switch --discard-changes`: throw away local changes.
64pub const DISCARD_CHANGES: u16 = 11;
65/// `--pathspec-from-file`: the paths come from a file, so the command is the path form.
66pub const PATHSPEC_FROM_FILE: u16 = 12;
67
68/// What:
69///  `git checkout`:
70///  `checkout_options`,
71///  then the common,
72///  switch-branch and
73///       checkout-path groups.
74///  `Some(b'b')` with `None` is an option that has only a letter.
75/// Why:
76///   `-b` and `-B` take the branch name as a value;
77///  `--track` and
78///       `--recurse-submodules` take an attached value only.
79///
80/// In TS you'd write (pseudocode):
81/// ```ts
82/// export const CHECKOUT_TABLE = [row(NEW_BRANCH, 'b', undefined, 'required', true), /* ... */] as const;
83/// ```
84pub const CHECKOUT_TABLE: &[OptionSpec] = &[
85    row(NEW_BRANCH, Some(b'b'), None, Arity::Required, true),
86    row(NEW_BRANCH_FORCE, Some(b'B'), None, Arity::Required, true),
87    row(UNREAD, Some(b'l'), None, Arity::None, true),
88    row(GUESS, None, Some("guess"), Arity::None, true),
89    row(OVERLAY, None, Some("overlay"), Arity::None, true),
90    row(UNREAD, None, Some("auto-advance"), Arity::None, true),
91    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
92    row(
93        UNREAD,
94        None,
95        Some("recurse-submodules"),
96        Arity::Optional,
97        true,
98    ),
99    row(UNREAD, None, Some("progress"), Arity::None, true),
100    row(UNREAD, Some(b'm'), Some("merge"), Arity::None, true),
101    row(UNREAD, None, Some("conflict"), Arity::Required, true),
102    row(DETACH, Some(b'd'), Some("detach"), Arity::None, true),
103    row(TRACK, Some(b't'), Some("track"), Arity::Optional, true),
104    row(FORCE, Some(b'f'), Some("force"), Arity::None, true),
105    row(ORPHAN, None, Some("orphan"), Arity::Required, true),
106    row(UNREAD, None, Some("overwrite-ignore"), Arity::None, true),
107    row(
108        UNREAD,
109        None,
110        Some("ignore-other-worktrees"),
111        Arity::None,
112        true,
113    ),
114    row(STAGE, Some(b'2'), Some("ours"), Arity::None, false),
115    row(STAGE, Some(b'3'), Some("theirs"), Arity::None, false),
116    row(PATCH, Some(b'p'), Some("patch"), Arity::None, true),
117    row(UNREAD, Some(b'U'), Some("unified"), Arity::Required, false),
118    row(
119        UNREAD,
120        None,
121        Some("inter-hunk-context"),
122        Arity::Required,
123        false,
124    ),
125    row(
126        UNREAD,
127        None,
128        Some("ignore-skip-worktree-bits"),
129        Arity::None,
130        true,
131    ),
132    row(
133        PATHSPEC_FROM_FILE,
134        None,
135        Some("pathspec-from-file"),
136        Arity::Required,
137        true,
138    ),
139    row(UNREAD, None, Some("pathspec-file-nul"), Arity::None, true),
140];
141
142/// What:
143///  `git switch`:
144///  `switch_options`,
145///  then the common and switch-branch groups.
146/// Why:
147///   `switch` has no path options;
148///  `-c` and `-C` have long names and can be negated.
149///
150/// In TS you'd write (pseudocode):
151/// ```ts
152/// export const SWITCH_TABLE = [row(NEW_BRANCH, 'c', 'create', 'required', true), /* ... */] as const;
153/// ```
154pub const SWITCH_TABLE: &[OptionSpec] = &[
155    row(
156        NEW_BRANCH,
157        Some(b'c'),
158        Some("create"),
159        Arity::Required,
160        true,
161    ),
162    row(
163        NEW_BRANCH_FORCE,
164        Some(b'C'),
165        Some("force-create"),
166        Arity::Required,
167        true,
168    ),
169    row(GUESS, None, Some("guess"), Arity::None, true),
170    row(DISCARD_CHANGES, None, Some("discard-changes"), Arity::None, true),
171    row(UNREAD, Some(b'q'), Some("quiet"), Arity::None, true),
172    row(
173        UNREAD,
174        None,
175        Some("recurse-submodules"),
176        Arity::Optional,
177        true,
178    ),
179    row(UNREAD, None, Some("progress"), Arity::None, true),
180    row(UNREAD, Some(b'm'), Some("merge"), Arity::None, true),
181    row(UNREAD, None, Some("conflict"), Arity::Required, true),
182    row(DETACH, Some(b'd'), Some("detach"), Arity::None, true),
183    row(TRACK, Some(b't'), Some("track"), Arity::Optional, true),
184    row(FORCE, Some(b'f'), Some("force"), Arity::None, true),
185    row(ORPHAN, None, Some("orphan"), Arity::Required, true),
186    row(UNREAD, None, Some("overwrite-ignore"), Arity::None, true),
187    row(
188        UNREAD,
189        None,
190        Some("ignore-other-worktrees"),
191        Arity::None,
192        true,
193    ),
194];