# test -L usage

3 messages from 2010-09-22 to 2010-09-22. Participants: Bruce Momjian, Jeff King.
Thread: https://gitlist.dev/t/25191

## Bruce Momjian, 2010-09-22 00:11

Subject: test -L usage
Message-ID: <201009220011.o8M0BFO26150@momjian.us>
URL: https://gitlist.dev/e/201009220011.o8M0BFO26150%40momjian.us

```
git-1.7.3/contrib/workdir/git-new-workdir uses 'test -L' to test for
symlinks.  I suggest using 'test -h' because it is more portable, and
would have avoided a problem on my BSD machine.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

```

## Jeff King, 2010-09-22 00:35

Subject: Re: test -L usage
Message-ID: <20100922003559.GB23931@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20100922003559.GB23931%40sigill.intra.peff.net
In-Reply-To: <201009220011.o8M0BFO26150@momjian.us>

```
On Tue, Sep 21, 2010 at 08:11:15PM -0400, Bruce Momjian wrote:

> git-1.7.3/contrib/workdir/git-new-workdir uses 'test -L' to test for
> symlinks.  I suggest using 'test -h' because it is more portable, and
> would have avoided a problem on my BSD machine.

Yeah, we generally do, but the stuff in contrib/ doesn't get exercised
as much. There are also a few occurences in the svn tests. All cleaned
up with the patch below.

-->8--
Subject: [PATCH] prefer test -h over test -L in shell scripts

Even though "-L" is POSIX, the former is more portable, and
we tend to prefer it already.

Signed-off-by: Jeff King <peff@peff.net>
---
 contrib/workdir/git-new-workdir  |    2 +-
 t/t9100-git-svn-basic.sh         |    6 +++---
 t/t9131-git-svn-empty-symlink.sh |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
index 3ad2c0c..75e8b25 100755
--- a/contrib/workdir/git-new-workdir
+++ b/contrib/workdir/git-new-workdir
@@ -42,7 +42,7 @@ then
 fi
 
 # don't link to a workdir
-if test -L "$git_dir/config"
+if test -h "$git_dir/config"
 then
 	die "\"$orig_git\" is a working directory only, please specify" \
 		"a complete repository."
diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh
index 2f458f7..b041516 100755
--- a/t/t9100-git-svn-basic.sh
+++ b/t/t9100-git-svn-basic.sh
@@ -143,7 +143,7 @@ test_expect_success "$name" '
 	git svn set-tree --find-copies-harder --rmdir \
 		${remotes_git_svn}..mybranch5 &&
 	svn_cmd up "$SVN_TREE" &&
-	test -L "$SVN_TREE"/exec.sh'
+	test -h "$SVN_TREE"/exec.sh'
 
 name='new symlink is added to a file that was also just made executable'
 
@@ -156,7 +156,7 @@ test_expect_success "$name" '
 		${remotes_git_svn}..mybranch5 &&
 	svn_cmd up "$SVN_TREE" &&
 	test -x "$SVN_TREE"/bar/zzz &&
-	test -L "$SVN_TREE"/exec-2.sh'
+	test -h "$SVN_TREE"/exec-2.sh'
 
 name='modify a symlink to become a file'
 test_expect_success "$name" '
@@ -169,7 +169,7 @@ test_expect_success "$name" '
 		${remotes_git_svn}..mybranch5 &&
 	svn_cmd up "$SVN_TREE" &&
 	test -f "$SVN_TREE"/exec-2.sh &&
-	test ! -L "$SVN_TREE"/exec-2.sh &&
+	test ! -h "$SVN_TREE"/exec-2.sh &&
 	test_cmp help "$SVN_TREE"/exec-2.sh'
 
 name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL"
diff --git a/t/t9131-git-svn-empty-symlink.sh b/t/t9131-git-svn-empty-symlink.sh
index 9a24a65..f762038 100755
--- a/t/t9131-git-svn-empty-symlink.sh
+++ b/t/t9131-git-svn-empty-symlink.sh
@@ -88,7 +88,7 @@ test_expect_success 'enable broken symlink workaround' \
 test_expect_success '"bar" is an empty file' 'test -f x/bar && ! test -s x/bar'
 test_expect_success 'get "bar" => symlink fix from svn' \
 		'(cd x && git svn rebase)'
-test_expect_success SYMLINKS '"bar" becomes a symlink' 'test -L x/bar'
+test_expect_success SYMLINKS '"bar" becomes a symlink' 'test -h x/bar'
 
 
 test_expect_success 'clone using git svn' 'git svn clone -r1 "$svnrepo" y'
-- 
1.7.3.256.gb9713

```

## Bruce Momjian, 2010-09-22 00:37

Subject: Re: test -L usage
Message-ID: <201009220037.o8M0bUT29845@momjian.us>
URL: https://gitlist.dev/e/201009220037.o8M0bUT29845%40momjian.us
In-Reply-To: <20100922003559.GB23931@sigill.intra.peff.net>

```
Jeff King wrote:
> On Tue, Sep 21, 2010 at 08:11:15PM -0400, Bruce Momjian wrote:
> 
> > git-1.7.3/contrib/workdir/git-new-workdir uses 'test -L' to test for
> > symlinks.  I suggest using 'test -h' because it is more portable, and
> > would have avoided a problem on my BSD machine.
> 
> Yeah, we generally do, but the stuff in contrib/ doesn't get exercised
> as much. There are also a few occurences in the svn tests. All cleaned
> up with the patch below.

Thanks.

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

```
