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