tests: introduce test_ln_s_add
authorJohannes Sixt <j6t@kdbg.org>
Fri, 7 Jun 2013 20:53:27 +0000 (22:53 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 Jun 2013 22:01:16 +0000 (15:01 -0700)
Add a new function that creates a symbolic link and adds it to the index
to be used in cases where a symbolic link is not required on the file
system. We will use it to remove many SYMLINKS prerequisites from test
cases.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/README
t/test-lib-functions.sh
index e669bb31b9aa2513a6f71de9fd066a21a0a3bde7..bbe25c31b438b9a4de8b289bc8608e12940e8478 100644 (file)
--- a/t/README
+++ b/t/README
@@ -592,6 +592,20 @@ library for your script to use.
                test_cmp expected actual
        '
 
+ - test_ln_s_add <path1> <path2>
+
+   This function helps systems whose filesystem does not support symbolic
+   links. Use it to add a symbolic link entry to the index when it is not
+   important that the file system entry is a symbolic link, i.e., instead
+   of the sequence
+
+       ln -s foo bar &&
+       git add bar
+
+   Sometimes it is possible to split a test in a part that does not need
+   the symbolic link in the file system and a part that does; then only
+   the latter part need be protected by a SYMLINKS prerequisite (see below).
+
 Prerequisites
 -------------
 
index 52510094add59b508e1581ffebfa555e7249561c..fac9234d3c688ed588da6844163c5d0e712ba3ab 100644 (file)
@@ -679,3 +679,20 @@ test_create_repo () {
                mv .git/hooks .git/hooks-disabled
        ) || exit
 }
+
+# This function helps on symlink challenged file systems when it is not
+# important that the file system entry is a symbolic link.
+# Use test_ln_s_add instead of "ln -s x y && git add y" to add a
+# symbolic link entry y to the index.
+
+test_ln_s_add () {
+       if test_have_prereq SYMLINKS
+       then
+               ln -s "$1" "$2" &&
+               git update-index --add "$2"
+       else
+               printf '%s' "$1" >"$2" &&
+               ln_s_obj=$(git hash-object -w "$2") &&
+               git update-index --add --cacheinfo 120000 $ln_s_obj "$2"
+       fi
+}