git-rev-parse: parse ".." before simple SHA1's
[alt-git.git] / git-commit-script
blob5e5c0ccb3a8605248e1467a6841a03ef65540eb0
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 PARENTS="-p HEAD"
8 if [ ! -r $GIT_DIR/HEAD ]; then
9 if [ -z "$(git-ls-files)" ]; then
10 echo Nothing to commit 1>&2
11 exit 1
14 echo "#"
15 echo "# Initial commit"
16 echo "#"
17 git-ls-files | sed 's/^/# New file: /'
18 echo "#"
19 ) > .editmsg
20 PARENTS=""
21 else
22 if [ -f $GIT_DIR/MERGE_HEAD ]; then
23 echo "#"
24 echo "# It looks like your may be committing a MERGE."
25 echo "# If this is not correct, please remove the file"
26 echo "# $GIT_DIR/MERGE_HEAD"
27 echo "# and try again"
28 echo "#"
29 PARENTS="-p HEAD -p MERGE_HEAD"
30 fi > .editmsg
31 git-status-script >> .editmsg
33 if [ "$?" != "0" ]
34 then
35 cat .editmsg
36 rm .editmsg
37 exit 1
39 ${VISUAL:-${EDITOR:-vi}} .editmsg
40 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
41 [ -s .cmitmsg ] &&
42 tree=$(git-write-tree) &&
43 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
44 echo $commit > $GIT_DIR/HEAD &&
45 rm -f -- $GIT_DIR/MERGE_HEAD
46 ret="$?"
47 rm -f .cmitmsg .editmsg
48 exit "$ret"