git-commit: log parameter updates.
[git/dkf.git] / git-commit-script
blob24ec446a9d7ed8ad08d25aa6c921eba4c80f0bfe
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup-script || die "Not a git archive"
8 usage () {
9 die 'git commit [-a] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
12 all= logfile= use_commit= no_edit= log_given= log_message=
13 while case "$#" in 0) break;; esac
15 case "$1" in
16 -a|--a|--al|--all)
17 all=t
18 shift ;;
19 -F=*|--f=*|--fi=*|--fil=*|--file=*)
20 log_given=t$log_given
21 logfile=`expr "$1" : '-[^=]*=\(.*\)'`
22 no_edit=t
23 shift ;;
24 -F|--f|--fi|--fil|--file)
25 case "$#" in 1) usage ;; esac; shift
26 log_given=t$log_given
27 logfile="$1"
28 no_edit=t
29 shift ;;
30 -m=*|--m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*)
31 log_given=t$log_given
32 log_message=`expr "$1" : '-[^=]*=\(.*\)'`
33 no_edit=t
34 shift ;;
35 -m|--m|--me|--mes|--mess|--messa|--messag|--message)
36 case "$#" in 1) usage ;; esac; shift
37 log_given=t$log_given
38 log_message="$1"
39 no_edit=t
40 shift ;;
41 -c=*|--ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\
42 --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\
43 --reedit-messag=*|--reedit-message=*)
44 log_given=t$log_given
45 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
46 shift ;;
47 -c|--ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\
48 --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message)
49 case "$#" in 1) usage ;; esac; shift
50 log_given=t$log_given
51 use_commit="$1"
52 shift ;;
53 -C=*|--reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\
54 --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\
55 --reuse-message=*)
56 log_given=t$log_given
57 use_commit=`expr "$1" : '-[^=]*=\(.*\)'`
58 no_edit=t
59 shift ;;
60 -C|--reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\
61 --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message)
62 case "$#" in 1) usage ;; esac; shift
63 log_given=t$log_given
64 use_commit="$1"
65 no_edit=t
66 shift ;;
67 --)
68 shift
69 break ;;
70 -*)
71 usage ;;
73 break ;;
74 esac
75 done
77 case "$log_given" in
78 tt*)
79 die "Only one of -c/-C/-F/-m can be used." ;;
80 esac
82 case "$all" in
84 git-diff-files --name-only -z |
85 xargs -0 git-update-cache -q -- || exit 1 ;;
86 esac
87 git-update-cache -q --refresh -- "$@" || exit 1
89 PARENTS="-p HEAD"
90 if [ ! -r "$GIT_DIR/HEAD" ]; then
91 if [ -z "$(git-ls-files)" ]; then
92 echo Nothing to commit 1>&2
93 exit 1
96 echo "#"
97 echo "# Initial commit"
98 case "$no_edit" in
99 t) echo "# (ignoring your commit message for initial commit)"
100 no_edit=
101 esac
102 echo "#"
103 git-ls-files | sed 's/^/# New file: /'
104 echo "#"
105 } >.editmsg
106 PARENTS=""
107 no_edit=
108 else
109 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
110 echo "#"
111 echo "# It looks like your may be committing a MERGE."
112 echo "# If this is not correct, please remove the file"
113 echo "# $GIT_DIR/MERGE_HEAD"
114 echo "# and try again"
115 case "$no_edit" in
116 t) echo "# (ignoring your commit message for merge commit)"
117 no_edit=
118 esac
119 echo "#"
120 PARENTS="-p HEAD -p MERGE_HEAD"
121 elif test "$log_message" != ''
122 then
123 echo "$log_message"
124 elif test "$logfile" != ""
125 then
126 if test "$logfile" = -
127 then
128 test -t 0 &&
129 echo >&2 "(reading log message from standard input)"
131 else
132 cat <"$logfile"
134 elif test "$use_commit" != ""
135 then
136 pick_author_script='
137 /^author /{
139 s/^author \([^<]*\) <[^>]*> .*$/\1/
140 s/'\''/'\''\'\'\''/g
141 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
144 s/^author [^<]* <\([^>]*\)> .*$/\1/
145 s/'\''/'\''\'\'\''/g
146 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
149 s/^author [^<]* <[^>]*> \(.*\)$/\1/
150 s/'\''/'\''\'\'\''/g
151 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
156 set_author_env=`git-cat-file commit "$use_commit" |
157 sed -ne "$pick_author_script"`
158 eval "$set_author_env"
159 export GIT_AUTHOR_NAME
160 export GIT_AUTHOR_EMAIL
161 export GIT_AUTHOR_DATE
162 git-cat-file commit "$use_commit" |
163 sed -e '1,/^$/d'
164 fi >.editmsg
165 git-status-script >>.editmsg
167 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
168 then
169 cat .editmsg
170 rm .editmsg
171 exit 1
173 case "$no_edit" in
175 ${VISUAL:-${EDITOR:-vi}} .editmsg
177 esac
178 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
179 if test -s .cmitmsg
180 then
181 tree=$(git-write-tree) &&
182 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
183 echo $commit > "$GIT_DIR/HEAD" &&
184 rm -f -- "$GIT_DIR/MERGE_HEAD"
185 else
186 echo >&2 "* no commit message? aborting commit."
187 false
189 ret="$?"
190 rm -f .cmitmsg .editmsg
191 exit "$ret"