]>
Commit | Line | Data |
---|---|---|
a3e870f2 | 1 | #!/bin/sh |
5fec3ef1 JH |
2 | # |
3 | # Copyright (c) 2005 Linus Torvalds | |
4 | # | |
5 | ||
b33e9666 LT |
6 | . git-sh-setup-script || die "Not a git archive" |
7 | ||
5fec3ef1 | 8 | usage () { |
b33e9666 | 9 | die 'git commit [-m existing-commit] [<path>...]' |
5fec3ef1 JH |
10 | } |
11 | ||
5fec3ef1 JH |
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 | ||
07954953 | 28 | git-update-cache -q --refresh -- "$@" || exit 1 |
96069cf0 | 29 | PARENTS="-p HEAD" |
5fec3ef1 | 30 | if [ ! -r "$GIT_DIR/HEAD" ]; then |
96069cf0 LT |
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 | |
5fec3ef1 | 44 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
96069cf0 LT |
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" | |
5fec3ef1 JH |
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 | |
96069cf0 | 84 | fi |
a3e870f2 LT |
85 | if [ "$?" != "0" ] |
86 | then | |
87 | cat .editmsg | |
170241b7 | 88 | rm .editmsg |
a3e870f2 LT |
89 | exit 1 |
90 | fi | |
5fec3ef1 JH |
91 | case "$use_commit" in |
92 | '') | |
93 | ${VISUAL:-${EDITOR:-vi}} .editmsg | |
94 | ;; | |
95 | esac | |
a3e870f2 | 96 | grep -v '^#' < .editmsg | git-stripspace > .cmitmsg |
170241b7 LT |
97 | [ -s .cmitmsg ] && |
98 | tree=$(git-write-tree) && | |
99 | commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) && | |
5fec3ef1 JH |
100 | echo $commit > "$GIT_DIR/HEAD" && |
101 | rm -f -- "$GIT_DIR/MERGE_HEAD" | |
170241b7 LT |
102 | ret="$?" |
103 | rm -f .cmitmsg .editmsg | |
104 | exit "$ret" |