Skip to content

Commit 09ccc49

Browse files
Updated pre-push hook to be a bit smarter about cloning
1 parent c59344f commit 09ccc49

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

.githooks/pre-push

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
#!/bin/sh
2-
root_dir=$(git rev-parse --show-toplevel)
3-
tempdir=$(mktemp -d)
4-
cd $tempdir
5-
git clone $root_dir . --quiet
2+
3+
cleanup() {
4+
if [ -n "$project_location" ] && [ "$project_location" != "$original_project_location" ]; then
5+
echo "Cleaning up copy under $project_location"
6+
rm -rf $project_location
7+
fi
8+
cd $original_dir
9+
}
10+
11+
project_location=$(git rev-parse --show-toplevel)
12+
original_project_location=$project_location
13+
original_dir=$(pwd)
14+
15+
if [ -n "$(git status --porcelain)" ]; then
16+
trap cleanup EXIT
17+
project_location=$(mktemp -d)
18+
echo "Uncommitted changes in project. Creating a temporary copy at $project_location"
19+
git clone $original_project_location $project_location --quiet
20+
fi
21+
22+
cd $project_location
23+
624
Rscript -e "devtools::test(stop_on_failure=TRUE)"

0 commit comments

Comments
 (0)