Skip to content

Commit d532224

Browse files
committed
Fix readlink errors & more properly CD to the project root.
Signed-off-by: Nick Semenkovich <semenko@alum.mit.edu>
1 parent 7627c76 commit d532224

File tree

4 files changed

+39
-20
lines changed

4 files changed

+39
-20
lines changed

test.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33

44
# Get into the project-root. This script may be executed as `test.sh`
55
# or as .git/hooks/pre-push, so we need to find the directory containing
6-
# test.sh before we can proceed. If $0 is not a symlink, `readlink` will
7-
# print nothing; if it is a symlink it will print the link target.
6+
# test.sh before we can proceed.
87

9-
cd $(dirname $0)/$(dirname $(readlink $0))
8+
if [ -n "$GIT_DIR" ]
9+
then
10+
# $GIT_DIR is set, so we're running as a hook.
11+
cd $GIT_DIR
12+
else
13+
# Git command exists? Cool, let's CD to the right place.
14+
git rev-parse && cd "$(git rev-parse --show-toplevel)"
15+
fi
1016

1117
./test/rules.sh
1218
./test/firefox.sh $@

test/chromium.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
#!/bin/bash
1+
#!/bin/bash -ex
22
# Run Chromium tests for HTTPS Everywhere
3-
#
4-
# Get into the project-root. This script may be executed as `chromium.sh`
5-
# or as ./test/chromium.sh, so we need to find the directory
6-
# containing firefox.sh before we can proceed. If $0 is not a symlink,
7-
# `readlink` will print nothing; if it is a symlink it will print the
8-
# link target.
93

10-
set -o errexit -o xtrace
4+
# Get to the repo root directory, even when we're symlinked as a hook.
5+
if [ -n "$GIT_DIR" ]
6+
then
7+
# $GIT_DIR is set, so we're running as a hook.
8+
cd $GIT_DIR
9+
else
10+
# Git command exists? Cool, let's CD to the right place.
11+
git rev-parse && cd "$(git rev-parse --show-toplevel)"
12+
fi
1113

12-
cd $(dirname $0)/$(dirname $(readlink $0))../
1314

1415
# If you just want to run Chromium with the latest code:
1516
if [ "$1" == "--justrun" ]; then

test/firefox.sh

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#!/bin/bash -ex
22
# Run Firefox tests for HTTPS Everywhere
3-
#
4-
# Get into the project-root. This script may be executed as `firefox.sh`
5-
# or as ./test/firefox.sh, so we need to find the directory containing
6-
# firefox.sh before we can proceed. If $0 is not a symlink, `readlink`
7-
# will print nothing; if it is a symlink it will print the link target.
83

9-
cd $(dirname $0)/$(dirname $(readlink $0))../
4+
# Get to the repo root directory, even when we're symlinked as a hook.
5+
if [ -n "$GIT_DIR" ]
6+
then
7+
# $GIT_DIR is set, so we're running as a hook.
8+
cd $GIT_DIR
9+
else
10+
# Git command exists? Cool, let's CD to the right place.
11+
git rev-parse && cd "$(git rev-parse --show-toplevel)"
12+
fi
13+
1014

1115
source utils/mktemp.sh
1216

test/rules.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
#!/bin/bash
1+
#!/bin/bash -ex
22
#
33
# Test that all rulesets modified after a certain date have sufficient test
44
# coverage, according to the ruleset checker.
55
#
66

7-
cd $(dirname $0)/$(dirname $(readlink $0))../
7+
# Get to the repo root directory, even when we're symlinked as a hook.
8+
if [ -n "$GIT_DIR" ]
9+
then
10+
# $GIT_DIR is set, so we're running as a hook.
11+
cd $GIT_DIR
12+
else
13+
# Git command exists? Cool, let's CD to the right place.
14+
git rev-parse && cd "$(git rev-parse --show-toplevel)"
15+
fi
816

917
source utils/mktemp.sh
1018

0 commit comments

Comments
 (0)