1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum HookCategory {
3 Commit,
4 Merge,
5 Rebase,
6 Push,
7 Receive,
8 Email,
9 Misc,
10}
11
12impl HookCategory {
13 pub fn label(self) -> &'static str {
14 match self {
15 Self::Commit => "Commit",
16 Self::Merge => "Merge",
17 Self::Rebase => "Rebase",
18 Self::Push => "Push",
19 Self::Receive => "Receive (server-side)",
20 Self::Email => "Email / Patch",
21 Self::Misc => "Misc",
22 }
23 }
24}
25
26pub struct HookInfo {
27 pub name: &'static str,
28 pub description: &'static str,
29 pub category: HookCategory,
30}
31
32pub const ALL_HOOKS: &[HookInfo] = &[
33 HookInfo {
35 name: "pre-commit",
36 description: "Runs before commit message editor; abort with non-zero exit.",
37 category: HookCategory::Commit,
38 },
39 HookInfo {
40 name: "prepare-commit-msg",
41 description: "Runs after default message is prepared, before editor starts.",
42 category: HookCategory::Commit,
43 },
44 HookInfo {
45 name: "commit-msg",
46 description: "Validates/normalises the commit message. Receives message file path as $1.",
47 category: HookCategory::Commit,
48 },
49 HookInfo {
50 name: "post-commit",
51 description: "Notification hook after a commit is made. Cannot affect outcome.",
52 category: HookCategory::Commit,
53 },
54 HookInfo {
56 name: "pre-merge-commit",
57 description: "Runs after merge completes, before merge commit is created.",
58 category: HookCategory::Merge,
59 },
60 HookInfo {
61 name: "post-merge",
62 description: "Notification hook after git-merge / git-pull. Cannot affect outcome.",
63 category: HookCategory::Merge,
64 },
65 HookInfo {
67 name: "pre-rebase",
68 description: "Runs before git-rebase; abort with non-zero exit.",
69 category: HookCategory::Rebase,
70 },
71 HookInfo {
72 name: "post-rewrite",
73 description: "Runs after commits are rewritten (amend, rebase).",
74 category: HookCategory::Rebase,
75 },
76 HookInfo {
78 name: "pre-push",
79 description: "Runs before git-push; abort with non-zero exit.",
80 category: HookCategory::Push,
81 },
82 HookInfo {
83 name: "push-to-checkout",
84 description: "Overrides default behaviour when pushing to a checked-out branch.",
85 category: HookCategory::Push,
86 },
87 HookInfo {
89 name: "pre-receive",
90 description: "Server-side: runs once before updating refs. Abort with non-zero exit.",
91 category: HookCategory::Receive,
92 },
93 HookInfo {
94 name: "update",
95 description: "Server-side: runs once per ref being updated.",
96 category: HookCategory::Receive,
97 },
98 HookInfo {
99 name: "proc-receive",
100 description: "Server-side: handles commands matched by receive.procReceiveRefs.",
101 category: HookCategory::Receive,
102 },
103 HookInfo {
104 name: "post-receive",
105 description: "Server-side: notification after all refs are updated.",
106 category: HookCategory::Receive,
107 },
108 HookInfo {
109 name: "post-update",
110 description: "Server-side: notification after all refs are updated (receives ref names).",
111 category: HookCategory::Receive,
112 },
113 HookInfo {
115 name: "applypatch-msg",
116 description: "Validates/normalises commit message from applied patch.",
117 category: HookCategory::Email,
118 },
119 HookInfo {
120 name: "pre-applypatch",
121 description: "Runs after patch is applied but before committing.",
122 category: HookCategory::Email,
123 },
124 HookInfo {
125 name: "post-applypatch",
126 description: "Notification after patch is applied and committed.",
127 category: HookCategory::Email,
128 },
129 HookInfo {
130 name: "sendemail-validate",
131 description: "Validates patch emails before git-send-email sends them.",
132 category: HookCategory::Email,
133 },
134 HookInfo {
136 name: "post-checkout",
137 description: "Runs after git-checkout or git-switch; receives old HEAD, new HEAD, branch flag.",
138 category: HookCategory::Misc,
139 },
140 HookInfo {
141 name: "reference-transaction",
142 description: "Runs on every reference transaction (prepared/committed/aborted).",
143 category: HookCategory::Misc,
144 },
145 HookInfo {
146 name: "pre-auto-gc",
147 description: "Runs before git gc --auto; abort with non-zero exit.",
148 category: HookCategory::Misc,
149 },
150 HookInfo {
151 name: "fsmonitor-watchman",
152 description: "Used with core.fsmonitor for filesystem change monitoring.",
153 category: HookCategory::Misc,
154 },
155 HookInfo {
156 name: "post-index-change",
157 description: "Runs after the index is written.",
158 category: HookCategory::Misc,
159 },
160 HookInfo {
162 name: "p4-changelist",
163 description: "git-p4 submit: validates/normalises changelist message.",
164 category: HookCategory::Misc,
165 },
166 HookInfo {
167 name: "p4-prepare-changelist",
168 description: "git-p4 submit: runs before changelist editor starts.",
169 category: HookCategory::Misc,
170 },
171 HookInfo {
172 name: "p4-post-changelist",
173 description: "git-p4 submit: notification after successful submit.",
174 category: HookCategory::Misc,
175 },
176 HookInfo {
177 name: "p4-pre-submit",
178 description: "git-p4 submit: runs before submission; abort with non-zero exit.",
179 category: HookCategory::Misc,
180 },
181];
182
183pub fn find_hook(name: &str) -> Option<&'static HookInfo> {
184 ALL_HOOKS.iter().find(|h| h.name == name)
185}