Skip to content

Commit 9ce415d

Browse files
j6tgitster
authored andcommitted
tests: introduce test_ln_s_add
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb64868 commit 9ce415d

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

t/README

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,20 @@ library for your script to use.
592592
test_cmp expected actual
593593
'
594594

595+
- test_ln_s_add <path1> <path2>
596+
597+
This function helps systems whose filesystem does not support symbolic
598+
links. Use it to add a symbolic link entry to the index when it is not
599+
important that the file system entry is a symbolic link, i.e., instead
600+
of the sequence
601+
602+
ln -s foo bar &&
603+
git add bar
604+
605+
Sometimes it is possible to split a test in a part that does not need
606+
the symbolic link in the file system and a part that does; then only
607+
the latter part need be protected by a SYMLINKS prerequisite (see below).
608+
595609
Prerequisites
596610
-------------
597611

t/test-lib-functions.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,3 +679,20 @@ test_create_repo () {
679679
mv .git/hooks .git/hooks-disabled
680680
) || exit
681681
}
682+
683+
# This function helps on symlink challenged file systems when it is not
684+
# important that the file system entry is a symbolic link.
685+
# Use test_ln_s_add instead of "ln -s x y && git add y" to add a
686+
# symbolic link entry y to the index.
687+
688+
test_ln_s_add () {
689+
if test_have_prereq SYMLINKS
690+
then
691+
ln -s "$1" "$2" &&
692+
git update-index --add "$2"
693+
else
694+
printf '%s' "$1" >"$2" &&
695+
ln_s_obj=$(git hash-object -w "$2") &&
696+
git update-index --add --cacheinfo 120000 $ln_s_obj "$2"
697+
fi
698+
}

0 commit comments

Comments
 (0)