[PATCH 04/11] tests: introduce test_ln_s and test_ln_s_add

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add new functions that create symbolic links and add them to the index to
be used in cases where a symbolic link is not required on the file system.
We will use them to remove many SYMLINKS prerequisites from test cases.

Signed-off-by: Johannes Sixt <j6t@xxxxxxxx>
---
 t/README                | 17 +++++++++++++++++
 t/test-lib-functions.sh | 30 ++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/t/README b/t/README
index e669bb3..bb938f2 100644
--- a/t/README
+++ b/t/README
@@ -592,6 +592,23 @@ library for your script to use.
 		test_cmp expected actual
 	'
 
+ - test_ln_s <path1> <path2>
+   test_ln_s_add <path1> <path2>
+
+   These functions help systems whose filesystem does not support symbolic
+   links. Use them to add a symbolic link entry to the index when it is
+   not important that the file system entry is a symbolic link.
+
+   Use test_ln_s instead of plain "ln -s foo bar" and test_ln_s_add 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
 -------------
 
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 5251009..ad7905a 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -679,3 +679,33 @@ test_create_repo () {
 		mv .git/hooks .git/hooks-disabled
 	) || exit
 }
+
+# These functions help 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.
+#
+# - Use test_ln_s instead of "ln -s x y" when y has been added as a
+#   symbolic link entry earlier.
+
+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
+}
+
+test_ln_s () {
+	if test_have_prereq SYMLINKS
+	then
+		ln -s "$1" "$2"
+	else
+		printf '%s' "$1" >"$2"
+	fi
+}
-- 
1.8.3.rc1.32.g8b61cbb

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]