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