Initial commit
[hgct.git] / citool-commit
blob63cae04223e0dcd28153063443737e64948e965a
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 usage () {
7 echo 'citool-commit [<path>...] < commit-message'
8 exit 1
11 : ${GIT_DIR=.git}
12 if [ ! -d "$GIT_DIR" ]; then
13 echo Not a git directory 1>&2
14 exit 1
17 git-update-cache -q --refresh -- "$@" || exit 1
18 PARENTS="-p HEAD"
19 if [ ! -r "$GIT_DIR/HEAD" ]; then
20 if [ -z "$(git-ls-files)" ]; then
21 echo Nothing to commit 1>&2
22 exit 1
24 PARENTS=""
25 else
26 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
27 echo "#"
28 echo "# It looks like your may be committing a MERGE."
29 echo "# If this is not correct, please remove the file"
30 echo "# $GIT_DIR/MERGE_HEAD"
31 echo "# and try again"
32 echo "#"
33 PARENTS="-p HEAD -p MERGE_HEAD"
34 fi >.editmsg
35 git-status-script >>.editmsg
37 if [ "$?" != "0" ]
38 then
39 cat .editmsg
40 rm .editmsg
41 exit 1
43 cat >> .editmsg
44 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
45 [ -s .cmitmsg ] &&
46 tree=$(git-write-tree) &&
47 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
48 echo $commit > "$GIT_DIR/HEAD" &&
49 rm -f -- "$GIT_DIR/MERGE_HEAD"
50 ret="$?"
51 rm -f .cmitmsg .editmsg
52 exit "$ret"