1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
//! What:
//! The names of the commands built into Git 2.56.0,
//! and the test "is this word one
//! of them".
//! Why:
//! Git never expands an alias whose name is a built-in command,
//! so a built-in word
//! is the command that runs.
//! Any other word may be an alias for anything,
//! including
//! `worktree add`,
//! and resolving aliases is not ported;
//! the caller needs to know
//! which of the two it is looking at without starting Git.
//!
//! In TS you'd write (pseudocode):
//! ```ts
//! // GIT_BUILTIN_COMMANDS.has('status') === true; GIT_BUILTIN_COMMANDS.has('st') === false
//! ```
/// What:
/// Every name `git --list-cmds=builtins` prints for Git 2.56.0,
/// in that order.
/// `&[&[u8]]` is a borrowed list of byte spellings baked into the program.
/// Sibling
/// the reader might expect:
/// `&[&str]`,
/// a list of UTF-8 texts.
/// Why:
/// Command words arrive as raw bytes and are compared without decoding,
/// so the
/// table holds bytes.
/// A test compares the whole table with real Git's own answer.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// const GIT_BUILTIN_COMMANDS: ReadonlySet<string> = new Set(['add', 'am', /* ... */]);
/// ```
pub const GIT_BUILTIN_COMMANDS: &[&[u8]] = &[
b"add",
b"am",
b"annotate",
b"apply",
b"archive",
b"backfill",
b"bisect",
b"blame",
b"branch",
b"bugreport",
b"bundle",
b"cat-file",
b"check-attr",
b"check-ignore",
b"check-mailmap",
b"check-ref-format",
b"checkout",
b"checkout--worker",
b"checkout-index",
b"cherry",
b"cherry-pick",
b"clean",
b"clone",
b"column",
b"commit",
b"commit-graph",
b"commit-tree",
b"config",
b"count-objects",
b"credential",
b"credential-cache",
b"credential-cache--daemon",
b"credential-store",
b"describe",
b"diagnose",
b"diff",
b"diff-files",
b"diff-index",
b"diff-pairs",
b"diff-tree",
b"difftool",
b"fast-export",
b"fast-import",
b"fetch",
b"fetch-pack",
b"fmt-merge-msg",
b"for-each-ref",
b"for-each-repo",
b"format-patch",
b"format-rev",
b"fsck",
b"fsck-objects",
b"fsmonitor--daemon",
b"gc",
b"get-tar-commit-id",
b"grep",
b"hash-object",
b"help",
b"history",
b"hook",
b"index-pack",
b"init",
b"init-db",
b"interpret-trailers",
b"last-modified",
b"log",
b"ls-files",
b"ls-remote",
b"ls-tree",
b"mailinfo",
b"mailsplit",
b"maintenance",
b"merge",
b"merge-base",
b"merge-file",
b"merge-index",
b"merge-ours",
b"merge-recursive",
b"merge-recursive-ours",
b"merge-recursive-theirs",
b"merge-subtree",
b"merge-tree",
b"mktag",
b"mktree",
b"multi-pack-index",
b"mv",
b"name-rev",
b"notes",
b"pack-objects",
b"pack-redundant",
b"pack-refs",
b"patch-id",
b"pickaxe",
b"prune",
b"prune-packed",
b"pull",
b"push",
b"range-diff",
b"read-tree",
b"rebase",
b"receive-pack",
b"reflog",
b"refs",
b"remote",
b"remote-ext",
b"remote-fd",
b"repack",
b"replace",
b"replay",
b"repo",
b"rerere",
b"reset",
b"restore",
b"rev-list",
b"rev-parse",
b"revert",
b"rm",
b"send-pack",
b"shortlog",
b"show",
b"show-branch",
b"show-index",
b"show-ref",
b"sparse-checkout",
b"stage",
b"stash",
b"status",
b"stripspace",
b"submodule--helper",
b"switch",
b"symbolic-ref",
b"tag",
b"unpack-file",
b"unpack-objects",
b"update-index",
b"update-ref",
b"update-server-info",
b"upload-archive",
b"upload-archive--writer",
b"upload-pack",
b"url-parse",
b"var",
b"verify-commit",
b"verify-pack",
b"verify-tag",
b"version",
b"whatchanged",
b"worktree",
b"write-tree",
];
/// What:
/// Whether `word` is a command built into Git 2.56.0.
/// `&[u8]` borrows the word's
/// raw bytes;
/// `bool` is true or false.
/// Why:
/// A built-in word cannot be an alias,
/// so what the word says is what Git runs.
///
/// In TS you'd write (pseudocode):
/// ```ts
/// function isGitBuiltin(word: string): boolean { return GIT_BUILTIN_COMMANDS.has(word); }
/// ```
pub fn is_git_builtin(word: &[u8]) -> bool {
// `.contains(&word)` borrows the word for the lookup.
return GIT_BUILTIN_COMMANDS.contains(&word);
}
/// The comparison with real Git stays out of the release executable.
#[cfg(test)]
#[path = "git_builtins_tests.rs"]
mod tests;