[PATCH] HTTP partial transfer support fix.
[git/debian.git] / git-commit.sh
blob18b259c7086224f70cfd69798dc6332df040a61d
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup || die "Not a git archive"
8 usage () {
9 die 'git commit [-a] [-v | --no-verify] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
12 all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
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 -e|--e|--ed|--edi|--edit)
68 no_edit=
69 shift ;;
70 -s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
71 signoff=t
72 shift ;;
73 -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
74 verify=
75 shift ;;
76 -v|--v|--ve|--ver|--veri|--verif|--verify)
77 verify=t
78 shift ;;
79 --)
80 shift
81 break ;;
82 -*)
83 usage ;;
85 break ;;
86 esac
87 done
89 case "$log_given" in
90 tt*)
91 die "Only one of -c/-C/-F/-m can be used." ;;
92 esac
94 case "$all,$#" in
95 t,*)
96 git-diff-files --name-only -z |
97 git-update-index --remove -z --stdin
99 ,0)
102 git-diff-files --name-only -z "$@" |
103 git-update-index --remove -z --stdin
105 esac || exit 1
106 git-update-index -q --refresh || exit 1
108 case "$verify" in
110 if test -x "$GIT_DIR"/hooks/pre-commit
111 then
112 "$GIT_DIR"/hooks/pre-commit || exit
114 esac
116 if test "$log_message" != ''
117 then
118 echo "$log_message"
119 elif test "$logfile" != ""
120 then
121 if test "$logfile" = -
122 then
123 test -t 0 &&
124 echo >&2 "(reading log message from standard input)"
126 else
127 cat <"$logfile"
129 elif test "$use_commit" != ""
130 then
131 git-cat-file commit "$use_commit" | sed -e '1,/^$/d'
132 fi | git-stripspace >.editmsg
134 case "$signoff" in
136 git-var GIT_COMMITTER_IDENT | sed -e '
137 s/>.*/>/
138 s/^/Signed-off-by: /
139 ' >>.editmsg
141 esac
143 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
145 test -f "$GIT_DIR/MERGE_MSG" && cat "$GIT_DIR/MERGE_MSG"
147 echo "#"
148 echo "# It looks like your may be committing a MERGE."
149 echo "# If this is not correct, please remove the file"
150 echo "# $GIT_DIR/MERGE_HEAD"
151 echo "# and try again"
152 echo "#"
153 fi >>.editmsg
155 PARENTS="-p HEAD"
156 if [ ! -r "$GIT_DIR/HEAD" ]; then
157 if [ -z "$(git-ls-files)" ]; then
158 echo Nothing to commit 1>&2
159 exit 1
161 PARENTS=""
162 current=
163 else
164 current=$(git-rev-parse --verify HEAD)
165 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
166 PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"`
168 if test "$use_commit" != ""
169 then
170 pick_author_script='
171 /^author /{
173 s/^author \([^<]*\) <[^>]*> .*$/\1/
174 s/'\''/'\''\'\'\''/g
175 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
178 s/^author [^<]* <\([^>]*\)> .*$/\1/
179 s/'\''/'\''\'\'\''/g
180 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
183 s/^author [^<]* <[^>]*> \(.*\)$/\1/
184 s/'\''/'\''\'\'\''/g
185 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
190 set_author_env=`git-cat-file commit "$use_commit" |
191 sed -ne "$pick_author_script"`
192 eval "$set_author_env"
193 export GIT_AUTHOR_NAME
194 export GIT_AUTHOR_EMAIL
195 export GIT_AUTHOR_DATE
198 git-status >>.editmsg
199 if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ]
200 then
201 rm -f .editmsg
202 git-status
203 exit 1
205 case "$no_edit" in
207 ${VISUAL:-${EDITOR:-vi}} .editmsg
209 esac
211 case "$verify" in
213 if test -x "$GIT_DIR"/hooks/commit-msg
214 then
215 "$GIT_DIR"/hooks/commit-msg .editmsg || exit
217 esac
219 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
220 grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk
221 if test -s .cmitchk
222 then
223 tree=$(git-write-tree) &&
224 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
225 git-update-ref HEAD $commit $current &&
226 rm -f -- "$GIT_DIR/MERGE_HEAD"
227 else
228 echo >&2 "* no commit message? aborting commit."
229 false
231 ret="$?"
232 rm -f .cmitmsg .editmsg .cmitchk
234 if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
235 then
236 "$GIT_DIR"/hooks/post-commit
238 exit "$ret"