t: use git-show-ref(1) to check for ref existence
Convert tests that use `test_path_is_file` and `test_path_is_missing` to instead use a set of helpers `test_ref_exists` and `test_ref_missing`. These helpers are implemented via the newly introduced `git show-ref --exists` command. Thus, we can avoid intimate knowledge of how the ref backend stores references on disk. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9080a7f178
commit
0497e6c611
@ -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>
|
||||
|
Reference in New Issue
Block a user