@@ -612,7 +612,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
612612 /* This checks and barfs if author is badly specified */
613613 determine_author_info (author_ident );
614614
615- if (!no_verify && run_hook ( index_file , "pre-commit" , NULL ))
615+ if (!no_verify && run_commit_hook ( use_editor , index_file , "pre-commit" , NULL ))
616616 return 0 ;
617617
618618 if (squash_message ) {
@@ -866,8 +866,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
866866 return 0 ;
867867 }
868868
869- if (run_hook ( index_file , "prepare-commit-msg" ,
870- git_path (commit_editmsg ), hook_arg1 , hook_arg2 , NULL ))
869+ if (run_commit_hook ( use_editor , index_file , "prepare-commit-msg" ,
870+ git_path (commit_editmsg ), hook_arg1 , hook_arg2 , NULL ))
871871 return 0 ;
872872
873873 if (use_editor ) {
@@ -883,7 +883,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
883883 }
884884
885885 if (!no_verify &&
886- run_hook ( index_file , "commit-msg" , git_path (commit_editmsg ), NULL )) {
886+ run_commit_hook ( use_editor , index_file , "commit-msg" , git_path (commit_editmsg ), NULL )) {
887887 return 0 ;
888888 }
889889
@@ -1067,8 +1067,6 @@ static int parse_and_validate_options(int argc, const char *argv[],
10671067 use_editor = 0 ;
10681068 if (0 <= edit_flag )
10691069 use_editor = edit_flag ;
1070- if (!use_editor )
1071- setenv ("GIT_EDITOR" , ":" , 1 );
10721070
10731071 /* Sanity check options */
10741072 if (amend && !current_head )
@@ -1445,6 +1443,29 @@ static int run_rewrite_hook(const unsigned char *oldsha1,
14451443 return finish_command (& proc );
14461444}
14471445
1446+ int run_commit_hook (int editor_is_used , const char * index_file , const char * name , ...)
1447+ {
1448+ const char * hook_env [3 ] = { NULL };
1449+ char index [PATH_MAX ];
1450+ va_list args ;
1451+ int ret ;
1452+
1453+ snprintf (index , sizeof (index ), "GIT_INDEX_FILE=%s" , index_file );
1454+ hook_env [0 ] = index ;
1455+
1456+ /*
1457+ * Let the hook know that no editor will be launched.
1458+ */
1459+ if (!editor_is_used )
1460+ hook_env [1 ] = "GIT_EDITOR=:" ;
1461+
1462+ va_start (args , name );
1463+ ret = run_hook_ve (hook_env , name , args );
1464+ va_end (args );
1465+
1466+ return ret ;
1467+ }
1468+
14481469int cmd_commit (int argc , const char * * argv , const char * prefix )
14491470{
14501471 static struct wt_status s ;
@@ -1669,7 +1690,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
16691690 "not exceeded, and then \"git reset HEAD\" to recover." ));
16701691
16711692 rerere (0 );
1672- run_hook ( get_index_file (), "post-commit" , NULL );
1693+ run_commit_hook ( use_editor , get_index_file (), "post-commit" , NULL );
16731694 if (amend && !no_post_rewrite ) {
16741695 struct notes_rewrite_cfg * cfg ;
16751696 cfg = init_copy_notes_for_rewrite ("amend" );
0 commit comments