From 3c3f6f219dec60908d242401738f5a060248a5c7 Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Sun, 15 Oct 2023 16:21:01 +0200 Subject: [PATCH] implement pre push hooks for checking for duplicate tilesets in maps --- .githooks/git-hooks-config.bat | 7 +++++++ .githooks/git-hooks-config.sh | 7 +++++++ .githooks/pre-push | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 .githooks/git-hooks-config.bat create mode 100644 .githooks/git-hooks-config.sh create mode 100755 .githooks/pre-push diff --git a/.githooks/git-hooks-config.bat b/.githooks/git-hooks-config.bat new file mode 100644 index 000000000..de890732f --- /dev/null +++ b/.githooks/git-hooks-config.bat @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# This script will config git hook path into specific folder in your project. This script will invoked by maven build. +# @author : Mak Sophea +# @version : 1.0# +# +echo "config git hooksPath to .githooks folder for commit-msg and pre-push" +git config core.hooksPath .githooks \ No newline at end of file diff --git a/.githooks/git-hooks-config.sh b/.githooks/git-hooks-config.sh new file mode 100644 index 000000000..de890732f --- /dev/null +++ b/.githooks/git-hooks-config.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# This script will config git hook path into specific folder in your project. This script will invoked by maven build. +# @author : Mak Sophea +# @version : 1.0# +# +echo "config git hooksPath to .githooks folder for commit-msg and pre-push" +git config core.hooksPath .githooks \ No newline at end of file diff --git a/.githooks/pre-push b/.githooks/pre-push new file mode 100755 index 000000000..2159f0939 --- /dev/null +++ b/.githooks/pre-push @@ -0,0 +1,34 @@ +#!/usr/bin/env bash +# +# @author: OMGeeky +# @created: 2023-10-15 +# @description: A script to check if a tileset is duplicated in a Tiled map. + +echo "Checking for duplicate tilesets..." + +# The folder to scan +folder="AndorsTrail/res/xml/*.tmx" +# The regex pattern to look for +regex='(?s)(map_\w*").*\1' +found=0 +# Iterate over the files in the folder +for file in $folder; do + # If the file matches the regex pattern, print a warning and exit with a nonzero status +# echo "Checking file $file" + if grep -Pzq "$regex" "$file"; then + echo "Warning: File $file contains the regex pattern!" + found=$((found + 1)) + # Print each location where the pattern is found + grep -Pzao '(?s)(map_\w*").*\1' "$file" | awk -F "\"" '{print $1; exit}' + echo "" + fi +done +if [ $found -gt 0 ]; then + echo "Duplicate tilesets found in $found files." + exit 1 +else + echo "No duplicate tilesets found." +fi + +# If no files matched the regex pattern, exit with a zero status +exit 0 \ No newline at end of file