[PATCH] Documentation: update recommended workflow when working with others.
[git/gitweb.git] / git-commit-script
blobc6f8ee2b3df1a93bcf9b167b5fc5d3ee30381fd8
1 #!/bin/sh
3 # Copyright (c) 2005 Linus Torvalds
6 . git-sh-setup-script || die "Not a git archive"
8 usage () {
9 die 'git commit [-m existing-commit] [<path>...]'
12 while case "$#" in 0) break ;; esac
14 case "$1" in
15 -m) shift
16 case "$#" in
17 0) usage ;;
18 *) use_commit=`git-rev-parse "$1"` ||
19 exit ;;
20 esac
22 *) break
24 esac
25 shift
26 done
28 git-update-cache -q --refresh -- "$@" || exit 1
29 PARENTS="-p HEAD"
30 if [ ! -r "$GIT_DIR/HEAD" ]; then
31 if [ -z "$(git-ls-files)" ]; then
32 echo Nothing to commit 1>&2
33 exit 1
36 echo "#"
37 echo "# Initial commit"
38 echo "#"
39 git-ls-files | sed 's/^/# New file: /'
40 echo "#"
41 ) > .editmsg
42 PARENTS=""
43 else
44 if [ -f "$GIT_DIR/MERGE_HEAD" ]; then
45 echo "#"
46 echo "# It looks like your may be committing a MERGE."
47 echo "# If this is not correct, please remove the file"
48 echo "# $GIT_DIR/MERGE_HEAD"
49 echo "# and try again"
50 echo "#"
51 PARENTS="-p HEAD -p MERGE_HEAD"
52 elif test "$use_commit" != ""
53 then
54 pick_author_script='
55 /^author /{
57 s/^author \([^<]*\) <[^>]*> .*$/\1/
58 s/'\''/'\''\'\'\''/g
59 s/.*/GIT_AUTHOR_NAME='\''&'\''/p
62 s/^author [^<]* <\([^>]*\)> .*$/\1/
63 s/'\''/'\''\'\'\''/g
64 s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
67 s/^author [^<]* <[^>]*> \(.*\)$/\1/
68 s/'\''/'\''\'\'\''/g
69 s/.*/GIT_AUTHOR_DATE='\''&'\''/p
74 set_author_env=`git-cat-file commit "$use_commit" |
75 sed -ne "$pick_author_script"`
76 eval "$set_author_env"
77 export GIT_AUTHOR_NAME
78 export GIT_AUTHOR_EMAIL
79 export GIT_AUTHOR_DATE
80 git-cat-file commit "$use_commit" |
81 sed -e '1,/^$/d'
82 fi >.editmsg
83 git-status-script >>.editmsg
85 if [ "$?" != "0" ]
86 then
87 cat .editmsg
88 rm .editmsg
89 exit 1
91 case "$use_commit" in
92 '')
93 ${VISUAL:-${EDITOR:-vi}} .editmsg
95 esac
96 grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
97 [ -s .cmitmsg ] &&
98 tree=$(git-write-tree) &&
99 commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) &&
100 echo $commit > "$GIT_DIR/HEAD" &&
101 rm -f -- "$GIT_DIR/MERGE_HEAD"
102 ret="$?"
103 rm -f .cmitmsg .editmsg
104 exit "$ret"