[PATCH] fetch/pull: short-hand notation for remote repositories.
[git] / git-commit-script
1 #!/bin/sh
2 #
3 # Copyright (c) 2005 Linus Torvalds
4 #
5
6 . git-sh-setup-script || die "Not a git archive"
7
8 usage () {
9         die 'git commit [-m existing-commit] [<path>...]'
10 }
11
12 while case "$#" in 0) break ;; esac
13 do
14     case "$1" in
15     -m) shift
16         case "$#" in
17         0) usage ;;
18         *) use_commit=`git-rev-parse "$1"` ||
19            exit ;;
20         esac
21         ;;
22     *)  break
23         ;;
24     esac
25     shift
26 done
27
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
34         fi
35         (
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 /{
56                         h
57                         s/^author \([^<]*\) <[^>]*> .*$/\1/
58                         s/'\''/'\''\'\'\''/g
59                         s/.*/GIT_AUTHOR_NAME='\''&'\''/p
60
61                         g
62                         s/^author [^<]* <\([^>]*\)> .*$/\1/
63                         s/'\''/'\''\'\'\''/g
64                         s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
65
66                         g
67                         s/^author [^<]* <[^>]*> \(.*\)$/\1/
68                         s/'\''/'\''\'\'\''/g
69                         s/.*/GIT_AUTHOR_DATE='\''&'\''/p
70
71                         q
72                 }
73                 '
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
84 fi
85 if [ "$?" != "0" ]
86 then
87         cat .editmsg
88         rm .editmsg
89         exit 1
90 fi
91 case "$use_commit" in
92 '')
93         ${VISUAL:-${EDITOR:-vi}} .editmsg
94         ;;
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"