fi
}
+function display_error_message() {
+ echo "----------------------------------------------------" >&2
+ echo "" >&2
+ echo "" >&2
+ for ((i=1;i<=$#;i+=1)); do
+ eval message="$"$i
+ echo "$message" >&2
+ done
+ echo "" >&2
+ echo "" >&2
+ echo "----------------------------------------------------" >&2
+}
# in it.
#
+. $(dirname $0)/functions
+
# Command line
refname="$1"
oldrev="$2"
count=${#follows[@]}
for ((i = 0 ; i < count ; i++)) do
follow="${follows[$i]}"
- git rev-parse "$follow"
+ git rev-parse --verify --quiet "$follow"
if [ $? -eq 0 ] ; then
missing_commits=$(git log ^$newrev $follow --pretty=oneline | wc -l)
if [ $missing_commits -ne 0 ] ; then
- echo "----------------------------------------------------"
- echo
- echo "You need to merge $follow into $short_refname"
- echo
- echo "----------------------------------------------------"
+ display_error_message "You need to merge $follow into $short_refname"
exit 1
fi
fi
# Tags should only be allowed to point to commits that are within a branch.
#
+. $(dirname $0)/functions
+
refname="$1"
oldrev="$2"
newrev="$3"
contains=$(git branch --contains "$newrev" | wc -l)
if [ $contains -eq 0 ] ; then
- echo "----------------------------------------------------"
- echo
- echo "The tag $short_refname is not included in any branch."
- echo
- echo "----------------------------------------------------"
+ display_error_message "The tag $short_refname is not included in any branch."
exit 1
fi
#!/bin/sh
+. $(dirname $0)/functions
+
# Command line
refname="$1"
oldrev="$2"
;;
esac
-
excused=" $(git config hooks.update-ensure-ticket-reference.excused) "
if [[ $excused =~ " $short_refname " ]] ; then
exit 0
# Have log dump the "subject line, new line, body" of each commit message for grepping
git log -n 1 '--pretty=format:%s%n%b' "$commit" | grep -i '\(\(re\|refs\|qa\) #[0-9]\+\)\|\(no ticket\)' > /dev/null
if [ $? -ne 0 ] ; then
- echo "----------------------------------------------------" >&2
- echo "" >&2
- echo "Commit $commit does not reference a ticket" >&2
- echo "" >&2
- echo "----------------------------------------------------" >&2
+ display_error_message "Commit $commit does not reference a ticket"
exit 1
fi
done
# \
# c -- d <-- topic
+. $(dirname $0)/functions
+
refname="$1"
oldrev="$2"
newrev="$3"
all_commits=$(git rev-list --first-parent $baserev..$parent | wc -l)
new_commits=$(git rev-parse --not --branches | git rev-list --stdin $baserev..$parent | wc -l)
if [ $all_commits -eq $new_commits ] ; then
- # echo "parent=$parent"
- # echo "all_commits=$all_commits"
- # echo "new_commits=$new_commits"
- echo "----------------------------------------------------"
- echo
- echo "It looks like you should rebase instead of merging $commit"
- echo
- echo "----------------------------------------------------"
+ # echo "parent=$parent" # echo "all_commits=$all_commits" # echo "new_commits=$new_commits"
+ display_error_message "It looks like you should rebase instead of merging $commit"
exit 1
fi
done
# that ratetables could still sneak when, but we'll give
# people the benefit of the doubt.
+. $(dirname $0)/functions
+
# Command line
refname="$1"
oldrev="$2"
if expr "$oldrev" : '0*$' >/dev/null ; then
if expr "$refname" : '.*[A-Z].*' ; then
- echo "----------------------------------------------------"
- echo
- echo "Please prefer underscored branch names (e.g. rate_tables)"
- echo "instead of camel-casing branch names (e.g. rateTables)."
- echo
- echo "----------------------------------------------------"
+ display_error_message "Please use underscored branch names (e.g. rate_tables)"
exit 1
fi
fi
# would not have appeared in QA.
#
+. $(dirname $0)/functions
+
refname="$1"
oldrev="$2"
newrev="$3"
-. $(dirname $0)/functions
-set_change_type
-
case "$refname" in
refs/heads/*)
short_refname=${refname##refs/heads/}
;;
esac
+set_change_type
if [ "$change_type" == "delete" ] ; then
exit 0
fi
if [ "$change_type" == "create" -a "$short_refname" != "stable" ] ; then
not_on_stable=$(git rev-list stable..$newrev)
if [ "$not_on_stable" == "" ] ; then
- echo "----------------------------------------------------"
- echo
- echo "Creating a branch must include new commits"
- echo
- echo "----------------------------------------------------"
+ display_error_message "Creating a branch must include new commits"
exit 1
fi
fi
# = all new commits on stable
count=$(git rev-parse --not --branches | git rev-list --stdin $oldrev..$newrev | wc -l)
if [ "$count" -ne "1" ] ; then
- echo "----------------------------------------------------"
- echo
- echo "Moving stable must entail a single commit"
- echo
- echo "----------------------------------------------------"
+ display_error_message "Moving stable must entail a single commit"
exit 1
fi
number_of_parents=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | wc -l)
if [ "$number_of_parents" -ne "2" ] ; then
- echo "----------------------------------------------------"
- echo
- echo "Moving stable must entail a merge commit"
- echo
- echo "----------------------------------------------------"
+ display_error_message "Moving stable must entail a merge commit"
exit 1
fi
first_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | head --lines=1)
if [ "$first_parent" != "$oldrev" ] ; then
- echo "----------------------------------------------------"
- echo
- echo "Moving stable must have the previous stable as the first parent"
- echo
- echo "----------------------------------------------------"
+ display_error_message "Moving stable must have the previous stable as the first parent"
exit 1
fi
second_parent=$(git rev-list --no-walk --parents $newrev | sed 's/ /\n/g' | grep -v $newrev | tail --lines=1)
changed_lines=$(git diff $second_parent..$newrev | wc -l)
if [ "$changed_lines" -ne "0" ] ; then
- echo "----------------------------------------------------"
- echo
- echo "Moving stable must not result in any changes from $second_parent"
- echo
- echo "----------------------------------------------------"
+ display_error_message "Moving stable must not result in any changes from $second_parent"
exit 1
fi
else
# Check if candidate/topic is already in stable
git branch --contains "$oldrev" | grep stable >/dev/null
if [ $? -eq 0 ] ; then
- echo "----------------------------------------------------"
- echo
- echo "$short_refname has been merged into stable"
- echo
- echo "----------------------------------------------------"
+ display_error_message "$short_refname has been merged into stable"
exit 1
fi
# Check if topic is already in candidates
candidate=$(git branch --contains "$oldrev" | grep -oP "candidate.*" --max-count=1)
if [ $? -eq 0 ] ; then
- echo "----------------------------------------------------"
- echo
- echo "$short_refname has been merged into $candidate"
- echo
- echo "----------------------------------------------------"
+ display_error_message "$short_refname has been merged into $candidate"
exit 1
fi
fi
'
# setup the update hook
-install_server_hook 'update-ensure-ticket-reference' 'update'
+install_update_hook 'update-ensure-ticket-reference'
test_expect_success 'reject with bad message' '
echo $test_name >a &&
git commit -a -m "$test_name" &&
head=$(git rev-parse HEAD) &&
- ! git push >push.out 2>push.err &&
+ ! git push 2>push.err &&
cat push.err | grep "Commit $head does not reference a ticket"
'
echo "$test_name third" >a &&
git commit -a -m "$test_name third re #3222" &&
- ! git push >push.out 2>push.err &&
+ ! git push 2>push.err &&
cat push.err | grep "Commit $head does not reference a ticket"
'
'
# setup the hook
-install_server_hook 'update-ensure-ticket-reference' 'update'
+install_update_hook 'update-ensure-ticket-reference'
test_expect_success 'accept merge with merge message' '
git checkout -b topic1 master &&
echo "$test_name" >a &&
git commit -a -m "$test_name on topicTopic" &&
! git push origin topicTopic 2>push.err &&
- cat push.err | grep "Please prefer underscored branch names"
+ cat push.err | grep "Please use underscored branch names"
'
test_done