Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 1 | #!/bin/sh |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2005 Linus Torvalds |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 4 | # Copyright (c) 2006 Junio C Hamano |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 5 | |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 6 | USAGE='[-a] [-s] [-v] [--no-verify] [-m <message> | -F <logfile> | (-C|-c) <commit>] [-u] [--amend] [-e] [--author <author>] [[-i | -o] <path>...]' |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 7 | SUBDIRECTORY_OK=Yes |
Junio C Hamano | ae2b0f1 | 2005-11-24 00:12:11 -0800 | [diff] [blame] | 8 | . git-sh-setup |
Linus Torvalds | b33e966 | 2005-07-08 10:57:21 -0700 | [diff] [blame] | 9 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 10 | git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t |
| 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 | 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 | |
| 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 | |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 137 | option="" |
| 138 | if test -z "$untracked_files"; then |
| 139 | option="--directory --no-empty-directory" |
| 140 | fi |
Alex Riesen | 3dffd2c | 2006-07-13 10:30:43 +0200 | [diff] [blame] | 141 | hdr_shown= |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 142 | if test -f "$GIT_DIR/info/exclude" |
| 143 | then |
Alex Riesen | 3dffd2c | 2006-07-13 10:30:43 +0200 | [diff] [blame] | 144 | git-ls-files --others $option \ |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 145 | --exclude-from="$GIT_DIR/info/exclude" \ |
| 146 | --exclude-per-directory=.gitignore |
| 147 | else |
Alex Riesen | 3dffd2c | 2006-07-13 10:30:43 +0200 | [diff] [blame] | 148 | git-ls-files --others $option \ |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 149 | --exclude-per-directory=.gitignore |
| 150 | fi | |
Alex Riesen | 3dffd2c | 2006-07-13 10:30:43 +0200 | [diff] [blame] | 151 | while read line; do |
| 152 | if [ -z "$hdr_shown" ]; then |
| 153 | echo '#' |
| 154 | echo '# Untracked files:' |
| 155 | echo '# (use "git add" to add to commit)' |
| 156 | echo '#' |
| 157 | hdr_shown=1 |
| 158 | fi |
| 159 | echo "# $line" |
| 160 | done |
Junio C Hamano | 9ae6be8 | 2006-02-10 18:38:24 -0800 | [diff] [blame] | 161 | |
Yasushi SHOJI | 1fa7a68 | 2006-03-20 22:11:12 +0900 | [diff] [blame] | 162 | if test -n "$verbose" -a -z "$IS_INITIAL" |
Junio C Hamano | 9ae6be8 | 2006-02-10 18:38:24 -0800 | [diff] [blame] | 163 | then |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 164 | git-diff-index --cached -M -p --diff-filter=MDTCRA $REFERENCE |
Junio C Hamano | 9ae6be8 | 2006-02-10 18:38:24 -0800 | [diff] [blame] | 165 | fi |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 166 | case "$committable" in |
| 167 | 0) |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 168 | case "$amend" in |
| 169 | t) |
| 170 | echo "# No changes" ;; |
| 171 | *) |
| 172 | echo "nothing to commit" ;; |
| 173 | esac |
| 174 | exit 1 ;; |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 175 | esac |
| 176 | exit 0 |
| 177 | ) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 178 | } |
| 179 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 180 | trap ' |
| 181 | test -z "$TMP_INDEX" || { |
| 182 | test -f "$TMP_INDEX" && rm -f "$TMP_INDEX" |
| 183 | } |
| 184 | rm -f "$NEXT_INDEX" |
| 185 | ' 0 |
| 186 | |
| 187 | ################################################################ |
| 188 | # Command line argument parsing and sanity checking |
| 189 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 190 | all= |
| 191 | also= |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 192 | only= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 193 | logfile= |
| 194 | use_commit= |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 195 | amend= |
Jeff King | cda8ab5 | 2006-06-23 09:43:38 -0400 | [diff] [blame] | 196 | edit_flag= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 197 | no_edit= |
| 198 | log_given= |
| 199 | log_message= |
| 200 | verify=t |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 201 | verbose= |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 202 | signoff= |
| 203 | force_author= |
Junio C Hamano | bba319b | 2006-02-14 12:40:20 -0800 | [diff] [blame] | 204 | only_include_assumed= |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 205 | untracked_files= |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 206 | while case "$#" in 0) break;; esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 207 | do |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 208 | case "$1" in |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 209 | -F|--F|-f|--f|--fi|--fil|--file) |
| 210 | case "$#" in 1) usage ;; esac |
| 211 | shift |
| 212 | no_edit=t |
| 213 | log_given=t$log_given |
| 214 | logfile="$1" |
| 215 | shift |
| 216 | ;; |
| 217 | -F*|-f*) |
| 218 | no_edit=t |
| 219 | log_given=t$log_given |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 220 | logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 221 | shift |
| 222 | ;; |
| 223 | --F=*|--f=*|--fi=*|--fil=*|--file=*) |
| 224 | no_edit=t |
| 225 | log_given=t$log_given |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 226 | logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 227 | shift |
| 228 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 229 | -a|--a|--al|--all) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 230 | all=t |
| 231 | shift |
| 232 | ;; |
| 233 | --au=*|--aut=*|--auth=*|--autho=*|--author=*) |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 234 | force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 235 | shift |
| 236 | ;; |
| 237 | --au|--aut|--auth|--autho|--author) |
| 238 | case "$#" in 1) usage ;; esac |
| 239 | shift |
| 240 | force_author="$1" |
| 241 | shift |
| 242 | ;; |
| 243 | -e|--e|--ed|--edi|--edit) |
Jeff King | cda8ab5 | 2006-06-23 09:43:38 -0400 | [diff] [blame] | 244 | edit_flag=t |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 245 | shift |
| 246 | ;; |
| 247 | -i|--i|--in|--inc|--incl|--inclu|--includ|--include) |
| 248 | also=t |
| 249 | shift |
| 250 | ;; |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 251 | -o|--o|--on|--onl|--only) |
| 252 | only=t |
| 253 | shift |
| 254 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 255 | -m|--m|--me|--mes|--mess|--messa|--messag|--message) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 256 | case "$#" in 1) usage ;; esac |
| 257 | shift |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 258 | log_given=m$log_given |
| 259 | if test "$log_message" = '' |
| 260 | then |
| 261 | log_message="$1" |
| 262 | else |
| 263 | log_message="$log_message |
| 264 | |
| 265 | $1" |
| 266 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 267 | no_edit=t |
| 268 | shift |
| 269 | ;; |
| 270 | -m*) |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 271 | log_given=m$log_given |
| 272 | if test "$log_message" = '' |
| 273 | then |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 274 | log_message=`expr "z$1" : 'z-m\(.*\)'` |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 275 | else |
| 276 | log_message="$log_message |
| 277 | |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 278 | `expr "z$1" : 'z-m\(.*\)'`" |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 279 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 280 | no_edit=t |
| 281 | shift |
| 282 | ;; |
| 283 | --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 284 | log_given=m$log_given |
| 285 | if test "$log_message" = '' |
| 286 | then |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 287 | log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 288 | else |
| 289 | log_message="$log_message |
| 290 | |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 291 | `expr "z$1" : 'zq-[^=]*=\(.*\)'`" |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 292 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 293 | no_edit=t |
| 294 | shift |
| 295 | ;; |
| 296 | -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify) |
| 297 | verify= |
| 298 | shift |
| 299 | ;; |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 300 | --a|--am|--ame|--amen|--amend) |
| 301 | amend=t |
| 302 | log_given=t$log_given |
| 303 | use_commit=HEAD |
| 304 | shift |
| 305 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 306 | -c) |
| 307 | case "$#" in 1) usage ;; esac |
| 308 | shift |
| 309 | log_given=t$log_given |
| 310 | use_commit="$1" |
| 311 | no_edit= |
| 312 | shift |
| 313 | ;; |
| 314 | --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 315 | --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ |
| 316 | --reedit-messag=*|--reedit-message=*) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 317 | log_given=t$log_given |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 318 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 319 | no_edit= |
| 320 | shift |
| 321 | ;; |
| 322 | --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 323 | --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|--reedit-message) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 324 | case "$#" in 1) usage ;; esac |
| 325 | shift |
| 326 | log_given=t$log_given |
| 327 | use_commit="$1" |
| 328 | no_edit= |
| 329 | shift |
| 330 | ;; |
| 331 | -C) |
| 332 | case "$#" in 1) usage ;; esac |
| 333 | shift |
| 334 | log_given=t$log_given |
| 335 | use_commit="$1" |
| 336 | no_edit=t |
| 337 | shift |
| 338 | ;; |
| 339 | --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 340 | --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ |
| 341 | --reuse-message=*) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 342 | log_given=t$log_given |
Dennis Stosberg | 8096fae | 2006-06-27 18:54:26 +0200 | [diff] [blame] | 343 | use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 344 | no_edit=t |
| 345 | shift |
| 346 | ;; |
| 347 | --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 348 | --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 349 | case "$#" in 1) usage ;; esac |
| 350 | shift |
| 351 | log_given=t$log_given |
| 352 | use_commit="$1" |
| 353 | no_edit=t |
| 354 | shift |
| 355 | ;; |
Junio C Hamano | 0cfe1d3 | 2005-08-12 23:39:15 -0700 | [diff] [blame] | 356 | -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 357 | signoff=t |
| 358 | shift |
| 359 | ;; |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 360 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
| 361 | verbose=t |
| 362 | shift |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 363 | ;; |
Matthias Lederhofer | 443f833 | 2006-05-22 23:02:06 +0200 | [diff] [blame] | 364 | -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|--untracked|\ |
| 365 | --untracked-|--untracked-f|--untracked-fi|--untracked-fil|--untracked-file|\ |
| 366 | --untracked-files) |
| 367 | untracked_files=t |
| 368 | shift |
| 369 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 370 | --) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 371 | shift |
| 372 | break |
| 373 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 374 | -*) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 375 | usage |
| 376 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 377 | *) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 378 | break |
| 379 | ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 380 | esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 381 | done |
Jeff King | cda8ab5 | 2006-06-23 09:43:38 -0400 | [diff] [blame] | 382 | case "$edit_flag" in t) no_edit= ;; esac |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 383 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 384 | ################################################################ |
| 385 | # Sanity check options |
| 386 | |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 387 | case "$amend,$initial_commit" in |
| 388 | t,t) |
| 389 | die "You do not have anything to amend." ;; |
| 390 | t,) |
| 391 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
| 392 | die "You are in the middle of a merge -- cannot amend." |
| 393 | fi ;; |
| 394 | esac |
| 395 | |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 396 | case "$log_given" in |
| 397 | tt*) |
Shawn Pearce | 6891281 | 2006-05-29 04:45:49 -0400 | [diff] [blame] | 398 | die "Only one of -c/-C/-F can be used." ;; |
| 399 | *tm*|*mt*) |
| 400 | die "Option -m cannot be combined with -c/-C/-F." ;; |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 401 | esac |
| 402 | |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 403 | case "$#,$also,$only,$amend" in |
| 404 | *,t,t,*) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 405 | die "Only one of --include/--only can be used." ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 406 | 0,t,,* | 0,,t,) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 407 | die "No paths with --include/--only does not make sense." ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 408 | 0,,t,t) |
| 409 | only_include_assumed="# Clever... amending the last one with dirty index." ;; |
| 410 | 0,,,*) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 411 | ;; |
Junio C Hamano | 6a74642 | 2006-04-20 01:20:56 -0700 | [diff] [blame] | 412 | *,,,*) |
Junio C Hamano | 756e3ee | 2006-02-14 17:51:02 -0800 | [diff] [blame] | 413 | 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] | 414 | also= |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 415 | ;; |
| 416 | esac |
| 417 | unset only |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 418 | case "$all,$also,$#" in |
| 419 | t,t,*) |
| 420 | die "Cannot use -a and -i at the same time." ;; |
| 421 | t,,[1-9]*) |
| 422 | die "Paths with -a does not make sense." ;; |
| 423 | ,t,0) |
| 424 | die "No paths with -i does not make sense." ;; |
| 425 | esac |
| 426 | |
| 427 | ################################################################ |
| 428 | # Prepare index to have a tree to be committed |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 429 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 430 | TOP=`git-rev-parse --show-cdup` |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 431 | if test -z "$TOP" |
| 432 | then |
| 433 | TOP=./ |
| 434 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 435 | |
| 436 | case "$all,$also" in |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 437 | t,) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 438 | save_index && |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 439 | ( |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 440 | cd "$TOP" |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 441 | GIT_INDEX_FILE="$NEXT_INDEX" |
| 442 | export GIT_INDEX_FILE |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 443 | git-diff-files --name-only -z | |
| 444 | git-update-index --remove -z --stdin |
| 445 | ) |
| 446 | ;; |
| 447 | ,t) |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 448 | save_index && |
Junio C Hamano | bba319b | 2006-02-14 12:40:20 -0800 | [diff] [blame] | 449 | git-ls-files --error-unmatch -- "$@" >/dev/null || exit |
| 450 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 451 | git-diff-files --name-only -z -- "$@" | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 452 | ( |
| 453 | cd "$TOP" |
| 454 | GIT_INDEX_FILE="$NEXT_INDEX" |
| 455 | export GIT_INDEX_FILE |
| 456 | git-update-index --remove -z --stdin |
| 457 | ) |
Junio C Hamano | 22cff6a | 2005-08-16 18:08:19 -0700 | [diff] [blame] | 458 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 459 | ,) |
| 460 | case "$#" in |
| 461 | 0) |
| 462 | ;; # commit as-is |
| 463 | *) |
| 464 | if test -f "$GIT_DIR/MERGE_HEAD" |
| 465 | then |
| 466 | refuse_partial "Cannot do a partial commit during a merge." |
| 467 | fi |
| 468 | TMP_INDEX="$GIT_DIR/tmp-index$$" |
| 469 | if test -z "$initial_commit" |
| 470 | then |
| 471 | # make sure index is clean at the specified paths, or |
| 472 | # they are additions. |
| 473 | dirty_in_index=`git-diff-index --cached --name-status \ |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 474 | --diff-filter=DMTU HEAD -- "$@"` |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 475 | test -z "$dirty_in_index" || |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 476 | refuse_partial "Different in index and the last commit: |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 477 | $dirty_in_index" |
| 478 | fi |
Junio C Hamano | bba319b | 2006-02-14 12:40:20 -0800 | [diff] [blame] | 479 | commit_only=`git-ls-files --error-unmatch -- "$@"` || exit |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 480 | |
| 481 | # Build the temporary index and update the real index |
| 482 | # the same way. |
| 483 | if test -z "$initial_commit" |
| 484 | then |
| 485 | cp "$THIS_INDEX" "$TMP_INDEX" |
| 486 | GIT_INDEX_FILE="$TMP_INDEX" git-read-tree -m HEAD |
| 487 | else |
| 488 | rm -f "$TMP_INDEX" |
| 489 | fi || exit |
| 490 | |
| 491 | echo "$commit_only" | |
| 492 | GIT_INDEX_FILE="$TMP_INDEX" \ |
| 493 | git-update-index --add --remove --stdin && |
| 494 | |
| 495 | save_index && |
| 496 | echo "$commit_only" | |
| 497 | ( |
| 498 | GIT_INDEX_FILE="$NEXT_INDEX" |
| 499 | export GIT_INDEX_FILE |
| 500 | git-update-index --remove --stdin |
| 501 | ) || exit |
| 502 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 503 | esac |
Junio C Hamano | f678dd1 | 2005-11-25 13:33:14 -0800 | [diff] [blame] | 504 | ;; |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 505 | esac |
| 506 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 507 | ################################################################ |
| 508 | # If we do as-is commit, the index file will be THIS_INDEX, |
| 509 | # otherwise NEXT_INDEX after we make this commit. We leave |
| 510 | # the index as is if we abort. |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 511 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 512 | if test -f "$NEXT_INDEX" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 513 | then |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 514 | USE_INDEX="$NEXT_INDEX" |
| 515 | else |
| 516 | USE_INDEX="$THIS_INDEX" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 517 | fi |
| 518 | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 519 | GIT_INDEX_FILE="$USE_INDEX" \ |
| 520 | git-update-index -q $unmerged_ok_if_status --refresh || exit |
| 521 | |
| 522 | ################################################################ |
| 523 | # If the request is status, just show it and exit. |
| 524 | |
| 525 | case "$0" in |
| 526 | *status) |
| 527 | run_status |
| 528 | exit $? |
| 529 | esac |
| 530 | |
| 531 | ################################################################ |
| 532 | # Grab commit message, write out tree and make commit. |
| 533 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 534 | if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit |
| 535 | then |
| 536 | if test "$TMP_INDEX" |
| 537 | then |
| 538 | GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit |
| 539 | else |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 540 | GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 541 | fi || exit |
| 542 | fi |
Junio C Hamano | 0cfe1d3 | 2005-08-12 23:39:15 -0700 | [diff] [blame] | 543 | |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 544 | if test "$log_message" != '' |
| 545 | then |
| 546 | echo "$log_message" |
| 547 | elif test "$logfile" != "" |
| 548 | then |
| 549 | if test "$logfile" = - |
| 550 | then |
| 551 | test -t 0 && |
| 552 | echo >&2 "(reading log message from standard input)" |
| 553 | cat |
| 554 | else |
| 555 | cat <"$logfile" |
| 556 | fi |
| 557 | elif test "$use_commit" != "" |
| 558 | then |
| 559 | git-cat-file commit "$use_commit" | sed -e '1,/^$/d' |
Junio C Hamano | e521580 | 2005-11-01 22:01:28 -0800 | [diff] [blame] | 560 | elif test -f "$GIT_DIR/MERGE_HEAD" && test -f "$GIT_DIR/MERGE_MSG" |
| 561 | then |
| 562 | cat "$GIT_DIR/MERGE_MSG" |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 563 | elif test -f "$GIT_DIR/SQUASH_MSG" |
| 564 | then |
| 565 | cat "$GIT_DIR/SQUASH_MSG" |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 566 | fi | git-stripspace >"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 567 | |
| 568 | case "$signoff" in |
| 569 | t) |
Junio C Hamano | f641339 | 2005-10-03 23:49:46 -0700 | [diff] [blame] | 570 | { |
| 571 | echo |
| 572 | git-var GIT_COMMITTER_IDENT | sed -e ' |
| 573 | s/>.*/>/ |
| 574 | s/^/Signed-off-by: / |
| 575 | ' |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 576 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 577 | ;; |
| 578 | esac |
| 579 | |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 580 | 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] | 581 | echo "#" |
Alex Riesen | b6ae540 | 2006-01-05 12:44:59 +0100 | [diff] [blame] | 582 | echo "# It looks like you may be committing a MERGE." |
Junio C Hamano | 2d56993 | 2005-08-31 17:15:25 -0700 | [diff] [blame] | 583 | echo "# If this is not correct, please remove the file" |
| 584 | echo "# $GIT_DIR/MERGE_HEAD" |
| 585 | echo "# and try again" |
| 586 | echo "#" |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 587 | fi >>"$GIT_DIR"/COMMIT_EDITMSG |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 588 | |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 589 | # Author |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 590 | if test '' != "$force_author" |
| 591 | then |
Mark Wooding | f327dbc | 2006-04-13 22:01:24 +0000 | [diff] [blame] | 592 | GIT_AUTHOR_NAME=`expr "z$force_author" : 'z\(.*[^ ]\) *<.*'` && |
| 593 | GIT_AUTHOR_EMAIL=`expr "z$force_author" : '.*\(<.*\)'` && |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 594 | test '' != "$GIT_AUTHOR_NAME" && |
| 595 | test '' != "$GIT_AUTHOR_EMAIL" || |
Pavel Roskin | 82e5a82 | 2006-07-10 01:50:18 -0400 | [diff] [blame] | 596 | die "malformed --author parameter" |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 597 | export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL |
| 598 | elif test '' != "$use_commit" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 599 | then |
| 600 | pick_author_script=' |
| 601 | /^author /{ |
| 602 | s/'\''/'\''\\'\'\''/g |
| 603 | h |
| 604 | s/^author \([^<]*\) <[^>]*> .*$/\1/ |
| 605 | s/'\''/'\''\'\'\''/g |
| 606 | s/.*/GIT_AUTHOR_NAME='\''&'\''/p |
| 607 | |
| 608 | g |
| 609 | s/^author [^<]* <\([^>]*\)> .*$/\1/ |
| 610 | s/'\''/'\''\'\'\''/g |
| 611 | s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p |
| 612 | |
| 613 | g |
| 614 | s/^author [^<]* <[^>]*> \(.*\)$/\1/ |
| 615 | s/'\''/'\''\'\'\''/g |
| 616 | s/.*/GIT_AUTHOR_DATE='\''&'\''/p |
| 617 | |
| 618 | q |
| 619 | } |
| 620 | ' |
| 621 | set_author_env=`git-cat-file commit "$use_commit" | |
| 622 | LANG=C LC_ALL=C sed -ne "$pick_author_script"` |
| 623 | eval "$set_author_env" |
| 624 | export GIT_AUTHOR_NAME |
| 625 | export GIT_AUTHOR_EMAIL |
| 626 | export GIT_AUTHOR_DATE |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 627 | fi |
| 628 | |
Linus Torvalds | 96069cf | 2005-06-14 10:20:14 -0700 | [diff] [blame] | 629 | PARENTS="-p HEAD" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 630 | if test -z "$initial_commit" |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 631 | then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 632 | rloga='commit' |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 633 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 634 | rloga='commit (merge)' |
Junio C Hamano | 91063bb | 2005-09-08 13:47:12 -0700 | [diff] [blame] | 635 | PARENTS="-p HEAD "`sed -e 's/^/-p /' "$GIT_DIR/MERGE_HEAD"` |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 636 | elif test -n "$amend"; then |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 637 | rloga='commit (amend)' |
Junio C Hamano | b4019f0 | 2006-03-02 21:04:05 -0800 | [diff] [blame] | 638 | PARENTS=$(git-cat-file commit HEAD | |
| 639 | sed -n -e '/^$/q' -e 's/^parent /-p /p') |
Junio C Hamano | aba2da1 | 2005-08-25 18:57:35 -0700 | [diff] [blame] | 640 | fi |
Junio C Hamano | b831015 | 2006-03-02 21:13:24 -0800 | [diff] [blame] | 641 | current=$(git-rev-parse --verify HEAD) |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 642 | else |
| 643 | if [ -z "$(git-ls-files)" ]; then |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 644 | echo >&2 Nothing to commit |
Junio C Hamano | 8098a17 | 2005-09-30 14:26:57 -0700 | [diff] [blame] | 645 | exit 1 |
| 646 | fi |
| 647 | PARENTS="" |
Junio C Hamano | b831015 | 2006-03-02 21:13:24 -0800 | [diff] [blame] | 648 | current= |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 649 | rloga='commit (initial)' |
Linus Torvalds | 96069cf | 2005-06-14 10:20:14 -0700 | [diff] [blame] | 650 | fi |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 651 | |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 652 | if test -z "$no_edit" |
| 653 | then |
| 654 | { |
Martin Waitz | 88a1531 | 2006-05-26 01:42:18 +0200 | [diff] [blame] | 655 | echo "" |
| 656 | echo "# Please enter the commit message for your changes." |
| 657 | echo "# (Comment lines starting with '#' will not be included)" |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 658 | test -z "$only_include_assumed" || echo "$only_include_assumed" |
| 659 | run_status |
| 660 | } >>"$GIT_DIR"/COMMIT_EDITMSG |
| 661 | else |
| 662 | # we need to check if there is anything to commit |
| 663 | run_status >/dev/null |
| 664 | fi |
Junio C Hamano | 8588452 | 2006-03-04 20:36:28 -0800 | [diff] [blame] | 665 | if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] |
Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 666 | then |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 667 | rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
Junio C Hamano | 5a798fb | 2006-02-05 16:08:01 -0800 | [diff] [blame] | 668 | run_status |
Linus Torvalds | a3e870f | 2005-05-30 12:51:00 -0700 | [diff] [blame] | 669 | exit 1 |
| 670 | fi |
Junio C Hamano | 475443c | 2006-04-12 11:45:18 -0700 | [diff] [blame] | 671 | |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 672 | case "$no_edit" in |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 673 | '') |
Junio C Hamano | 7334f06 | 2006-02-04 22:10:32 -0800 | [diff] [blame] | 674 | case "${VISUAL:-$EDITOR},$TERM" in |
| 675 | ,dumb) |
| 676 | echo >&2 "Terminal is dumb but no VISUAL nor EDITOR defined." |
| 677 | echo >&2 "Please supply the commit log message using either" |
| 678 | echo >&2 "-m or -F option. A boilerplate log message has" |
| 679 | echo >&2 "been prepared in $GIT_DIR/COMMIT_EDITMSG" |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 680 | exit 1 |
| 681 | ;; |
Junio C Hamano | 7334f06 | 2006-02-04 22:10:32 -0800 | [diff] [blame] | 682 | esac |
Sean | ec4e69c | 2006-05-13 23:09:32 -0400 | [diff] [blame] | 683 | git-var GIT_AUTHOR_IDENT > /dev/null || die |
| 684 | git-var GIT_COMMITTER_IDENT > /dev/null || die |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 685 | ${VISUAL:-${EDITOR:-vi}} "$GIT_DIR/COMMIT_EDITMSG" |
Junio C Hamano | 5fec3ef | 2005-06-25 02:22:05 -0700 | [diff] [blame] | 686 | ;; |
| 687 | esac |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 688 | |
| 689 | case "$verify" in |
| 690 | t) |
| 691 | if test -x "$GIT_DIR"/hooks/commit-msg |
| 692 | then |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 693 | "$GIT_DIR"/hooks/commit-msg "$GIT_DIR"/COMMIT_EDITMSG || exit |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 694 | fi |
| 695 | esac |
| 696 | |
Yann Dirson | 29f4ad8 | 2006-06-24 00:04:05 +0200 | [diff] [blame] | 697 | if test -z "$no_edit" |
| 698 | then |
| 699 | sed -e ' |
| 700 | /^diff --git a\/.*/{ |
| 701 | s/// |
| 702 | q |
| 703 | } |
| 704 | /^#/d |
| 705 | ' "$GIT_DIR"/COMMIT_EDITMSG |
| 706 | else |
| 707 | cat "$GIT_DIR"/COMMIT_EDITMSG |
| 708 | fi | |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 709 | git-stripspace >"$GIT_DIR"/COMMIT_MSG |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 710 | |
| 711 | if cnt=`grep -v -i '^Signed-off-by' "$GIT_DIR"/COMMIT_MSG | |
| 712 | git-stripspace | |
| 713 | wc -l` && |
| 714 | test 0 -lt $cnt |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 715 | then |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 716 | if test -z "$TMP_INDEX" |
| 717 | then |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 718 | tree=$(GIT_INDEX_FILE="$USE_INDEX" git-write-tree) |
Junio C Hamano | 130fcca | 2006-02-05 00:07:44 -0800 | [diff] [blame] | 719 | else |
| 720 | tree=$(GIT_INDEX_FILE="$TMP_INDEX" git-write-tree) && |
| 721 | rm -f "$TMP_INDEX" |
| 722 | fi && |
Santi_Béjar | f8e2c54 | 2005-10-09 17:30:19 -0700 | [diff] [blame] | 723 | commit=$(cat "$GIT_DIR"/COMMIT_MSG | git-commit-tree $tree $PARENTS) && |
Shawn Pearce | 67644a4 | 2006-05-19 05:16:18 -0400 | [diff] [blame] | 724 | rlogm=$(sed -e 1q "$GIT_DIR"/COMMIT_MSG) && |
Shawn Pearce | a3a733e | 2006-07-10 22:48:47 -0400 | [diff] [blame] | 725 | git-update-ref -m "$rloga: $rlogm" HEAD $commit $current && |
Junio C Hamano | cf7bb58 | 2006-02-10 00:45:59 -0800 | [diff] [blame] | 726 | rm -f -- "$GIT_DIR/MERGE_HEAD" && |
| 727 | if test -f "$NEXT_INDEX" |
| 728 | then |
| 729 | mv "$NEXT_INDEX" "$THIS_INDEX" |
| 730 | else |
| 731 | : ;# happy |
| 732 | fi |
Junio C Hamano | 0c09129 | 2005-08-08 17:03:14 -0700 | [diff] [blame] | 733 | else |
| 734 | echo >&2 "* no commit message? aborting commit." |
| 735 | false |
| 736 | fi |
Linus Torvalds | 170241b | 2005-06-19 19:57:01 -0700 | [diff] [blame] | 737 | ret="$?" |
Junio C Hamano | 7d0c688 | 2006-06-23 01:37:02 -0700 | [diff] [blame] | 738 | rm -f "$GIT_DIR/COMMIT_MSG" "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" |
Junio C Hamano | 1536dd9c6 | 2006-02-11 18:55:43 -0800 | [diff] [blame] | 739 | if test -d "$GIT_DIR/rr-cache" |
| 740 | then |
| 741 | git-rerere |
| 742 | fi |
Junio C Hamano | 89e2c5f | 2005-08-18 17:20:08 -0700 | [diff] [blame] | 743 | |
| 744 | if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0 |
| 745 | then |
| 746 | "$GIT_DIR"/hooks/post-commit |
| 747 | fi |
Linus Torvalds | 170241b | 2005-06-19 19:57:01 -0700 | [diff] [blame] | 748 | exit "$ret" |