Fourth batch
[gitweb.git] / t / lib-t6000.sh
index 102d5678151d5b1fcca731724efb2bd1ad0647d6..b0ed4767e320e200c592e979dce0fa1e4cfd6ede 100644 (file)
@@ -4,11 +4,11 @@ mkdir -p .git/refs/tags
 
 >sed.script
 
-# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags
+# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
 tag () {
        _tag=$1
-       test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist"
-       cat ".git/refs/tags/$_tag"
+       git rev-parse --verify "refs/tags/$_tag" ||
+       error "tag: \"$_tag\" does not exist"
 }
 
 # Generate a commit using the text specified to make it unique and the tree
@@ -34,7 +34,7 @@ save_tag () {
        mv sed.script.tmp sed.script
 }
 
-# Replace unhelpful sha1 hashses with their symbolic equivalents
+# Replace unhelpful sha1 hashes with their symbolic equivalents
 entag () {
        sed -f sed.script
 }
@@ -64,13 +64,30 @@ commit_date () {
        sed -n "s/^committer .*> \([0-9]*\) .*/\1/p"
 }
 
+# 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
+}
+
 on_committer_date () {
-       _date=$1
-       shift 1
-       GIT_COMMITTER_DATE="$_date"
+       assign_fake_date GIT_COMMITTER_DATE "$1"
        export GIT_COMMITTER_DATE
+       shift 1
+       "$@"
+}
+
+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
        "$@"
-       unset GIT_COMMITTER_DATE
 }
 
 # Execute a command and suppress any error output.