@@ -144,6 +144,26 @@ impl Hooks {
144
144
}
145
145
}
146
146
147
+ /// Run `reference-transaction` hook to signal that all reference updates have been queued to the transaction.
148
+ ///
149
+ /// **changed_refs (old, new, name):**
150
+ /// - `name` is the full name of the ref
151
+ /// - `old` is zeroed out when force updating the reference regardless of its current value or
152
+ /// when the reference is to be created anew
153
+ pub fn run_reference_transaction < ' t > (
154
+ & ' t self ,
155
+ repo : & ' t git2:: Repository ,
156
+ changed_refs : & ' t [ ( git2:: Oid , git2:: Oid , & ' t str ) ] ,
157
+ ) -> Result < ReferenceTransaction < ' _ > , std:: io:: Error > {
158
+ self . run_reference_transaction_prepare ( repo, changed_refs) ?;
159
+
160
+ Ok ( ReferenceTransaction {
161
+ hook : self ,
162
+ repo,
163
+ changed_refs,
164
+ } )
165
+ }
166
+
147
167
/// Run `reference-transaction` hook to signal that all reference updates have been queued to the transaction.
148
168
///
149
169
/// **changed_refs (old, new, name):**
@@ -245,6 +265,39 @@ impl Hooks {
245
265
}
246
266
}
247
267
268
+ pub struct ReferenceTransaction < ' t > {
269
+ hook : & ' t Hooks ,
270
+ repo : & ' t git2:: Repository ,
271
+ changed_refs : & ' t [ ( git2:: Oid , git2:: Oid , & ' t str ) ] ,
272
+ }
273
+
274
+ impl < ' t > ReferenceTransaction < ' t > {
275
+ pub fn committed ( self ) {
276
+ let Self {
277
+ hook,
278
+ repo,
279
+ changed_refs,
280
+ } = self ;
281
+ hook. run_reference_transaction_committed ( repo, changed_refs) ;
282
+ }
283
+
284
+ pub fn aborted ( self ) {
285
+ let Self {
286
+ hook,
287
+ repo,
288
+ changed_refs,
289
+ } = self ;
290
+ hook. run_reference_transaction_aborted ( repo, changed_refs) ;
291
+ }
292
+ }
293
+
294
+ impl < ' t > Drop for ReferenceTransaction < ' t > {
295
+ fn drop ( & mut self ) {
296
+ self . hook
297
+ . run_reference_transaction_aborted ( self . repo , self . changed_refs ) ;
298
+ }
299
+ }
300
+
248
301
const PUSH_HOOKS : & [ & str ] = & [
249
302
"pre-receive" ,
250
303
"update" ,
0 commit comments