Merge with master to pick up commit hook works.

This commit is contained in:
Junio C Hamano 2005-08-20 01:47:08 -07:00
commit b0e985d5de
10 changed files with 227 additions and 80 deletions

View File

@ -6,10 +6,10 @@
. git-sh-setup-script || die "Not a git archive"
usage () {
die 'git commit [-a] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
die 'git commit [-a] [-v | --no-verify] [-m <message>] [-F <logfile>] [(-C|-c) <commit>] [<path>...]'
}
all= logfile= use_commit= no_edit= log_given= log_message= verify= signoff=
all= logfile= use_commit= no_edit= log_given= log_message= verify=t signoff=
while case "$#" in 0) break;; esac
do
case "$1" in
@ -67,6 +67,9 @@ do
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
signoff=t
shift ;;
-n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|--no-verify)
verify=
shift ;;
-v|--v|--ve|--ver|--veri|--verif|--verify)
verify=t
shift ;;
@ -101,56 +104,10 @@ git-update-cache -q --refresh || exit 1
case "$verify" in
t)
# This is slightly modified from Andrew Morton's Perfect Patch.
# Lines you introduce should not have trailing whitespace.
# Also check for an indentation that has SP before a TAB.
perl -e '
my $fh;
my $found_bad = 0;
my $filename;
my $reported_filename = "";
my $lineno;
sub bad_line {
my ($why, $line) = @_;
if (!$found_bad) {
print "*\n";
print "* You have some suspicious patch lines:\n";
print "*\n";
$found_bad = 1;
}
if ($reported_filename ne $filename) {
print "* In $filename\n";
$reported_filename = $filename;
}
print "* $why (line $lineno)\n$line\n";
}
open $fh, "-|", qw(git-diff-cache -p -M --cached HEAD);
while (<$fh>) {
if (m|^diff --git a/(.*) b/\1$|) {
$filename = $1;
next;
}
if (/^@@ -\S+ \+(\d+)/) {
$lineno = $1 - 1;
next;
}
if (/^ /) {
$lineno++;
next;
}
if (s/^\+//) {
$lineno++;
chomp;
if (/\s$/) {
bad_line("trailing whitespace", $_);
}
if (/^\s* /) {
bad_line("indent SP followed by a TAB", $_);
}
}
}
exit($found_bad);
' || exit ;;
if test -x "$GIT_DIR"/hooks/pre-commit
then
"$GIT_DIR"/hooks/pre-commit || exit
fi
esac
PARENTS="-p HEAD"
@ -255,6 +212,15 @@ case "$no_edit" in
${VISUAL:-${EDITOR:-vi}} .editmsg
;;
esac
case "$verify" in
t)
if test -x "$GIT_DIR"/hooks/commit-msg
then
"$GIT_DIR"/hooks/commit-msg .editmsg || exit
fi
esac
grep -v '^#' < .editmsg | git-stripspace > .cmitmsg
grep -v -i '^Signed-off-by' .cmitmsg >.cmitchk
if test -s .cmitchk
@ -269,4 +235,9 @@ else
fi
ret="$?"
rm -f .cmitmsg .editmsg .cmitchk
if test -x "$GIT_DIR"/hooks/post-commit && test "$ret" = 0
then
"$GIT_DIR"/hooks/post-commit
fi
exit "$ret"

View File

@ -3,10 +3,11 @@
. git-sh-setup-script || die "Not a git archive"
dryrun=
echo=
while case "$#" in 0) break ;; esac
do
case "$1" in
-n) dryrun=echo ;;
-n) dryrun=-n echo=echo ;;
--) break ;;
-*) echo >&2 "usage: git-prune-script [ -n ] [ heads... ]"; exit 1 ;;
*) break ;;
@ -20,6 +21,7 @@ sed -ne '/unreachable /{
s|\(..\)|\1/|p
}' | {
cd "$GIT_OBJECT_DIRECTORY" || exit
xargs $dryrun rm -f
xargs $echo rm -f
}
git-prune-packed $dryrun

View File

@ -6,21 +6,25 @@
#
. git-sh-setup-script || die "Not a git archive"
head=$(git-rev-parse --verify "$1"^0) || exit
merge=$(git-rev-parse --verify "$2"^0) || exit
merge_msg="$3"
usage () {
die "git-resolve-script <head> <remote> <merge-message>"
}
dropheads() {
rm -f -- "$GIT_DIR/MERGE_HEAD" \
"$GIT_DIR/LAST_MERGE" || exit 1
}
head=$(git-rev-parse --verify "$1"^0) &&
merge=$(git-rev-parse --verify "$2"^0) &&
merge_msg="$3" || usage
#
# The remote name is just used for the message,
# but we do want it.
#
if [ -z "$head" -o -z "$merge" -o -z "$merge_msg" ]; then
die "git-resolve-script <head> <remote> <merge-message>"
usage
fi
dropheads

View File

@ -1,6 +1,9 @@
#include "cache.h"
static const char prune_packed_usage[] = "git-prune-packed (no arguments)";
static const char prune_packed_usage[] =
"git-prune-packed [-n]";
static int dryrun;
static void prune_dir(int i, DIR *dir, char *pathname, int len)
{
@ -18,7 +21,9 @@ static void prune_dir(int i, DIR *dir, char *pathname, int len)
if (!has_sha1_pack(sha1))
continue;
memcpy(pathname + len, de->d_name, 38);
if (unlink(pathname) < 0)
if (dryrun)
printf("rm -f %s\n", pathname);
else if (unlink(pathname) < 0)
error("unable to unlink %s", pathname);
}
}
@ -55,8 +60,11 @@ int main(int argc, char **argv)
const char *arg = argv[i];
if (*arg == '-') {
/* Handle flags here .. */
usage(prune_packed_usage);
if (!strcmp(arg, "-n"))
dryrun = 1;
else
usage(prune_packed_usage);
continue;
}
/* Handle arguments here .. */
usage(prune_packed_usage);

View File

@ -0,0 +1,14 @@
#!/bin/sh
#
# An example hook script to check the commit log message taken by
# applypatch from an e-mail message.
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit. The hook is
# allowed to edit the commit message file.
#
# To enable this hook, make this file executable.
test -x "$GIT_DIR/hooks/commit-msg" &&
exec "$GIT_DIR/hooks/commit-msg" ${1+"$@"}
:

View File

@ -0,0 +1,14 @@
#!/bin/sh
#
# An example hook script to check the commit log message.
# Called by git-commit-script with one argument, the name of the file
# that has the commit message. The hook should exit with non-zero
# status after issuing an appropriate message if it wants to stop the
# commit. The hook is allowed to edit the commit message file.
#
# To enable this hook, make this file executable.
# This example catches duplicate Signed-off-by lines.
test "" = "$(grep '^Signed-off-by: ' "$1" |
sort | uniq -c | sed -e '/^[ ]*1 /d')"

View File

@ -0,0 +1,8 @@
#!/bin/sh
#
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, make this file executable.
: Nothing

View File

@ -0,0 +1,14 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed
# by applypatch from an e-mail message.
#
# The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit.
#
# To enable this hook, make this file executable.
test -x "$GIT_DIR/hooks/pre-commit" &&
exec "$GIT_DIR/hooks/pre-commit" ${1+"$@"}
:

View File

@ -0,0 +1,61 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by git-commit-script with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, make this file executable.
# This is slightly modified from Andrew Morton's Perfect Patch.
# Lines you introduce should not have trailing whitespace.
# Also check for an indentation that has SP before a TAB.
perl -e '
my $fh;
my $found_bad = 0;
my $filename;
my $reported_filename = "";
my $lineno;
sub bad_line {
my ($why, $line) = @_;
if (!$found_bad) {
print "*\n";
print "* You have some suspicious patch lines:\n";
print "*\n";
$found_bad = 1;
}
if ($reported_filename ne $filename) {
print "* In $filename\n";
$reported_filename = $filename;
}
print "* $why (line $lineno)\n";
print "$filename:$lineno:$line\n";
}
open $fh, "-|", qw(git-diff-cache -p -M --cached HEAD);
while (<$fh>) {
if (m|^diff --git a/(.*) b/\1$|) {
$filename = $1;
next;
}
if (/^@@ -\S+ \+(\d+)/) {
$lineno = $1 - 1;
next;
}
if (/^ /) {
$lineno++;
next;
}
if (s/^\+//) {
$lineno++;
chomp;
if (/\s$/) {
bad_line("trailing whitespace", $_);
}
if (/^\s* /) {
bad_line("indent SP followed by a TAB", $_);
}
}
}
exit($found_bad);
'

View File

@ -10,58 +10,109 @@
## $3 - "info" file with Author, email and subject
## $4 - optional file containing signoff to add
##
signoff="$4"
. git-sh-setup-script || die "Not a git archive."
final=.dotest/final-commit
##
## If this file exists, we ask before applying
##
query_apply=.dotest/.query_apply
## We do not munge the first line of the commit message too much
## if this file exists.
keep_subject=.dotest/.keep_subject
MSGFILE=$1
PATCHFILE=$2
INFO=$3
EDIT=${VISUAL:-$EDITOR}
EDIT=${EDIT:-vi}
SIGNOFF=$4
EDIT=${VISUAL:-${EDITOR:-vi}}
export GIT_AUTHOR_NAME="$(sed -n '/^Author/ s/Author: //p' .dotest/info)"
export GIT_AUTHOR_EMAIL="$(sed -n '/^Email/ s/Email: //p' .dotest/info)"
export GIT_AUTHOR_DATE="$(sed -n '/^Date/ s/Date: //p' .dotest/info)"
export SUBJECT="$(sed -n '/^Subject/ s/Subject: //p' .dotest/info)"
if [ -n "$signoff" -a -f "$signoff" ]; then
cat $signoff >> $MSGFILE
if test '' != "$SIGNOFF"
then
if test -f "$SIGNOFF"
then
SIGNOFF=`cat "$SIGNOFF"` || exit
elif case "$SIGNOFF" in yes | true | me | please) : ;; *) false ;; esac
then
SIGNOFF=`git-var GIT_COMMITTER_IDENT | sed -e '
s/>.*/>/
s/^/Signed-off-by: /'
`
else
SIGNOFF=
fi
if test '' != "$SIGNOFF"
then
LAST_SIGNED_OFF_BY=`
sed -ne '/^Signed-off-by: /p' "$MSGFILE" |
tail -n 1
`
test "$LAST_SIGNED_OFF_BY" = "$SIGNOFF" ||
echo "$SIGNOFF" >>"$MSGFILE"
fi
fi
patch_header=
test -f "$keep_subject" || patch_header='[PATCH] '
(echo "$patch_header$SUBJECT" ; if [ -s $MSGFILE ]; then echo ; cat $MSGFILE; fi ) > $final
{
echo "$patch_header$SUBJECT"
if test -s "$MSGFILE"
then
echo
cat "$MSGFILE"
fi
} >"$final"
f=0
[ -f $query_apply ] || f=1
interactive=yes
test -f "$query_apply" || interactive=no
while [ $f -eq 0 ]; do
while [ "$interactive" = yes ]; do
echo "Commit Body is:"
echo "--------------------------"
cat $final
cat "$final"
echo "--------------------------"
echo -n "Apply? [y]es/[n]o/[e]dit/[a]ccept all "
read reply
case $reply in
y|Y) f=1;;
case "$reply" in
y|Y) interactive=no;;
n|N) exit 2;; # special value to tell dotest to keep going
e|E) $EDIT $final;;
a|A) rm -f $query_apply
f=1;;
e|E) "$EDIT" "$final";;
a|A) rm -f "$query_apply"
interactive=no ;;
esac
done
if test -x "$GIT_DIR"/hooks/applypatch-msg
then
"$GIT_DIR"/hooks/applypatch-msg "$final" || exit
fi
echo
echo Applying "'$SUBJECT'"
echo
git-apply --index $PATCHFILE || exit 1
git-apply --index "$PATCHFILE" || exit 1
if test -x "$GIT_DIR"/hooks/pre-applypatch
then
"$GIT_DIR"/hooks/pre-applypatch || exit
fi
tree=$(git-write-tree) || exit 1
echo Wrote tree $tree
commit=$(git-commit-tree $tree -p $(cat .git/HEAD) < $final) || exit 1
commit=$(git-commit-tree $tree -p $(cat "$GIT_DIR"/HEAD) < "$final") || exit 1
echo Committed: $commit
echo $commit > .git/HEAD
echo $commit > "$GIT_DIR"/HEAD
if test -x "$GIT_DIR"/hooks/post-applypatch
then
"$GIT_DIR"/hooks/post-applypatch
fi