2010-01-31 00:59:09 +01:00
|
|
|
: included from 6002 and others
|
|
|
|
|
2013-06-21 19:12:48 +02:00
|
|
|
>sed.script
|
2005-07-06 12:11:24 +02:00
|
|
|
|
2018-05-23 07:25:17 +02:00
|
|
|
# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
|
2013-06-21 19:12:48 +02:00
|
|
|
tag () {
|
2005-07-06 12:11:24 +02:00
|
|
|
_tag=$1
|
2018-05-23 07:25:17 +02:00
|
|
|
git rev-parse --verify "refs/tags/$_tag" ||
|
|
|
|
error "tag: \"$_tag\" does not exist"
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate a commit using the text specified to make it unique and the tree
|
|
|
|
# named by the tag specified.
|
2013-06-21 19:12:48 +02:00
|
|
|
unique_commit () {
|
2005-07-06 12:11:24 +02:00
|
|
|
_text=$1
|
2013-06-21 19:12:48 +02:00
|
|
|
_tree=$2
|
2005-07-06 12:11:24 +02:00
|
|
|
shift 2
|
2013-06-21 19:12:48 +02:00
|
|
|
echo "$_text" | git commit-tree $(tag "$_tree") "$@"
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Save the output of a command into the tag specified. Prepend
|
2005-07-07 02:50:07 +02:00
|
|
|
# a substitution script for the tag onto the front of sed.script
|
2013-06-21 19:12:48 +02:00
|
|
|
save_tag () {
|
2007-06-07 09:04:01 +02:00
|
|
|
_tag=$1
|
2013-06-21 19:12:48 +02:00
|
|
|
test -n "$_tag" || error "usage: save_tag tag commit-args ..."
|
2005-07-06 12:11:24 +02:00
|
|
|
shift 1
|
2020-06-30 14:05:35 +02:00
|
|
|
|
|
|
|
git update-ref "refs/tags/$_tag" $("$@")
|
2005-07-06 12:11:29 +02:00
|
|
|
|
2013-06-21 19:12:48 +02:00
|
|
|
echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
|
|
|
|
cat sed.script >>sed.script.tmp
|
2005-07-07 02:50:07 +02:00
|
|
|
rm sed.script
|
|
|
|
mv sed.script.tmp sed.script
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
2013-07-29 10:18:21 +02:00
|
|
|
# Replace unhelpful sha1 hashes with their symbolic equivalents
|
2013-06-21 19:12:48 +02:00
|
|
|
entag () {
|
2005-07-07 02:50:07 +02:00
|
|
|
sed -f sed.script
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL
|
|
|
|
# tag to a specified value. Restore the original value on return.
|
2013-06-21 19:12:48 +02:00
|
|
|
as_author () {
|
2005-07-06 12:11:24 +02:00
|
|
|
_author=$1
|
|
|
|
shift 1
|
2013-06-21 19:12:48 +02:00
|
|
|
_save=$GIT_AUTHOR_EMAIL
|
2005-07-06 12:11:24 +02:00
|
|
|
|
2008-05-04 07:37:58 +02:00
|
|
|
GIT_AUTHOR_EMAIL="$_author"
|
|
|
|
export GIT_AUTHOR_EMAIL
|
2005-07-06 12:11:24 +02:00
|
|
|
"$@"
|
2006-02-08 00:35:46 +01:00
|
|
|
if test -z "$_save"
|
|
|
|
then
|
|
|
|
unset GIT_AUTHOR_EMAIL
|
|
|
|
else
|
2008-05-04 07:37:58 +02:00
|
|
|
GIT_AUTHOR_EMAIL="$_save"
|
|
|
|
export GIT_AUTHOR_EMAIL
|
2006-02-08 00:35:46 +01:00
|
|
|
fi
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 19:12:48 +02:00
|
|
|
commit_date () {
|
|
|
|
_commit=$1
|
|
|
|
git cat-file commit $_commit |
|
|
|
|
sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
2013-06-21 19:29:59 +02:00
|
|
|
# Assign the value of fake date to a variable, but
|
|
|
|
# allow fairly common "1971-08-16 00:00" to be omittd
|
|
|
|
assign_fake_date () {
|
|
|
|
case "$2" in
|
|
|
|
??:??:??) eval "$1='1971-08-16 $2'" ;;
|
|
|
|
??:??) eval "$1='1971-08-16 00:$2'" ;;
|
|
|
|
??) eval "$1='1971-08-16 00:00:$2'" ;;
|
|
|
|
*) eval "$1='$2'" ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2013-06-21 19:12:48 +02:00
|
|
|
on_committer_date () {
|
2013-06-21 19:29:59 +02:00
|
|
|
assign_fake_date GIT_COMMITTER_DATE "$1"
|
2013-06-21 19:12:48 +02:00
|
|
|
export GIT_COMMITTER_DATE
|
2013-06-21 19:29:59 +02:00
|
|
|
shift 1
|
2013-06-21 19:12:48 +02:00
|
|
|
"$@"
|
2013-06-21 20:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
on_dates () {
|
|
|
|
assign_fake_date GIT_COMMITTER_DATE "$1"
|
|
|
|
assign_fake_date GIT_AUTHOR_DATE "$2"
|
|
|
|
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
|
|
|
|
shift 2
|
|
|
|
"$@"
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Execute a command and suppress any error output.
|
2013-06-21 19:12:48 +02:00
|
|
|
hide_error () {
|
2005-07-06 12:11:24 +02:00
|
|
|
"$@" 2>/dev/null
|
|
|
|
}
|
|
|
|
|
2013-06-21 19:12:48 +02:00
|
|
|
check_output () {
|
2005-07-06 12:11:24 +02:00
|
|
|
_name=$1
|
|
|
|
shift 1
|
2013-06-21 19:12:48 +02:00
|
|
|
if eval "$*" | entag >"$_name.actual"
|
2005-07-06 12:11:24 +02:00
|
|
|
then
|
2013-06-21 19:12:48 +02:00
|
|
|
test_cmp "$_name.expected" "$_name.actual"
|
2005-07-06 12:11:24 +02:00
|
|
|
else
|
2013-06-21 19:12:48 +02:00
|
|
|
return 1
|
2005-07-06 12:11:24 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Turn a reasonable test description into a reasonable test name.
|
|
|
|
# All alphanums translated into -'s which are then compressed and stripped
|
|
|
|
# from front and back.
|
2013-06-21 19:12:48 +02:00
|
|
|
name_from_description () {
|
2008-03-15 01:32:33 +01:00
|
|
|
perl -pe '
|
|
|
|
s/[^A-Za-z0-9.]/-/g;
|
|
|
|
s/-+/-/g;
|
|
|
|
s/-$//;
|
|
|
|
s/^-//;
|
|
|
|
y/A-Z/a-z/;
|
|
|
|
'
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Execute the test described by the first argument, by eval'ing
|
|
|
|
# command line specified in the 2nd argument. Check the status code
|
2007-06-07 09:04:01 +02:00
|
|
|
# is zero and that the output matches the stream read from
|
2005-07-06 12:11:24 +02:00
|
|
|
# stdin.
|
|
|
|
test_output_expect_success()
|
2007-06-07 09:04:01 +02:00
|
|
|
{
|
2005-07-06 12:11:24 +02:00
|
|
|
_description=$1
|
2013-06-21 19:12:48 +02:00
|
|
|
_test=$2
|
|
|
|
test $# -eq 2 ||
|
|
|
|
error "usage: test_output_expect_success description test <<EOF ... EOF"
|
|
|
|
|
|
|
|
_name=$(echo $_description | name_from_description)
|
|
|
|
cat >"$_name.expected"
|
2007-06-07 09:04:01 +02:00
|
|
|
test_expect_success "$_description" "check_output $_name \"$_test\""
|
2005-07-06 12:11:24 +02:00
|
|
|
}
|