From a6fcdec0f8157fb65e52712255295ebe78c455af Mon Sep 17 00:00:00 2001
From: Riku Isokoski <riksu9000@gmail.com>
Date: Tue, 10 May 2022 22:29:20 +0300
Subject: [PATCH] Don't allow test-format.sh to be run locally

---
 .github/workflows/format.yml |  2 +-
 tests/test-format.sh         | 10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml
index 97ab11e4..8962d9d0 100644
--- a/.github/workflows/format.yml
+++ b/.github/workflows/format.yml
@@ -24,7 +24,7 @@ jobs:
           sudo apt-get -y install clang-format-12
 
       - name: Check formatting
-        run: tests/test-format.sh "$GITHUB_BASE_REF"
+        run: tests/test-format.sh
 
       - name: Upload patches
         uses: actions/upload-artifact@v3
diff --git a/tests/test-format.sh b/tests/test-format.sh
index 7196e260..1dd9cdbd 100755
--- a/tests/test-format.sh
+++ b/tests/test-format.sh
@@ -2,11 +2,13 @@
 
 set -e
 
-[ -z "$1" ] && exit
+if [ -z "$GITHUB_BASE_REF" ]
+then
+  echo "This script is only meant to be run in a GitHub Workflow"
+  exit 1
+fi
 
-basebranch=$1
-
-CHANGED_FILES=$(git diff --name-only "$basebranch"...HEAD)
+CHANGED_FILES=$(git diff --name-only "$GITHUB_BASE_REF"...HEAD)
 
 CHANGED=0