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