@@ -533,9 +533,20 @@ static int is_a_merge(const struct commit *current_head)
533533
534534static const char sign_off_header [] = "Signed-off-by: " ;
535535
536+ static void export_one (const char * var , const char * s , const char * e , int hack )
537+ {
538+ struct strbuf buf = STRBUF_INIT ;
539+ if (hack )
540+ strbuf_addch (& buf , hack );
541+ strbuf_addf (& buf , "%.*s" , (int )(e - s ), s );
542+ setenv (var , buf .buf , 1 );
543+ strbuf_release (& buf );
544+ }
545+
536546static void determine_author_info (struct strbuf * author_ident )
537547{
538548 char * name , * email , * date ;
549+ struct ident_split author ;
539550
540551 name = getenv ("GIT_AUTHOR_NAME" );
541552 email = getenv ("GIT_AUTHOR_EMAIL" );
@@ -585,6 +596,11 @@ static void determine_author_info(struct strbuf *author_ident)
585596 date = force_date ;
586597 strbuf_addstr (author_ident , fmt_ident (name , email , date ,
587598 IDENT_ERROR_ON_NO_NAME ));
599+ if (!split_ident_line (& author , author_ident -> buf , author_ident -> len )) {
600+ export_one ("GIT_AUTHOR_NAME" , author .name_begin , author .name_end , 0 );
601+ export_one ("GIT_AUTHOR_EMAIL" , author .mail_begin , author .mail_end , 0 );
602+ export_one ("GIT_AUTHOR_DATE" , author .date_begin , author .tz_end , '@' );
603+ }
588604}
589605
590606static int ends_rfc2822_footer (struct strbuf * sb )
@@ -652,6 +668,9 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
652668 int ident_shown = 0 ;
653669 int clean_message_contents = (cleanup_mode != CLEANUP_NONE );
654670
671+ /* This checks and barfs if author is badly specified */
672+ determine_author_info (author_ident );
673+
655674 if (!no_verify && run_hook (index_file , "pre-commit" , NULL ))
656675 return 0 ;
657676
@@ -771,9 +790,6 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
771790
772791 strbuf_release (& sb );
773792
774- /* This checks and barfs if author is badly specified */
775- determine_author_info (author_ident );
776-
777793 /* This checks if committer ident is explicitly given */
778794 strbuf_addstr (& committer_ident , git_committer_info (0 ));
779795 if (use_editor && include_status ) {
@@ -905,27 +921,10 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
905921 return 1 ;
906922}
907923
908- /*
909- * Find out if the message in the strbuf contains only whitespace and
910- * Signed-off-by lines.
911- */
912- static int message_is_empty (struct strbuf * sb )
924+ static int rest_is_empty (struct strbuf * sb , int start )
913925{
914- struct strbuf tmpl = STRBUF_INIT ;
926+ int i , eol ;
915927 const char * nl ;
916- int eol , i , start = 0 ;
917-
918- if (cleanup_mode == CLEANUP_NONE && sb -> len )
919- return 0 ;
920-
921- /* See if the template is just a prefix of the message. */
922- if (template_file && strbuf_read_file (& tmpl , template_file , 0 ) > 0 ) {
923- stripspace (& tmpl , cleanup_mode == CLEANUP_ALL );
924- if (start + tmpl .len <= sb -> len &&
925- memcmp (tmpl .buf , sb -> buf + start , tmpl .len ) == 0 )
926- start += tmpl .len ;
927- }
928- strbuf_release (& tmpl );
929928
930929 /* Check if the rest is just whitespace and Signed-of-by's. */
931930 for (i = start ; i < sb -> len ; i ++ ) {
@@ -948,6 +947,40 @@ static int message_is_empty(struct strbuf *sb)
948947 return 1 ;
949948}
950949
950+ /*
951+ * Find out if the message in the strbuf contains only whitespace and
952+ * Signed-off-by lines.
953+ */
954+ static int message_is_empty (struct strbuf * sb )
955+ {
956+ if (cleanup_mode == CLEANUP_NONE && sb -> len )
957+ return 0 ;
958+ return rest_is_empty (sb , 0 );
959+ }
960+
961+ /*
962+ * See if the user edited the message in the editor or left what
963+ * was in the template intact
964+ */
965+ static int template_untouched (struct strbuf * sb )
966+ {
967+ struct strbuf tmpl = STRBUF_INIT ;
968+ char * start ;
969+
970+ if (cleanup_mode == CLEANUP_NONE && sb -> len )
971+ return 0 ;
972+
973+ if (!template_file || strbuf_read_file (& tmpl , template_file , 0 ) <= 0 )
974+ return 0 ;
975+
976+ stripspace (& tmpl , cleanup_mode == CLEANUP_ALL );
977+ start = (char * )skip_prefix (sb -> buf , tmpl .buf );
978+ if (!start )
979+ start = sb -> buf ;
980+ strbuf_release (& tmpl );
981+ return rest_is_empty (sb , start - sb -> buf );
982+ }
983+
951984static const char * find_author_by_nickname (const char * name )
952985{
953986 struct rev_info revs ;
@@ -1055,6 +1088,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
10551088 die (_ ("Only one of -c/-C/-F/--fixup can be used." ));
10561089 if (message .len && f > 0 )
10571090 die ((_ ("Option -m cannot be combined with -c/-C/-F/--fixup." )));
1091+ if (f || message .len )
1092+ template_file = NULL ;
10581093 if (edit_message )
10591094 use_message = edit_message ;
10601095 if (amend && !use_message && !fixup_message )
@@ -1494,6 +1529,11 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
14941529
14951530 if (cleanup_mode != CLEANUP_NONE )
14961531 stripspace (& sb , cleanup_mode == CLEANUP_ALL );
1532+ if (template_untouched (& sb ) && !allow_empty_message ) {
1533+ rollback_index_files ();
1534+ fprintf (stderr , _ ("Aborting commit; you did not edit the message.\n" ));
1535+ exit (1 );
1536+ }
14971537 if (message_is_empty (& sb ) && !allow_empty_message ) {
14981538 rollback_index_files ();
14991539 fprintf (stderr , _ ("Aborting commit due to empty commit message.\n" ));
0 commit comments