Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2005 Linus Torvalds |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 4 | # Copyright (c) 2006 Junio C Hamano |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 5 | |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 6 | USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]' |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 7 | SUBDIRECTORY_OK=Yes |
Junio C Hamano | ae2b0f1 | 2005-11-24 00:12:11 -0800 | [diff] [blame] | 8 | . git-sh-setup |
Shawn O. Pearce | 7eff28a | 2006-12-30 23:32:38 -0500 | [diff] [blame] | 9 | require_work_tree |
Linus Torvalds | b33e966 | 2005-07-08 10:57:21 -0700 | [diff] [blame] | 10 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 11 | git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 12 | |
| 13 | case "$0" in |
| 14 | *status) |
| 15 | status_only=t |
| 16 | unmerged_ok_if_status=--unmerged ;; |
| 17 | *commit) |
| 18 | status_only= |
| 19 | unmerged_ok_if_status= ;; |
| 20 | esac |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 21 | |
| 22 | refuse_partial () { |
| 23 | echo >&2 "$1" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 24 | echo >&2 "You might have meant to say 'git commit -i paths...', perhaps?" |
| 25 | exit 1 |
| 26 | } |
| 27 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 28 | THIS_INDEX="$GIT_DIR/index" |
| 29 | NEXT_INDEX="$GIT_DIR/next-index$$" |
| 30 | rm -f "$NEXT_INDEX" |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 31 | save_index () { |
Junio C Hamano | cc7d5bc | 2006-06-29 14:48:22 -0700 | [diff] [blame] | 32 | cp -p "$THIS_INDEX" "$NEXT_INDEX" |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 33 | } |
| 34 | |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 35 | run_status () { |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 36 | # If TMP_INDEX is defined, that means we are doing |
| 37 | # "--only" partial commit, and that index file is used |
| 38 | # to build the tree for the commit. Otherwise, if |
| 39 | # NEXT_INDEX exists, that is the index file used to |
| 40 | # make the commit. Otherwise we are using as-is commit |
| 41 | # so the regular index file is what we use to compare. |
| 42 | if test '' != "$TMP_INDEX" |
| 43 | then |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 44 | GIT_INDEX_FILE="$TMP_INDEX" |
| 45 | export GIT_INDEX_FILE |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 46 | elif test -f "$NEXT_INDEX" |
| 47 | then |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 48 | GIT_INDEX_FILE="$NEXT_INDEX" |
| 49 | export GIT_INDEX_FILE |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 50 | fi |
| 51 | |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 52 | case "$status_only" in |
| 53 | t) color= ;; |
| 54 | *) color=--nocolor ;; |
| 55 | esac |
| 56 | git-runstatus ${color} \ |
| 57 | ${verbose:+--verbose} \ |
| 58 | ${amend:+--amend} \ |
Johannes Schindelin | 2074cb0 | 2006-09-12 22:45:12 +0200 | [diff] [blame] | 59 | ${untracked_files:+--untracked} |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 62 | trap ' |
| 63 | test -z "$TMP_INDEX" || { |
| 64 | test -f "$TMP_INDEX" && rm -f "$TMP_INDEX" |
| 65 | } |
| 66 | rm -f "$NEXT_INDEX" |
| 67 | ' 0 |
| 68 | |
| 69 | ################################################################ |
| 70 | # Command line argument parsing and sanity checking |
| 71 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 72 | all= |
| 73 | also= |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 74 | only= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 75 | logfile= |
| 76 | use_commit= |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 77 | amend= |
Jeff King | cda8ab5 | 2006-06-23 09:43:38 -0400 | [diff] [blame] | 78 | edit_flag= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 79 | no_edit= |
| 80 | log_given= |
| 81 | log_message= |
| 82 | verify=t |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 83 | quiet= |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 84 | verbose= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 85 | signoff= |
| 86 | force_author= |
Junio C Hamano | bba319b | 2006-02-14 12:40:20 -0800 | [diff] [blame] | 87 | only_include_assumed= |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 88 | untracked_files= |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 89 | while case "$#" in 0) break;; esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 90 | do |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 91 | case "$1" in |
| 92 | -F|--F|-f|--f|--fi|--fil|--file) |
| 93 | case "$#" in 1) usage ;; esac |
| 94 | shift |
| 95 | no_edit=t |
| 96 | log_given=t$log_given |
| 97 | logfile="$1" |
| 98 | shift |
| 99 | ;; |
| 100 | -F*|-f*) |
| 101 | no_edit=t |
| 102 | log_given=t$log_given |
| 103 | logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` |
| 104 | shift |
| 105 | ;; |
| 106 | --F=*|--f=*|--fi=*|--fil=*|--file=*) |
| 107 | no_edit=t |
| 108 | log_given=t$log_given |
| 109 | logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
| 110 | shift |
| 111 | ;; |
| 112 | -a|--a|--al|--all) |
| 113 | all=t |
| 114 | shift |
| 115 | ;; |
| 116 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) |
| 117 | force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
| 118 | shift |
| 119 | ;; |
| 120 | --au|--aut|--auth|--autho|--author) |
| 121 | case "$#" in 1) usage ;; esac |
| 122 | shift |
| 123 | force_author="$1" |
| 124 | shift |
| 125 | ;; |
| 126 | -e|--e|--ed|--edi|--edit) |
| 127 | edit_flag=t |
| 128 | shift |
| 129 | ;; |
| 130 | -i|--i|--in|--inc|--incl|--inclu|--includ|--include) |
| 131 | also=t |
| 132 | shift |
| 133 | ;; |
| 134 | -o|--o|--on|--onl|--only) |
| 135 | only=t |
| 136 | shift |
| 137 | ;; |
| 138 | -m|--m|--me|--mes|--mess|--messa|--messag|--message) |
| 139 | case "$#" in 1) usage ;; esac |
| 140 | shift |
| 141 | log_given=m$log_given |
| 142 | if test "$log_message" = '' |
| 143 | then |
| 144 | log_message="$1" |
| 145 | else |
| 146 | log_message="$log_message |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 147 | |
| 148 | $1" |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 149 | fi |
| 150 | no_edit=t |
| 151 | shift |
| 152 | ;; |
| 153 | -m*) |
| 154 | log_given=m$log_given |
| 155 | if test "$log_message" = '' |
| 156 | then |
| 157 | log_message=`expr "z$1" : 'z-m\(.*\)'` |
| 158 | else |
| 159 | log_message="$log_message |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 160 | |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 161 | `expr "z$1" : 'z-m\(.*\)'`" |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 162 | fi |
| 163 | no_edit=t |
| 164 | shift |
| 165 | ;; |
| 166 | --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) |
| 167 | log_given=m$log_given |
| 168 | if test "$log_message" = '' |
| 169 | then |
| 170 | log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
| 171 | else |
| 172 | log_message="$log_message |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 173 | |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 174 | `expr "z$1" : 'zq-[^=]*=\(.*\)'`" |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 175 | fi |
| 176 | no_edit=t |
| 177 | shift |
| 178 | ;; |
| 179 | -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\ |
| 180 | --no-verify) |
| 181 | verify= |
| 182 | shift |
| 183 | ;; |
| 184 | --a|--am|--ame|--amen|--amend) |
| 185 | amend=t |
| 186 | log_given=t$log_given |
| 187 | use_commit=HEAD |
| 188 | shift |
| 189 | ;; |
| 190 | -c) |
| 191 | case "$#" in 1) usage ;; esac |
| 192 | shift |
| 193 | log_given=t$log_given |
| 194 | use_commit="$1" |
| 195 | no_edit= |
| 196 | shift |
| 197 | ;; |
| 198 | --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ |
| 199 | --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ |
| 200 | --reedit-messag=*|--reedit-message=*) |
| 201 | log_given=t$log_given |
| 202 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
| 203 | no_edit= |
| 204 | shift |
| 205 | ;; |
| 206 | --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ |
| 207 | --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\ |
| 208 | --reedit-message) |
| 209 | case "$#" in 1) usage ;; esac |
| 210 | shift |
| 211 | log_given=t$log_given |
| 212 | use_commit="$1" |
| 213 | no_edit= |
| 214 | shift |
| 215 | ;; |
| 216 | -C) |
| 217 | case "$#" in 1) usage ;; esac |
| 218 | shift |
| 219 | log_given=t$log_given |
| 220 | use_commit="$1" |
| 221 | no_edit=t |
| 222 | shift |
| 223 | ;; |
| 224 | --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ |
| 225 | --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ |
| 226 | --reuse-message=*) |
| 227 | log_given=t$log_given |
| 228 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
| 229 | no_edit=t |
| 230 | shift |
| 231 | ;; |
| 232 | --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ |
| 233 | --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) |
| 234 | case "$#" in 1) usage ;; esac |
| 235 | shift |
| 236 | log_given=t$log_given |
| 237 | use_commit="$1" |
| 238 | no_edit=t |
| 239 | shift |
| 240 | ;; |
| 241 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
| 242 | signoff=t |
| 243 | shift |
| 244 | ;; |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 245 | -q|--q|--qu|--qui|--quie|--quiet) |
| 246 | quiet=t |
| 247 | shift |
| 248 | ;; |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 249 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
| 250 | verbose=t |
| 251 | shift |
| 252 | ;; |
| 253 | -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\ |
| 254 | --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\ |
| 255 | --untracked-file|--untracked-files) |
| 256 | untracked_files=t |
| 257 | shift |
| 258 | ;; |
| 259 | --) |
| 260 | shift |
| 261 | break |
| 262 | ;; |
| 263 | -*) |
| 264 | usage |
| 265 | ;; |
| 266 | *) |
| 267 | break |
| 268 | ;; |
| 269 | esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 270 | done |
Jeff King | cda8ab5 | 2006-06-23 09:43:38 -0400 | [diff] [blame] | 271 | case "$edit_flag" in t) no_edit= ;; esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 272 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 273 | ################################################################ |
| 274 | # Sanity check options |
| 275 | |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 276 | case "$amend,$initial_commit" in |
| 277 | t,t) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 278 | die "You do not have anything to amend." ;; |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 279 | t,) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 280 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
| 281 | die "You are in the middle of a merge -- cannot amend." |
| 282 | fi ;; |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 283 | esac |
| 284 | |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 285 | case "$log_given" in |
| 286 | tt*) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 287 | die "Only one of -c/-C/-F can be used." ;; |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 288 | *tm*|*mt*) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 289 | die "Option -m cannot be combined with -c/-C/-F." ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 290 | esac |
| 291 | |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 292 | case "$#,$also,$only,$amend" in |
| 293 | *,t,t,*) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 294 | die "Only one of --include/--only can be used." ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 295 | 0,t,,* | 0,,t,) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 296 | die "No paths with --include/--only does not make sense." ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 297 | 0,,t,t) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 298 | only_include_assumed="# Clever... amending the last one with dirty index." ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 299 | 0,,,*) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 300 | ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 301 | *,,,*) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 302 | only_include_assumed="# Explicit paths specified without -i nor -o; assuming --only paths..." |
| 303 | also= |
| 304 | ;; |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 305 | esac |
| 306 | unset only |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 307 | case "$all,$also,$#" in |
| 308 | t,t,*) |
| 309 | die "Cannot use -a and -i at the same time." ;; |
| 310 | t,,[1-9]*) |
| 311 | die "Paths with -a does not make sense." ;; |
| 312 | ,t,0) |
| 313 | die "No paths with -i does not make sense." ;; |
| 314 | esac |
| 315 | |
| 316 | ################################################################ |
| 317 | # Prepare index to have a tree to be committed |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 318 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 319 | case "$all,$also" in |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 320 | t,) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 321 | save_index && |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 322 | ( |
Junio C Hamano | 514c09f | 2007-01-12 12:49:05 -0800 | [diff] [blame^] | 323 | cd_to_toplevel && |
| 324 | GIT_INDEX_FILE="$NEXT_INDEX" && |
| 325 | export GIT_INDEX_FILE && |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 326 | git-diff-files --name-only -z | |
| 327 | git-update-index --remove -z --stdin |
Junio C Hamano | 514c09f | 2007-01-12 12:49:05 -0800 | [diff] [blame^] | 328 | ) || exit |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 329 | ;; |
| 330 | ,t) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 331 | save_index && |
Junio C Hamano | bba319b | 2006-02-14 12:40:20 -0800 | [diff] [blame] | 332 | git-ls-files --error-unmatch -- "$@" >/dev/null || exit |
| 333 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 334 | git-diff-files --name-only -z -- "$@" | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 335 | ( |
Junio C Hamano | 514c09f | 2007-01-12 12:49:05 -0800 | [diff] [blame^] | 336 | cd_to_toplevel && |
| 337 | GIT_INDEX_FILE="$NEXT_INDEX" && |
| 338 | export GIT_INDEX_FILE && |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 339 | git-update-index --remove -z --stdin |
Junio C Hamano | 514c09f | 2007-01-12 12:49:05 -0800 | [diff] [blame^] | 340 | ) || exit |
Junio C Hamano | 22cff6a | 2005-08-16 18:08:19 -0700 | [diff] [blame] | 341 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 342 | ,) |
| 343 | case "$#" in |
| 344 | 0) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 345 | ;; # commit as-is |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 346 | *) |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 347 | if test -f "$GIT_DIR/MERGE_HEAD" |
| 348 | then |
| 349 | refuse_partial "Cannot do a partial commit during a merge." |
| 350 | fi |
| 351 | TMP_INDEX="$GIT_DIR/tmp-index$$" |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 352 | commit_only=`git-ls-files --error-unmatch -- "$@"` || exit |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 353 | |
Junio C Hamano | 158d057 | 2006-12-09 22:32:43 -0800 | [diff] [blame] | 354 | # Build a temporary index and update the real index |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 355 | # the same way. |
| 356 | if test -z "$initial_commit" |
| 357 | then |
| 358 | cp "$THIS_INDEX" "$TMP_INDEX" |
| 359 | GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD |
| 360 | else |
| 361 | rm -f "$TMP_INDEX" |
| 362 | fi || exit |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 363 | |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 364 | echo "$commit_only" | |
| 365 | GIT_INDEX_FILE="$TMP_INDEX" \ |
| 366 | git-update-index --add --remove --stdin && |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 367 | |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 368 | save_index && |
| 369 | echo "$commit_only" | |
| 370 | ( |
| 371 | GIT_INDEX_FILE="$NEXT_INDEX" |
| 372 | export GIT_INDEX_FILE |
| 373 | git-update-index --remove --stdin |
| 374 | ) || exit |
| 375 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 376 | esac |
Junio C Hamano | f678dd1 | 2005-11-25 13:33:14 -0800 | [diff] [blame] | 377 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 378 | esac |
| 379 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 380 | ################################################################ |
| 381 | # If we do as-is commit, the index file will be THIS_INDEX, |
| 382 | # otherwise NEXT_INDEX after we make this commit. We leave |
| 383 | # the index as is if we abort. |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 384 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 385 | if test -f "$NEXT_INDEX" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 386 | then |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 387 | USE_INDEX="$NEXT_INDEX" |
| 388 | else |
| 389 | USE_INDEX="$THIS_INDEX" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 390 | fi |
| 391 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 392 | GIT_INDEX_FILE="$USE_INDEX" \ |
Martin Waitz | 3de63c3 | 2006-10-07 21:07:40 +0200 | [diff] [blame] | 393 | git-update-index -q $unmerged_ok_if_status --refresh || exit |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 394 | |
| 395 | ################################################################ |
| 396 | # If the request is status, just show it and exit. |
| 397 | |
| 398 | case "$0" in |
| 399 | *status) |
| 400 | run_status |
| 401 | exit $? |
| 402 | esac |
| 403 | |
| 404 | ################################################################ |
| 405 | # Grab commit message, write out tree and make commit. |
| 406 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 407 | if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit |
| 408 | then |
| 409 | if test "$TMP_INDEX" |
| 410 | then |
| 411 | GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit |
| 412 | else |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 413 | GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 414 | fi || exit |
| 415 | fi |
Junio C Hamano | 0cfe1d3 | 2005-08-12 23:39:15 -0700 | [diff] [blame] | 416 | |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 417 | if test "$log_message" != '' |
| 418 | then |
| 419 | echo "$log_message" |
| 420 | elif test "$logfile" != "" |
| 421 | then |
| 422 | if test "$logfile" = - |
| 423 | then |
| 424 | test -t 0 && |
| 425 | echo >&2 "(reading log message from standard input)" |
| 426 | cat |
| 427 | else |
| 428 | cat <"$logfile" |
| 429 | fi |
| 430 | elif test "$use_commit" != "" |
| 431 | then |
| 432 | git-cat-file commit "$use_commit" | sed -e '1,/^$/d' |
Luben Tuikov | a9cb3c6 | 2006-10-12 14:52:42 -0700 | [diff] [blame] | 433 | elif test -f "$GIT_DIR/MERGE_MSG" |
Junio C Hamano | e521580 | 2005-11-01 22:01:28 -0800 | [diff] [blame] | 434 | then |
| 435 | cat "$GIT_DIR/MERGE_MSG" |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 436 | elif test -f "$GIT_DIR/SQUASH_MSG" |
| 437 | then |
| 438 | cat "$GIT_DIR/SQUASH_MSG" |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 439 | fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 440 | |
| 441 | case "$signoff" in |
| 442 | t) |
Junio C Hamano | f641339 | 2005-10-03 23:49:46 -0700 | [diff] [blame] | 443 | { |
| 444 | echo |
| 445 | git-var GIT_COMMITTER_IDENT | sed -e ' |
| 446 | s/>.*/>/ |
| 447 | s/^/Signed-off-by: / |
| 448 | ' |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 449 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 450 | ;; |
| 451 | esac |
| 452 | |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 453 | if test -f "$GIT_DIR/MERGE_HEAD" && test -z "$no_edit"; then |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 454 | echo "#" |
Alex Riesen | b6ae540 | 2006-01-05 12:44:59 +0100 | [diff] [blame] | 455 | echo "# It looks like you may be committing a MERGE." |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 456 | echo "# If this is not correct, please remove the file" |
| 457 | echo "# $GIT_DIR/MERGE_HEAD" |
| 458 | echo "# and try again" |
| 459 | echo "#" |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 460 | fi >>"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 461 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 462 | # Author |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 463 | if test '' != "$force_author" |
| 464 | then |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 465 | GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` && |
| 466 | GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 467 | test '' != "$GIT_AUTHOR_NAME" && |
| 468 | test '' != "$GIT_AUTHOR_EMAIL" || |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 469 | die "malformed --author parameter" |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 470 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL |
| 471 | elif test '' != "$use_commit" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 472 | then |
| 473 | pick_author_script=' |
| 474 | /^author /{ |
| 475 | s/'\''/'\''\\'\'\''/g |
| 476 | h |
| 477 | s/^author \([^<]*\) <[^>]*> .*$/\1/ |
| 478 | s/'\''/'\''\'\'\''/g |
| 479 | s/.*/GIT_AUTHOR_NAME='\''&'\''/p |
| 480 | |
| 481 | g |
| 482 | s/^author [^<]* <\([^>]*\)> .*$/\1/ |
| 483 | s/'\''/'\''\'\'\''/g |
| 484 | s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p |
| 485 | |
| 486 | g |
| 487 | s/^author [^<]* <[^>]*> \(.*\)$/\1/ |
| 488 | s/'\''/'\''\'\'\''/g |
| 489 | s/.*/GIT_AUTHOR_DATE='\''&'\''/p |
| 490 | |
| 491 | q |
| 492 | } |
| 493 | ' |
| 494 | set_author_env=`git-cat-file commit "$use_commit" | |
| 495 | LANG=C LC_ALL=C sed -ne "$pick_author_script"` |
| 496 | eval "$set_author_env" |
| 497 | export GIT_AUTHOR_NAME |
| 498 | export GIT_AUTHOR_EMAIL |
| 499 | export GIT_AUTHOR_DATE |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 500 | fi |
| 501 | |
Linus Torvalds | 96069cf | 2005-06-14 10:20:14 -0700 | [diff] [blame] | 502 | PARENTS="-p HEAD" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 503 | if test -z "$initial_commit" |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 504 | then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 505 | rloga='commit' |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 506 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 507 | rloga='commit (merge)' |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 508 | PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 509 | elif test -n "$amend"; then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 510 | rloga='commit (amend)' |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 511 | PARENTS=$(git-cat-file commit HEAD | |
| 512 | sed -n -e '/^$/q' -e 's/^parent /-p /p') |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 513 | fi |
Junio C Hamano | cede752 | 2006-09-27 02:06:31 -0700 | [diff] [blame] | 514 | current="$(git-rev-parse --verify HEAD)" |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 515 | else |
| 516 | if [ -z "$(git-ls-files)" ]; then |
Shawn O. Pearce | aeb80c7 | 2006-12-15 21:53:09 -0500 | [diff] [blame] | 517 | echo >&2 'nothing to commit (use "git add file1 file2" to include for commit)' |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 518 | exit 1 |
| 519 | fi |
| 520 | PARENTS="" |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 521 | rloga='commit (initial)' |
Junio C Hamano | cede752 | 2006-09-27 02:06:31 -0700 | [diff] [blame] | 522 | current='' |
Linus Torvalds | 96069cf | 2005-06-14 10:20:14 -0700 | [diff] [blame] | 523 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 524 | |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 525 | if test -z "$no_edit" |
| 526 | then |
| 527 | { |
Martin Waitz | 88a1531 | 2006-05-26 01:42:18 +0200 | [diff] [blame] | 528 | echo "" |
| 529 | echo "# Please enter the commit message for your changes." |
| 530 | echo "# (Comment lines starting with '#' will not be included)" |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 531 | test -z "$only_include_assumed" || echo "$only_include_assumed" |
| 532 | run_status |
| 533 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
| 534 | else |
| 535 | # we need to check if there is anything to commit |
| 536 | run_status >/dev/null |
| 537 | fi |
Junio C Hamano | 8588452 | 2006-03-04 20:36:28 -0800 | [diff] [blame] | 538 | if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] |
Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 539 | then |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 540 | rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 541 | run_status |
Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 542 | exit 1 |
| 543 | fi |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 544 | |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 545 | case "$no_edit" in |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 546 | '') |
Junio C Hamano | 7334f06 | 2006-02-04 22:10:32 -0800 | [diff] [blame] | 547 | case "${VISUAL:-$EDITOR},$TERM" in |
| 548 | ,dumb) |
| 549 | echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." |
| 550 | echo >&2 "Please supply the commit log message using either" |
| 551 | echo >&2 "-m or -F option. A boilerplate log message has" |
| 552 | echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 553 | exit 1 |
| 554 | ;; |
Junio C Hamano | 7334f06 | 2006-02-04 22:10:32 -0800 | [diff] [blame] | 555 | esac |
Sean | ec4e69c | 2006-05-13 23:09:32 -0400 | [diff] [blame] | 556 | git-var GIT_AUTHOR_IDENT > /dev/null || die |
| 557 | git-var GIT_COMMITTER_IDENT > /dev/null || die |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 558 | ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 559 | ;; |
| 560 | esac |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 561 | |
| 562 | case "$verify" in |
| 563 | t) |
| 564 | if test -x "$GIT_DIR"/hooks/commit-msg |
| 565 | then |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 566 | "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 567 | fi |
| 568 | esac |
| 569 | |
Yann Dirson | 29f4ad8 | 2006-06-24 00:04:05 +0200 | [diff] [blame] | 570 | if test -z "$no_edit" |
| 571 | then |
| 572 | sed -e ' |
| 573 | /^diff --git a\/.*/{ |
| 574 | s/// |
| 575 | q |
| 576 | } |
| 577 | /^#/d |
| 578 | ' "$GIT_DIR"/COMMIT_EDITMSG |
| 579 | else |
| 580 | cat "$GIT_DIR"/COMMIT_EDITMSG |
| 581 | fi | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 582 | git-stripspace >"$GIT_DIR"/COMMIT_MSG |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 583 | |
| 584 | if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | |
| 585 | git-stripspace | |
| 586 | wc -l` && |
| 587 | test 0 -lt $cnt |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 588 | then |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 589 | if test -z "$TMP_INDEX" |
| 590 | then |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 591 | tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 592 | else |
| 593 | tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) && |
| 594 | rm -f "$TMP_INDEX" |
| 595 | fi && |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 596 | commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) && |
Shawn Pearce | 67644a4 | 2006-05-19 05:16:18 -0400 | [diff] [blame] | 597 | rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && |
Junio C Hamano | cede752 | 2006-09-27 02:06:31 -0700 | [diff] [blame] | 598 | git-update-ref -m "$rloga: $rlogm" HEAD $commit "$current" && |
Luben Tuikov | a9cb3c6 | 2006-10-12 14:52:42 -0700 | [diff] [blame] | 599 | rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" && |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 600 | if test -f "$NEXT_INDEX" |
| 601 | then |
| 602 | mv "$NEXT_INDEX" "$THIS_INDEX" |
| 603 | else |
| 604 | : ;# happy |
| 605 | fi |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 606 | else |
| 607 | echo >&2 "* no commit message? aborting commit." |
| 608 | false |
| 609 | fi |
Linus Torvalds | 170241b | 2005-06-19 19:57:01 -0700 | [diff] [blame] | 610 | ret="$?" |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 611 | rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
Junio C Hamano | 1536dd9c6 | 2006-02-11 18:55:43 -0800 | [diff] [blame] | 612 | if test -d "$GIT_DIR/rr-cache" |
| 613 | then |
| 614 | git-rerere |
| 615 | fi |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 616 | |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 617 | if test "$ret" = 0 |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 618 | then |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 619 | if test -x "$GIT_DIR"/hooks/post-commit |
| 620 | then |
| 621 | "$GIT_DIR"/hooks/post-commit |
| 622 | fi |
| 623 | if test -z "$quiet" |
| 624 | then |
| 625 | echo "Created${initial_commit:+ initial} commit $commit" |
Michael Loeffler | 521f9c4 | 2007-01-08 20:23:13 +0100 | [diff] [blame] | 626 | git-diff-tree --shortstat --summary --root --no-commit-id HEAD -- |
Nicolas Pitre | ebd124c | 2006-12-14 23:15:44 -0500 | [diff] [blame] | 627 | fi |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 628 | fi |
Junio C Hamano | 61f5cb7 | 2006-10-24 21:48:55 -0700 | [diff] [blame] | 629 | |
Linus Torvalds | 170241b | 2005-06-19 19:57:01 -0700 | [diff] [blame] | 630 | exit "$ret" |