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