commit: --dry-run
This teaches --dry-run option to "git commit". It is the same as "git status", but in the longer term we would want to change the semantics of "git status" not to be the preview of commit, and this is the first step for doing so. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 7, 2009 at 23:03 UTC
3a5d13a3c32e0f39d8fc83330255fac27af5d853
2 files changed
+22
-14
Documentation/git-commit.txt
+6
-1
@@ -8,7 +8,7 @@ git-commit - Record changes to the repository
8
SYNOPSIS
9
--------
10
[verse]
11
-'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend]
11
+'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12
[(-c | -C) <commit>] [-F <file> | -m <msg>]
13
[--allow-empty] [--no-verify] [-e] [--author=<author>]
14
[--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -198,6 +198,11 @@ specified.
198
--quiet::
199
Suppress commit summary message.
200
201
+--dry-run::
202
+ Do not create a commit, but show a list of paths that are
203
+ to be committed, paths with local changes that will be left
204
+ uncommitted and paths that are untracked.
205
+
206
\--::
207
Do not interpret any more arguments as options.
208
builtin-commit.c
+16
-13
@@ -51,7 +51,7 @@ static const char *template_file;
51
static char *edit_message, *use_message;
52
static char *author_name, *author_email, *author_date;
53
static 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;
55
static char *untracked_files_arg;
56
/*
57
* The default commit message cleanup mode will remove the lines
@@ -103,6 +103,7 @@ static struct option builtin_commit_options[] = {
103
OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
104
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
105
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
106
+ OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
107
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
108
{ 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" },
109
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[],
814
return argc;
815
}
816
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)
818
{
818
- const char *index_file;
819
int commitable;
820
+ const char *index_file;
821
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();
825
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);
832
if (wt_status_use_color == -1)
833
wt_status_use_color = git_use_color_default;
825
-
834
if (diff_use_color_default == -1)
835
diff_use_color_default = git_use_color_default;
836
837
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);
839
}
840
841
static 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)
910
wt_status_use_color = git_use_color_default;
911
912
argc = parse_and_validate_options(argc, argv, builtin_commit_usage, prefix);
913
+ if (dry_run)
914
+ return dry_run_commit(argc, argv, prefix);
915
916
index_file = prepare_index(argc, argv, prefix, 0);
917