]>
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 () { |
eca35ecd | 9 | die 'git commit [--all] [-m existing-commit] [<path>...]' |
5fec3ef1 JH |
10 | } |
11 | ||
f0b32737 | 12 | files=() |
5fec3ef1 JH |
13 | while case "$#" in 0) break ;; esac |
14 | do | |
15 | case "$1" in | |
16 | -m) shift | |
17 | case "$#" in | |
18 | 0) usage ;; | |
f6e1a4d6 | 19 | *) use_commit=`git-rev-parse --verify "$1"` || |
5fec3ef1 JH |
20 | exit ;; |
21 | esac | |
22 | ;; | |
f0b32737 LT |
23 | --all) |
24 | files=($(git-diff-files --name-only))\ | |
25 | ;; | |
5fec3ef1 JH |
26 | *) break |
27 | ;; | |
28 | esac | |
29 | shift | |
30 | done | |
31 | ||
f0b32737 | 32 | git-update-cache -q --refresh -- "$@" "${files[@]}" || exit 1 |
96069cf0 | 33 | PARENTS="-p HEAD" |
5fec3ef1 | 34 | if [ ! -r "$GIT_DIR/HEAD" ]; then |
96069cf0 LT |
35 | if [ -z "$(git-ls-files)" ]; then |
36 | echo Nothing to commit 1>&2 | |
37 | exit 1 | |
38 | fi | |
39 | ( | |
40 | echo "#" | |
41 | echo "# Initial commit" | |
42 | echo "#" | |
43 | git-ls-files | sed 's/^/# New file: /' | |
44 | echo "#" | |
45 | ) > .editmsg | |
46 | PARENTS="" | |
47 | else | |
5fec3ef1 | 48 | if [ -f "$GIT_DIR/MERGE_HEAD" ]; then |
96069cf0 LT |
49 | echo "#" |
50 | echo "# It looks like your may be committing a MERGE." | |
51 | echo "# If this is not correct, please remove the file" | |
52 | echo "# $GIT_DIR/MERGE_HEAD" | |
53 | echo "# and try again" | |
54 | echo "#" | |
55 | PARENTS="-p HEAD -p MERGE_HEAD" | |
5fec3ef1 JH |
56 | elif test "$use_commit" != "" |
57 | then | |
58 | pick_author_script=' | |
59 | /^author /{ | |
60 | h | |
61 | s/^author \([^<]*\) <[^>]*> .*$/\1/ | |
62 | s/'\''/'\''\'\'\''/g | |
63 | s/.*/GIT_AUTHOR_NAME='\''&'\''/p | |
64 | ||
65 | g | |
66 | s/^author [^<]* <\([^>]*\)> .*$/\1/ | |
67 | s/'\''/'\''\'\'\''/g | |
68 | s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p | |
69 | ||
70 | g | |
71 | s/^author [^<]* <[^>]*> \(.*\)$/\1/ | |
72 | s/'\''/'\''\'\'\''/g | |
73 | s/.*/GIT_AUTHOR_DATE='\''&'\''/p | |
74 | ||
75 | q | |
76 | } | |
77 | ' | |
78 | set_author_env=`git-cat-file commit "$use_commit" | | |
79 | sed -ne "$pick_author_script"` | |
80 | eval "$set_author_env" | |
81 | export GIT_AUTHOR_NAME | |
82 | export GIT_AUTHOR_EMAIL | |
83 | export GIT_AUTHOR_DATE | |
84 | git-cat-file commit "$use_commit" | | |
85 | sed -e '1,/^$/d' | |
86 | fi >.editmsg | |
87 | git-status-script >>.editmsg | |
96069cf0 | 88 | fi |
eca35ecd | 89 | if [ "$?" != "0" -a ! -f $GIT_DIR/MERGE_HEAD ] |
a3e870f2 LT |
90 | then |
91 | cat .editmsg | |
170241b7 | 92 | rm .editmsg |
a3e870f2 LT |
93 | exit 1 |
94 | fi | |
5fec3ef1 JH |
95 | case "$use_commit" in |
96 | '') | |
97 | ${VISUAL:-${EDITOR:-vi}} .editmsg | |
98 | ;; | |
99 | esac | |
a3e870f2 | 100 | grep -v '^#' < .editmsg | git-stripspace > .cmitmsg |
170241b7 LT |
101 | [ -s .cmitmsg ] && |
102 | tree=$(git-write-tree) && | |
103 | commit=$(cat .cmitmsg | git-commit-tree $tree $PARENTS) && | |
5fec3ef1 JH |
104 | echo $commit > "$GIT_DIR/HEAD" && |
105 | rm -f -- "$GIT_DIR/MERGE_HEAD" | |
170241b7 LT |
106 | ret="$?" |
107 | rm -f .cmitmsg .editmsg | |
108 | exit "$ret" |