@@ -51,7 +51,7 @@ static const char *template_file;
5151static char * edit_message , * use_message ;
5252static char * author_name , * author_email , * author_date ;
5353static int all , edit_flag , also , interactive , only , amend , signoff ;
54- static int quiet , verbose , no_verify , allow_empty ;
54+ static int quiet , verbose , no_verify , allow_empty , dry_run ;
5555static char * untracked_files_arg ;
5656/*
5757 * The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {
103103 OPT_BOOLEAN (0 , "interactive" , & interactive , "interactively add files" ),
104104 OPT_BOOLEAN ('o' , "only" , & only , "commit only specified files" ),
105105 OPT_BOOLEAN ('n' , "no-verify" , & no_verify , "bypass pre-commit hook" ),
106+ OPT_BOOLEAN (0 , "dry-run" , & dry_run , "show what would be committed" ),
106107 OPT_BOOLEAN (0 , "amend" , & amend , "amend previous commit" ),
107108 { OPTION_STRING , 'u' , "untracked-files" , & untracked_files_arg , "mode" , "show untracked files, optional modes: all, normal, no. (Default: all)" , PARSE_OPT_OPTARG , NULL , (intptr_t )"all" },
108109 OPT_BOOLEAN (0 , "allow-empty" , & allow_empty , "ok to record an empty change" ),
@@ -813,28 +814,28 @@ static int parse_and_validate_options(int argc, const char *argv[],
813814 return argc ;
814815}
815816
816- int cmd_status (int argc , const char * * argv , const char * prefix )
817+ static int dry_run_commit (int argc , const char * * argv , const char * prefix )
817818{
818- const char * index_file ;
819819 int commitable ;
820+ const char * index_file ;
820821
821- git_config (git_status_config , NULL );
822+ index_file = prepare_index (argc , argv , prefix , 1 );
823+ commitable = run_status (stdout , index_file , prefix , 0 );
824+ rollback_index_files ();
822825
826+ return commitable ? 0 : 1 ;
827+ }
828+
829+ int cmd_status (int argc , const char * * argv , const char * prefix )
830+ {
831+ git_config (git_status_config , NULL );
823832 if (wt_status_use_color == -1 )
824833 wt_status_use_color = git_use_color_default ;
825-
826834 if (diff_use_color_default == -1 )
827835 diff_use_color_default = git_use_color_default ;
828836
829837 argc = parse_and_validate_options (argc , argv , builtin_status_usage , prefix );
830-
831- index_file = prepare_index (argc , argv , prefix , 1 );
832-
833- commitable = run_status (stdout , index_file , prefix , 0 );
834-
835- rollback_index_files ();
836-
837- return commitable ? 0 : 1 ;
838+ return dry_run_commit (argc , argv , prefix );
838839}
839840
840841static void print_summary (const char * prefix , const unsigned char * sha1 )
@@ -909,6 +910,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
909910 wt_status_use_color = git_use_color_default ;
910911
911912 argc = parse_and_validate_options (argc , argv , builtin_commit_usage , prefix );
913+ if (dry_run )
914+ return dry_run_commit (argc , argv , prefix );
912915
913916 index_file = prepare_index (argc , argv , prefix , 0 );
914917
0 commit comments