Let "git commit" take arguments for files to commit.
[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
07954953 7git-update-cache -q --refresh -- "$@" || exit 1
96069cf0
LT
8PARENTS="-p HEAD"
9if [ ! -r $GIT_DIR/HEAD ]; then
10 if [ -z "$(git-ls-files)" ]; then
11 echo Nothing to commit 1>&2
12 exit 1
13 fi
14 (
15 echo "#"
16 echo "# Initial commit"
17 echo "#"
18 git-ls-files | sed 's/^/# New file: /'
19 echo "#"
20 ) > .editmsg
21 PARENTS=""
22else
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
33fi
a3e870f2
LT
34if [ "$?" != "0" ]
35then
36 cat .editmsg
170241b7 37 rm .editmsg
a3e870f2
LT
38 exit 1
39fi
2036d841 40${VISUAL:-${EDITOR:-vi}} .editmsg
a3e870f2 41grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
170241b7
LT
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
47ret="$?"
48rm -f .cmitmsg .editmsg
49exit "$ret"