Skip to content

Commit 6cbf07e

Browse files
Paolo BonziniJunio C Hamano
authored andcommitted
git-commit: add a --interactive option
The --interactive option behaves like "git commit", except that "git add --interactive" is executed before committing. It is incompatible with -a and -i. Signed-off-by: Paolo Bonzini <bonzini@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent bd1fc62 commit 6cbf07e

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

Documentation/git-commit.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ git-commit - Record changes to the repository
88
SYNOPSIS
99
--------
1010
[verse]
11-
'git-commit' [-a] [-s] [-v] [(-c | -C) <commit> | -F <file> | -m <msg> |
12-
--amend] [--no-verify] [-e] [--author <author>]
11+
'git-commit' [-a | --interactive] [-s] [-v]
12+
[(-c | -C) <commit> | -F <file> | -m <msg> | --amend]
13+
[--no-verify] [-e] [--author <author>]
1314
[--] [[-i | -o ]<file>...]
1415

1516
DESCRIPTION
@@ -35,6 +36,10 @@ methods:
3536
before, and to automatically "rm" files that have been
3637
removed from the working tree, and perform the actual commit.
3738

39+
5. by using the --interactive switch with the 'commit' command to decide one
40+
by one which files should be part of the commit, before finalizing the
41+
operation. Currently, this is done by invoking `git-add --interactive`.
42+
3843
The gitlink:git-status[1] command can be used to obtain a
3944
summary of what is included by any of the above for the next
4045
commit by giving the same set of parameters you would give to

git-commit.sh

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright (c) 2005 Linus Torvalds
44
# Copyright (c) 2006 Junio C Hamano
55

6-
USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
6+
USAGE='[-a | --interactive] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit> | --amend] [-u] [-e] [--author <author>] [[-i | -o] <path>...]'
77
SUBDIRECTORY_OK=Yes
88
. git-sh-setup
99
require_work_tree
@@ -71,6 +71,7 @@ trap '
7171

7272
all=
7373
also=
74+
interactive=
7475
only=
7576
logfile=
7677
use_commit=
@@ -131,6 +132,11 @@ do
131132
also=t
132133
shift
133134
;;
135+
--int|--inte|--inter|--intera|--interac|--interact|--interacti|\
136+
--interactiv|--interactive)
137+
interactive=t
138+
shift
139+
;;
134140
-o|--o|--on|--onl|--only)
135141
only=t
136142
shift
@@ -304,12 +310,14 @@ case "$#,$also,$only,$amend" in
304310
;;
305311
esac
306312
unset only
307-
case "$all,$also,$#" in
308-
t,t,*)
309-
die "Cannot use -a and -i at the same time." ;;
313+
case "$all,$interactive,$also,$#" in
314+
*t,*t,*)
315+
die "Cannot use -a, --interactive or -i at the same time." ;;
310316
t,,[1-9]*)
311317
die "Paths with -a does not make sense." ;;
312-
,t,0)
318+
,t,[1-9]*)
319+
die "Paths with --interactive does not make sense." ;;
320+
,,t,0)
313321
die "No paths with -i does not make sense." ;;
314322
esac
315323

@@ -344,6 +352,9 @@ t,)
344352
) || exit
345353
;;
346354
,)
355+
if test "$interactive" = t; then
356+
git add --interactive || exit
357+
fi
347358
case "$#" in
348359
0)
349360
;; # commit as-is

0 commit comments

Comments
 (0)