Add support for -p/--patch to git-commit
The --interactive flag is already shared by git add and git commit, share the -p and --patch flags too. Signed-off-by: Conrad Irwin <conrad.irwin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Conrad Irwin committed
May 7, 2011 at 10:58 UTC
b4bd466820ee272fccfefff1d23d64c7826d1d07
4 files changed
+27
-16
Documentation/git-commit.txt
+16
-9
@@ -8,11 +8,12 @@ git-commit - Record changes to the repository
8
SYNOPSIS
9
--------
10
[verse]
11
-'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12
- [(-c | -C | --fixup | --squash) <commit>] [-F <file> | -m <msg>]
13
- [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]
14
- [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]
15
- [--status | --no-status] [-i | -o] [--] [<file>...]
11
+'git commit' [-a | --interactive | --patch] [-s] [-v] [-u<mode>] [--amend]
12
+ [--dry-run] [(-c | -C | --fixup | --squash) <commit>]
13
+ [-F <file> | -m <msg>] [--reset-author] [--allow-empty]
14
+ [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
15
+ [--date=<date>] [--cleanup=<mode>] [--status | --no-status]
16
+ [-i | -o] [--] [<file>...]
17
18
DESCRIPTION
19
-----------
@@ -39,10 +40,10 @@ The content to be added can be specified in several ways:
40
that have been removed from the working tree, and then perform the
41
actual commit;
42
42
-5. by using the --interactive switch with the 'commit' command to decide one
43
- by one which files should be part of the commit, before finalizing the
44
- operation. Currently, this is done by invoking 'git add --interactive'
45
- on a temporary index.
43
+5. by using the --interactive or --patch switches with the 'commit' command
44
+ to decide one by one which files or hunks should be part of the commit,
45
+ before finalizing the operation. See the ``Interactive Mode`` section of
46
+ linkgit:git-add[1] to learn how to operate these modes.
47
48
The `--dry-run` option can be used to obtain a
49
summary of what is included by any of the above for the next
@@ -60,6 +61,12 @@ OPTIONS
61
been modified and deleted, but new files you have not
62
told git about are not affected.
63
64
+-p::
65
+--patch::
66
+ Use the interactive patch selection interface to chose
67
+ which changes to commit. See linkgit:git-add[1] for
68
+ details.
69
+
70
-C <commit>::
71
--reuse-message=<commit>::
72
Take an existing commit object, and reuse the log message
builtin/add.c
+3
-3
@@ -241,7 +241,7 @@ int run_add_interactive(const char *revision, const char *patch_mode,
241
return status;
242
}
243
244
-int interactive_add(int argc, const char **argv, const char *prefix)
244
+int interactive_add(int argc, const char **argv, const char *prefix, int patch)
245
{
246
const char **pathspec = NULL;
247
@@ -252,7 +252,7 @@ int interactive_add(int argc, const char **argv, const char *prefix)
252
}
253
254
return run_add_interactive(NULL,
255
- patch_interactive ? "--patch" : NULL,
255
+ patch ? "--patch" : NULL,
256
pathspec);
257
}
258
@@ -377,7 +377,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
377
if (patch_interactive)
378
add_interactive = 1;
379
if (add_interactive)
380
- exit(interactive_add(argc - 1, argv + 1, prefix));
380
+ exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
381
382
if (edit_interactive)
383
return(edit_patch(argc, argv, prefix));
builtin/commit.c
+7
-3
@@ -83,7 +83,7 @@ static const char *template_file;
83
static const char *author_message, *author_message_buffer;
84
static char *edit_message, *use_message;
85
static char *fixup_message, *squash_message;
86
-static int all, edit_flag, also, interactive, only, amend, signoff;
86
+static int all, edit_flag, also, interactive, patch_interactive, only, amend, signoff;
87
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
88
static int no_post_rewrite, allow_empty_message;
89
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
@@ -152,6 +152,7 @@ static struct option builtin_commit_options[] = {
152
OPT_BOOLEAN('a', "all", &all, "commit all changed files"),
153
OPT_BOOLEAN('i', "include", &also, "add specified files to index for commit"),
154
OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
155
+ OPT_BOOLEAN('p', "patch", &patch_interactive, "interactively add changes"),
156
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
157
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
158
OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
@@ -360,7 +361,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix, int
361
old_index_env = getenv(INDEX_ENVIRONMENT);
362
setenv(INDEX_ENVIRONMENT, index_lock.filename, 1);
363
363
- if (interactive_add(argc, argv, prefix) != 0)
364
+ if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
365
die(_("interactive add failed"));
366
367
if (old_index_env && *old_index_env)
@@ -1061,8 +1062,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
1062
author_message_buffer = read_commit_message(author_message);
1063
}
1064
1065
+ if (patch_interactive)
1066
+ interactive = 1;
1067
+
1068
if (!!also + !!only + !!all + !!interactive > 1)
1065
- die(_("Only one of --include/--only/--all/--interactive can be used."));
1069
+ die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
1070
if (argc == 0 && (also || (only && !amend)))
1071
die(_("No paths with --include/--only does not make sense."));
1072
if (argc == 0 && only && amend)
commit.h
+1
-1
@@ -159,7 +159,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
159
int is_descendant_of(struct commit *, struct commit_list *);
160
int in_merge_bases(struct commit *, struct commit **, int);
161
162
-extern int interactive_add(int argc, const char **argv, const char *prefix);
162
+extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
163
extern int run_add_interactive(const char *revision, const char *patch_mode,
164
const char **pathspec);
165