Make "git commit" handle initial commits too
[git/git.git] / git-commit-script
CommitLineData
a3e870f2 1#!/bin/sh
9c065315 2: ${GIT_DIR=.git}
96069cf0
LT
3if [ ! -d $GIT_DIR ]; then
4 echo Not a git directory 1>&2
5 exit 1
6fi
7PARENTS="-p HEAD"
8if [ ! -r $GIT_DIR/HEAD ]; then
9 if [ -z "$(git-ls-files)" ]; then
10 echo Nothing to commit 1>&2
11 exit 1
12 fi
13 (
14 echo "#"
15 echo "# Initial commit"
16 echo "#"
17 git-ls-files | sed 's/^/# New file: /'
18 echo "#"
19 ) > .editmsg
20 PARENTS=""
21else
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
32fi
a3e870f2
LT
33if [ "$?" != "0" ]
34then
35 cat .editmsg
36 exit 1
37fi
2036d841 38${VISUAL:-${EDITOR:-vi}} .editmsg
a3e870f2
LT
39grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
40[ -s .cmitmsg ] || exit 1
41tree=$(git-write-tree) || exit 1
96069cf0 42commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) || exit 1
7f1d1129
LT
43echo $commit > $GIT_DIR/HEAD
44rm -f -- $GIT_DIR/MERGE_HEAD