Remove MERGE_HEAD in "git checkout/reset"
[git/kirr.git] / git-commit-script
blob57f5333db8517f4f250b563f694c067446c78c10
1 #!/bin/sh
2 : ${GIT_DIR=.git}
3 if [ ! -d $GIT_DIR ]; then
4 echo Not a git directory 1>&2
5 exit 1
6 fi
7 git-update-cache -q --refresh -- "$@" || exit 1
8 PARENTS="-p HEAD"
9 if [ ! -r $GIT_DIR/HEAD ]; then
10 if [ -z "$(git-ls-files)" ]; then
11 echo Nothing to commit 1>&2
12 exit 1
15 echo "#"
16 echo "# Initial commit"
17 echo "#"
18 git-ls-files | sed 's/^/# New file: /'
19 echo "#"
20 ) > .editmsg
21 PARENTS=""
22 else
23 if [ -f $GIT_DIR/MERGE_HEAD ]; then
24 echo "#"
25 echo "# It looks like your may be committing a MERGE."
26 echo "# If this is not correct, please remove the file"
27 echo "# $GIT_DIR/MERGE_HEAD"
28 echo "# and try again"
29 echo "#"
30 PARENTS="-p HEAD -p MERGE_HEAD"
31 fi > .editmsg
32 git-status-script >> .editmsg
34 if [ "$?" != "0" ]
35 then
36 cat .editmsg
37 rm .editmsg
38 exit 1
40 ${VISUAL:-${EDITOR:-vi}} .editmsg
41 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
42 [ -s .cmitmsg ] &&
43 tree=$(git-write-tree) &&
44 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
45 echo $commit > $GIT_DIR/HEAD &&
46 rm -f -- $GIT_DIR/MERGE_HEAD
47 ret="$?"
48 rm -f .cmitmsg .editmsg
49 exit "$ret"