[PATCH] Fixup t/t5300 unit tests broken by 5f3de58ff85c49620ae2a1722d8d4d37c881a054
[git/dscho.git] / git-commit-script
blob2632afdeede1af08e59fe1163cc8be2ba9e9f5cf
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 usage () {
7 echo 'git commit [-m existing-commit] [<path>...]'
8 exit 1
11 : ${GIT_DIR=.git}
12 if [ ! -d "$GIT_DIR" ]; then
13 echo Not a git directory 1>&2
14 exit 1
16 while case "$#" in 0) break ;; esac
18 case "$1" in
19 -m) shift
20 case "$#" in
21 0) usage ;;
22 *) use_commit=`git-rev-parse "$1"` ||
23 exit ;;
24 esac
26 *) break
28 esac
29 shift
30 done
32 git-update-cache -q --refresh -- "$@" || exit 1
33 PARENTS="-p HEAD"
34 if [ ! -r "$GIT_DIR/HEAD" ]; then
35 if [ -z "$(git-ls-files)" ]; then
36 echo Nothing to commit 1>&2
37 exit 1
40 echo "#"
41 echo "# Initial commit"
42 echo "#"
43 git-ls-files | sed 's/^/# New file: /'
44 echo "#"
45 ) > .editmsg
46 PARENTS=""
47 else
48 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
49 echo "#"
50 echo "# It looks like your may be committing a MERGE."
51 echo "# If this is not correct, please remove the file"
52 echo "# $GIT_DIR/MERGE_HEAD"
53 echo "# and try again"
54 echo "#"
55 PARENTS="-p HEAD -p MERGE_HEAD"
56 elif test "$use_commit" != ""
57 then
58 pick_author_script='
59 /^author /{
61 s/^author \([^<]*\) <[^>]*> .*$/\1/
62 s/'\''/'\''\'\'\''/g
63 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
66 s/^author [^<]* <\([^>]*\)> .*$/\1/
67 s/'\''/'\''\'\'\''/g
68 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
71 s/^author [^<]* <[^>]*> \(.*\)$/\1/
72 s/'\''/'\''\'\'\''/g
73 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
78 set_author_env=`git-cat-file commit "$use_commit" |
79 sed -ne "$pick_author_script"`
80 eval "$set_author_env"
81 export GIT_AUTHOR_NAME
82 export GIT_AUTHOR_EMAIL
83 export GIT_AUTHOR_DATE
84 git-cat-file commit "$use_commit" |
85 sed -e '1,/^$/d'
86 fi >.editmsg
87 git-status-script >>.editmsg
89 if [ "$?" != "0" ]
90 then
91 cat .editmsg
92 rm .editmsg
93 exit 1
95 case "$use_commit" in
96 '')
97 ${VISUAL:-${EDITOR:-vi}} .editmsg
99 esac
100 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
101 [ -s .cmitmsg ] &&
102 tree=$(git-write-tree) &&
103 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
104 echo $commit > "$GIT_DIR/HEAD" &&
105 rm -f -- "$GIT_DIR/MERGE_HEAD"
106 ret="$?"
107 rm -f .cmitmsg .editmsg
108 exit "$ret"