1 m4_define([_m4_divert(SCRIPT)], 100)
2 m4_divert_push([SCRIPT])#!/bin/sh
5 # clcommit (GNU @PACKAGE@) version 2.0
6 # Written by Gary V. Vaughan <gary@gnu.org>
7 # and Alexandre Oliva <aoliva@redhat.com>
9 # Copyright (C) 1999, 2000, 2004, 2006, 2008 Free Software Foundation, Inc.
10 # This is free software; see the source for copying conditions. There is NO
11 # warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 # Clcommit is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
18 # Clcommit is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with clcommit; see the file COPYING. If not, a copy
25 # can be downloaded from http://www.gnu.org/licenses/gpl.html,
26 # or obtained by writing to the Free Software Foundation, Inc.,
27 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 # Usage: $progname [OPTION]... [--] [filepattern ...]
31 # -a AUTHOR --author=AUTHOR override changeset author name with AUTHOR
32 # -C FILE --changelog=FILE extract commit message from specified FILE
33 # --debug enable verbose shell tracing
34 # -n --dry-run don't commit anything
35 # --fast same as --force --first
36 # -F file --file=FILE read commit message from FILE
37 # -1 --first extract first entry from ChangeLog, no git diff
38 # -f --force don't check (unless *followed* by -n), and just
39 # display commit message instead of running $PAGER
40 # --from=ADDRESS override default from ADDRESS in commit email
41 # -m msg --message=STRING set commit message to STRING
42 # --msg=STRING same as -m
43 # -p --push push the changes back to origin
44 # -r [FILE] --rcfile[=FILE] read default option from FILE [./.clcommitrc]
45 # -s addr --sendmail=ADDRESS send commit email of the differences to ADDRESS
46 # --signature[=FILE] add FILE to the end of the email [~/.signature]
47 # --signoff add a Signed-off-by attribution at the end
48 # -S TEXT --summary=TEXT specify a TEXT subject line for the commit email
49 # -v --verbose run in verbose mode
50 # --version print version information
51 # -h,-? --help print short or long help message
53 # This script eases checking in changes to git-maintained projects
54 # with ChangeLog files. It will check that there have been no
55 # conflicting commits in the CVS repository and print which files it
56 # is going to commit to stderr. A list of files to compare and to
57 # check in can be given in the command line. If it is not given, all
58 # files in the current working directory are considered for check in.
60 # The commit message will be extracted from the differences between a
61 # file named ChangeLog* in the commit list, or named after -C, and the
62 # one in the repository (unless a message was specified with `-m' or
63 # `-F'). An empty message is not accepted (but a blank line is). If
64 # the message is acceptable, it will be presented for verification
65 # (and possible edition) using the $PAGER environment variable (or
66 # `more', if it is not set, or `cat', if the `-f' switch is given).
67 # If $PAGER exits successfully, the modified files (at that moment)
68 # are checked in, unless `-n' was specified, in which case nothing is
71 # Report bugs to <gary@gnu.org>
74 : ${MAILNOTIFY="mailnotify"}
75 : ${MKSTAMP="mkstamp"}
77 test -f "libltdl/config/$MAILNOTIFY" && MAILNOTIFY="libltdl/config/$MAILNOTIFY"
78 test -f "libltdl/config/$MKSTAMP" && MKSTAMP="libltdl/config/$MKSTAMP"
85 m4_include([getopt.m4sh])
101 # try to find out whether read supports -r
102 if echo bt | tr b '\\' | { read -r line; test "X$line" = 'X\t'; } 2>/dev/null
109 # Locations for important files:
111 log_dir="`func_mktempdir`"
112 log_file="$log_dir/log"
114 trap '$RM -r "$log_dir"; exit $EXIT_FAILURE' 1 2 15
118 # Parse options once, thoroughly. This comes as soon as possible in
119 # the script to make things like `clcommit --version' happen quickly.
122 my_sed_single_opt='1s/^\(..\).*$/\1/;q'
123 my_sed_single_rest='1s/^..\(.*\)$/\1/;q'
124 my_sed_long_opt='1s/^\(--[^=]*\)=.*/\1/;q'
125 my_sed_long_arg='1s/^--[^=]*=//'
127 # this just eases exit handling
128 while test $# -gt 0; do
133 --author|-a) test $# = 0 && func_missing_arg $opt && break
134 func_quote_for_eval "$1"
135 git_flags="$git_flags --author=$func_quote_for_eval_result"
139 --[cC]hange[lL]og|-C)
140 test $# = 0 && func_missing_arg $opt && break
141 if test -f "$1"; then :; else
142 func_error "ChangeLog file \`$1' does not exist"
149 --debug) func_echo "enabling shell trace mode"
150 mailnotify_flags="$mailnotify_flags --debug"
154 --dry-run|-n) opt_commit=false; opt_update=: ;;
156 --fast) set dummy --force --first ${1+"$@"}; shift ;;
158 --file|-F) test $# = 0 && func_missing_arg $opt && break
159 if $opt_first || test -f "$log_file"; then
160 func_error "you can have at most one of -m, -F and -1"
163 if cat < "$1" > "$log_file"; then :; else
169 --first|-1) if test -f "$log_File"; then
170 func_error "you can have at most one of -m, -F and -1"
176 --force|-f) opt_update=false; PAGER=cat ;;
178 --from) test $# = 0 && func_missing_arg $opt && break
179 func_quote_for_eval "$1"
180 mailnotify_flags="$mailnotify_flags --from=$func_quote_for_eval_result"
185 test $# = 0 && func_missing_arg $opt && break
186 if $opt_first || test -f "$log_file"; then
187 func_error "you can have at most one of -m, -F and -1"
190 echo "$1" > "$log_file"
194 --push|-p) opt_push=: ;;
196 --rcfile|-r) rc_file="./.clcommitrc"
197 if test $# -gt 0; then
200 *) rc_file="$1"; shift ;;
203 if test -f "$rc_file"; then :; else
204 func_error "rcfile \`$rc_file' does not exist"
208 # The funny quoting allows keeping one option per
210 eval set dummy `echo \`cat $rc_file\` \${1+"\$@"}`
214 --sendmail|-s) test $# = 0 && func_missing_arg $opt && break
215 func_quote_for_eval "$1"
216 sendmail_to="$func_quote_for_eval_result"
220 --signature) test $# = 0 && func_missing_arg $opt && break
221 signature_file="$HOME/.signature"
224 *) signature_file="$1"; shift ;;
226 if test -f "$signature_file"; then :; else
227 func_error "\`$signature_file': file not found"
232 --signoff) git_flags="$git_flags --signoff" ;;
234 --summary|-S) test $# = 0 && func_missing_arg $opt && break
239 --verbose|-v) opt_verbose=: ;;
241 # Separate optargs to long options:
243 arg=`echo "$opt" | $SED "$my_sed_long_arg"`
244 opt=`echo "$opt" | $SED "$my_sed_long_opt"`
245 set dummy "$opt" "$arg" ${1+"$@"}
249 # Separate optargs to short options:
250 -a*|-m*|-F*|-C*|-S*|-s*)
251 arg=`echo "$opt" |$SED "$my_sed_single_rest"`
252 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
253 set dummy "$opt" "$arg" ${1+"$@"}
257 # Separate non-argument short options:
259 rest=`echo "$opt" |$SED "$my_sed_single_rest"`
260 opt=`echo "$opt" |$SED "$my_sed_single_opt"`
261 set dummy "$opt" "-$rest" ${1+"$@"}
265 -\?|-h) func_usage ;;
267 --version) func_version ;;
269 -*) func_fatal_help "unrecognized option \`$opt'" ;;
270 *) set dummy "$opt" ${1+"$@"}; shift; break ;;
274 if test -z "$sendmail_to"; then
276 # can't have a from address without a destination address
277 test -n "$sendmail_from" &&
278 func_error "can't use --from without --sendmail." && exit_cmd=exit
280 # can't use a signature file without a destination address
281 test -n "$signature_file" &&
282 func_error "can't use --signature without --sendmail." && exit_cmd=exit
285 # Bail if the options were screwed
286 $exit_cmd $EXIT_FAILURE
289 # func_check_conflicts
290 func_check_conflicts ()
292 # HELP?!? How to check for git push conflicts?
294 func_fatal_error "some conflicts were found with CVS repository, aborting..."
299 # func_check_commit_msg
300 func_check_commit_msg ()
302 if test -z "$ChangeLog"; then
303 for f in ${1+"$@"}; do
305 ChangeLog* | */ChangeLog*)
306 if test -z "$ChangeLog"; then
309 func_fatal_error "multiple ChangeLog files: $ChangeLog and $f"
316 func_verbose "$progname: checking commit message..."
319 $SED 's,^,+,' < ${ChangeLog-ChangeLog} |
320 while $read_r line; do
322 "+") if $skipping; then skipping=false; else break; fi;;
324 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
325 echo "$line" | $SED 's/^.//' >&2;;
327 $skipping || echo "$line" ;;
330 $SED 's,^\+ ,,' > "$log_file" || exit $EXIT_FAILURE
332 $GIT diff ${ChangeLog-ChangeLog} |
333 while $read_r line; do
337 func_error "*** Warning: the following line in ChangeLog diff is suspicious:"
338 echo "$line" | $SED 's/^.//' >&2;;
340 func_error "*** Warning: lines should start with tabs, not spaces; ignoring line:"
341 echo "$line" | $SED 's/^.//' >&2;;
343 "+ "*) echo "$line";;
346 $SED -e 's,\+ ,,' -e '/./p' -e '/./d' -e '1d' -e '$d' > "$log_file" \
347 || exit $EXIT_FAILURE
349 # The sed script above removes "+TAB" from the beginning of a line, then
350 # deletes the first and/or the last line, when they happen to be empty
357 ${PAGER-more} "$log_file" || exit $EXIT_FAILURE
359 sleep 1 # give the user some time for a ^C
361 subject=`git status 2>/dev/null | $SED -n 's/^#.*[mad][ode][dl].*ed: *//p'`
362 test $# -gt 0 && subject="$@"
364 test $# -gt 0 || { set dummy -a; shift; }
365 func_verbose "$GIT commit$git_flags -F $log_file ${1+$@}"
366 $GIT commit$git_flags -F $log_file ${1+"$@"} || exit $EXIT_FAILURE
368 $opt_push && $GIT push
377 notify_file="${log_dir}/notify"
378 func_verbose "Mailing commit notification to $sendmail_to"
381 echo Subject: $subject
382 test -f .git/config &&
383 echo "Root: `$SED -n 's,^ url = .*:\(.*\)$,\1,p' .git/config`"
385 echo "Timestamp: `$SHELL $MKSTAMP .`"
386 echo "Branch: `$GIT branch | sed -n 's/\* //p'`"
387 test -f .git/config &&
388 echo "Changes by: `$SED -n 's,^ url = \([^:]*\):.*$,\1,p' .git/config`"
391 $SED -e 's,^, ,' "$log_file"
392 test -f "$signature_file" && {
394 cat "$signature_file"
398 ${PAGER-more} "$notify_file" || break
400 # Break out the subject line again
401 my_mail_subject=`$SED -e '
406 my_mail_body=`$SED -e '2,$p;d' "$notify_file"`
407 echo "$my_mail_body" > "$notify_file"
409 func_verbose "mailing commit notification to \"$sendmail_to\""
410 func_quote_for_eval "$my_mail_subject"
411 func_show_eval "$MAILNOTIFY $mailnotify_flags \
412 -s $func_quote_for_eval_result -m 'text/plain' -f '$notify_file' \
423 $opt_update && func_check_conflicts
425 test -f "$log_file" || func_check_commit_msg
427 grep '[^ ]' < "$log_file" > /dev/null ||
428 func_fatal_error "empty commit message, aborting"
430 if grep '^$' < "$log_file" > /dev/null; then
431 func_error "*** Warning: blank lines should not appear within commit messages."
432 func_error "*** They should be used to separate distinct commits."
435 # Do not check for empty $log_file again, even though the user might have
436 # zeroed it out. If s/he did, it was probably intentional.
438 func_commit ${1+"$@"}
441 subject=`sed -n '1p' "$log_file"`
443 # Send a copy of the log_file if sendmail_to was set:
444 if test -n "$sendmail_to"; then
446 func_warning "Mail notification NOT sent for commit to local repository."