@@ -241,6 +241,113 @@ int git_hook_execute_io(git_buf *io, git_repository *repo, const char *hook_name
241
241
242
242
/** High-level hook calls */
243
243
244
+ int git_hook_call_pre_commit (git_repository * repo )
245
+ {
246
+ assert (repo );
247
+
248
+ return git_hook_execute (repo , "pre-commit" );
249
+ }
250
+
251
+ static int commit_message_file (git_buf * msg_path , git_repository * repo , const char * message , const char * file )
252
+ {
253
+ int err = 0 ;
254
+ git_buf msg_buf = GIT_BUF_INIT ;
255
+
256
+ assert (msg_path && repo && message && file );
257
+
258
+ git_buf_attach_notowned (& msg_buf , message , strlen (message ));
259
+
260
+ if ((err = git_repository_item_path (msg_path , repo , GIT_REPOSITORY_ITEM_GITDIR )) != 0 )
261
+ goto cleanup ;
262
+
263
+ if ((err = git_buf_joinpath (msg_path , git_buf_cstr (msg_path ), file )) != 0 )
264
+ goto cleanup ;
265
+
266
+ if ((err = git_futils_writebuffer (& msg_buf , git_buf_cstr (msg_path ), O_CREAT |O_WRONLY , 0766 )) != 0 )
267
+ goto cleanup ;
268
+
269
+ cleanup :
270
+ git_buf_free (& msg_buf );
271
+ if (err != 0 ) {
272
+ git_buf_free (msg_path );
273
+ }
274
+
275
+ return err ;
276
+ }
277
+
278
+ int git_hook_call_prepare_commit_message (git_repository * repo , const char * message )
279
+ {
280
+ int err = 0 ;
281
+ git_buf msg_path = GIT_BUF_INIT ;
282
+
283
+ assert (repo && message );
284
+
285
+ if ((err = commit_message_file (& msg_path , repo , message , "COMMIT_MSG" )) != 0 )
286
+ goto cleanup ;
287
+
288
+ err = git_hook_execute (repo , "prepare-commit-msg" , git_buf_cstr (& msg_path ), "message" , NULL );
289
+
290
+ p_unlink (git_buf_cstr (& msg_path ));
291
+
292
+ cleanup :
293
+ git_buf_free (& msg_path );
294
+ return err ;
295
+ }
296
+
297
+ int git_hook_call_prepare_commit_template (git_repository * repo , const char * template_file )
298
+ {
299
+ int err = 0 ;
300
+ git_buf msg_path = GIT_BUF_INIT ;
301
+ git_buf tpl_path = GIT_BUF_INIT ;
302
+ git_buf tpl_msg = GIT_BUF_INIT ;
303
+ git_config * conf ;
304
+
305
+ assert (repo );
306
+
307
+ if (template_file == NULL ) {
308
+ git_repository_config__weakptr (& conf , repo );
309
+ git_config_get_path (& tpl_path , conf , "commit.template" );
310
+ } else {
311
+ git_buf_puts (& tpl_path , template_file );
312
+ }
313
+
314
+ git_futils_readbuffer (& tpl_msg , git_buf_cstr (& tpl_path ));
315
+ git_buf_free (& tpl_path );
316
+
317
+ commit_message_file (& msg_path , repo , git_buf_cstr (& tpl_msg ), "COMMIT_MSG" );
318
+
319
+ err = git_hook_execute (repo , "prepare-commit-msg" , git_buf_cstr (& msg_path ), "template" , NULL );
320
+
321
+ p_unlink (git_buf_cstr (& msg_path ));
322
+
323
+ return err ;
324
+ }
325
+
326
+ int git_hook_call_commit_msg (git_repository * repo , const char * message )
327
+ {
328
+ int err = 0 ;
329
+ git_buf msg_path = GIT_BUF_INIT ;
330
+
331
+ assert (repo && message );
332
+
333
+ if ((err = commit_message_file (& msg_path , repo , message , "COMMIT_MSG" )) != 0 )
334
+ goto cleanup ;
335
+
336
+ err = git_hook_execute (repo , "commit-msg" , git_buf_cstr (& msg_path ), NULL );
337
+
338
+ p_unlink (git_buf_cstr (& msg_path ));
339
+
340
+ cleanup :
341
+ return err ;
342
+ }
343
+
344
+ int git_hook_call_post_commit (git_repository * repo )
345
+ {
346
+ assert (repo );
347
+
348
+ return git_hook_execute (repo , "post-commit" , NULL );
349
+ }
350
+
244
351
int git_hook_call_pre_rebase (git_repository * repo , const git_annotated_commit * upstream , const git_annotated_commit * rebased )
245
352
{
246
353
int err = 0 ;
0 commit comments