]> git.ipfire.org Git - thirdparty/git.git/blobdiff - t/test-lib-functions.sh
Merge branch 'js/update-urls-in-doc-and-comment' into maint-2.43
[thirdparty/git.git] / t / test-lib-functions.sh
index 0b7ddcc585881f619a18f897fff63f5655f9db61..03292602fb0f9e3109baf19798b49c9521fae4f1 100644 (file)
@@ -251,6 +251,61 @@ debug () {
        done
 }
 
+# Usage: test_ref_exists [options] <ref>
+#
+#   -C <dir>:
+#      Run all git commands in directory <dir>
+#
+# This helper function checks whether a reference exists. Symrefs or object IDs
+# will not be resolved. Can be used to check references with bad names.
+test_ref_exists () {
+       local indir=
+
+       while test $# != 0
+       do
+               case "$1" in
+               -C)
+                       indir="$2"
+                       shift
+                       ;;
+               *)
+                       break
+                       ;;
+               esac
+               shift
+       done &&
+
+       indir=${indir:+"$indir"/} &&
+
+       if test "$#" != 1
+       then
+               BUG "expected exactly one reference"
+       fi &&
+
+       git ${indir:+ -C "$indir"} show-ref --exists "$1"
+}
+
+# Behaves the same as test_ref_exists, except that it checks for the absence of
+# a reference. This is preferable to `! test_ref_exists` as this function is
+# able to distinguish actually-missing references from other, generic errors.
+test_ref_missing () {
+       test_ref_exists "$@"
+       case "$?" in
+       2)
+               # This is the good case.
+               return 0
+               ;;
+       0)
+               echo >&4 "test_ref_missing: reference exists"
+               return 1
+               ;;
+       *)
+               echo >&4 "test_ref_missing: generic error"
+               return 1
+               ;;
+       esac
+}
+
 # Usage: test_commit [options] <message> [<file> [<contents> [<tag>]]]
 #   -C <dir>:
 #      Run all git commands in directory <dir>
@@ -1208,14 +1263,16 @@ test_cmp_bin () {
        cmp "$@"
 }
 
-# Wrapper for grep which used to be used for
-# GIT_TEST_GETTEXT_POISON=false. Only here as a shim for other
-# in-flight changes. Should not be used and will be removed soon.
+# Deprecated - do not use this in new code
 test_i18ngrep () {
+       test_grep "$@"
+}
+
+test_grep () {
        eval "last_arg=\${$#}"
 
        test -f "$last_arg" ||
-       BUG "test_i18ngrep requires a file to read as the last parameter"
+       BUG "test_grep requires a file to read as the last parameter"
 
        if test $# -lt 2 ||
           { test "x!" = "x$1" && test $# -lt 3 ; }