From 1831d86a3100ebe2d5bd4e885364e522fa1228cb Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Thu, 18 Jul 2024 11:24:39 +0200 Subject: [PATCH 1/8] Added pre-commit hook checking spotless --- report-viewer/.husky/pre-commit | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/report-viewer/.husky/pre-commit b/report-viewer/.husky/pre-commit index b4eb63f65d..adbea9be11 100644 --- a/report-viewer/.husky/pre-commit +++ b/report-viewer/.husky/pre-commit @@ -1,2 +1,20 @@ cd ./report-viewer -npx lint-staged \ No newline at end of file +npx lint-staged + + +#spotless + +#prevents the shell from aborting if maven returns a non zero exit code +set +e +echo Checking spotless +cd .. +mvn spotless:check &> /dev/null +exitCode=$? + +echo $exitCode + +if [ $exitCode -gt 0 ] +then + echo "Spotless failed. Please run 'mvn spotless:apply' to fix." +fi +exit $exitCode From ebd25059b6de157f4121f742d3860aebbce2635c Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 19 Jul 2024 17:33:53 +0200 Subject: [PATCH 2/8] Moved git hooks out of the report-viewer and removed husky --- gitHooks/hooks/pre-commit | 42 +++++++++++++++++++ gitHooks/installHooks.py | 5 +++ .../scripts/javaPreCommit | 9 +--- gitHooks/scripts/reportViewerPreCommit | 3 ++ report-viewer/package-lock.json | 24 +---------- report-viewer/package.json | 3 +- 6 files changed, 53 insertions(+), 33 deletions(-) create mode 100755 gitHooks/hooks/pre-commit create mode 100755 gitHooks/installHooks.py rename report-viewer/.husky/pre-commit => gitHooks/scripts/javaPreCommit (78%) mode change 100644 => 100755 create mode 100755 gitHooks/scripts/reportViewerPreCommit diff --git a/gitHooks/hooks/pre-commit b/gitHooks/hooks/pre-commit new file mode 100755 index 0000000000..7796838649 --- /dev/null +++ b/gitHooks/hooks/pre-commit @@ -0,0 +1,42 @@ +#!/bin/sh + +echo "Running pre commit checks" + +hasJavaFiles=0 +hasJsFiles=0 + +files=`git diff --name-only --cached` +while read name +do + if [[ $name == report-viewer* ]] + then + hasJsFiles=1 + fi + + if [[ $name == *.java ]] + then + hasJavaFiles=1 + fi +done <<< "$files" + +if [[ $hasJsFiles -gt 0 ]] +then + echo "Running report viewer pre commit checks" + cd report-viewer + ../gitHooks/scripts/reportViewerPreCommit + if [ $? -gt 0 ] + then + exit 1 + fi + cd .. +fi + +if [[ $hasJavaFiles -gt 0 ]] +then + echo "Running java pre commit checks" + gitHooks/scripts/javaPreCommit + if [ $? -gt 0 ] + then + exit 1 + fi +fi diff --git a/gitHooks/installHooks.py b/gitHooks/installHooks.py new file mode 100755 index 0000000000..47ce627c8c --- /dev/null +++ b/gitHooks/installHooks.py @@ -0,0 +1,5 @@ +#!/bin/python + +import subprocess + +subprocess.run(["git", "config", "--local", "core.hooksPath", "gitHooks/hooks"]) \ No newline at end of file diff --git a/report-viewer/.husky/pre-commit b/gitHooks/scripts/javaPreCommit old mode 100644 new mode 100755 similarity index 78% rename from report-viewer/.husky/pre-commit rename to gitHooks/scripts/javaPreCommit index adbea9be11..829fd33e34 --- a/report-viewer/.husky/pre-commit +++ b/gitHooks/scripts/javaPreCommit @@ -1,18 +1,11 @@ -cd ./report-viewer -npx lint-staged - - -#spotless +#!/bin/bash #prevents the shell from aborting if maven returns a non zero exit code set +e echo Checking spotless -cd .. mvn spotless:check &> /dev/null exitCode=$? -echo $exitCode - if [ $exitCode -gt 0 ] then echo "Spotless failed. Please run 'mvn spotless:apply' to fix." diff --git a/gitHooks/scripts/reportViewerPreCommit b/gitHooks/scripts/reportViewerPreCommit new file mode 100755 index 0000000000..8185fec1f5 --- /dev/null +++ b/gitHooks/scripts/reportViewerPreCommit @@ -0,0 +1,3 @@ +#!/bin/bash + +npx lint-staged diff --git a/report-viewer/package-lock.json b/report-viewer/package-lock.json index a4a9ea4962..704100804d 100644 --- a/report-viewer/package-lock.json +++ b/report-viewer/package-lock.json @@ -38,7 +38,6 @@ "autoprefixer": "^10.4.19", "eslint": "^8.57.0", "eslint-plugin-vue": "^9.27.0", - "husky": "^9.0.11", "jsdom": "^24.1.0", "lint-staged": "^15.2.7", "npm-run-all": "^4.1.5", @@ -3499,21 +3498,6 @@ "node": ">=16.17.0" } }, - "node_modules/husky": { - "version": "9.0.11", - "resolved": "https://registry.npmjs.org/husky/-/husky-9.0.11.tgz", - "integrity": "sha512-AB6lFlbwwyIqMdHYhwPe+kjOC3Oc5P3nThEoW/AaO2BX3vJDjWPFxYLxokUZOo6RNX20He3AaT8sESs9NJcmEw==", - "dev": true, - "bin": { - "husky": "bin.mjs" - }, - "engines": { - "node": ">=18" - }, - "funding": { - "url": "https://github.com/sponsors/typicode" - } - }, "node_modules/iconv-lite": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", @@ -6113,12 +6097,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/sortablejs": { - "version": "1.15.2", - "resolved": "https://registry.npmjs.org/sortablejs/-/sortablejs-1.15.2.tgz", - "integrity": "sha512-FJF5jgdfvoKn1MAKSdGs33bIqLi3LmsgVTliuX6iITj834F+JRQZN90Z93yql8h0K2t0RwDPBmxwlbZfDcxNZA==", - "peer": true - }, "node_modules/source-map-js": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", @@ -6712,7 +6690,7 @@ "version": "5.5.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", - "devOptional": true, + "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" diff --git a/report-viewer/package.json b/report-viewer/package.json index 9d47d5b85e..23de5049a6 100644 --- a/report-viewer/package.json +++ b/report-viewer/package.json @@ -16,7 +16,7 @@ "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --max-warnings 0", "format": "prettier --write src/", - "prepare": "cd .. && husky report-viewer/.husky" + "prepare": "cd .. && python gitHooks/installHooks.py" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.6.0", @@ -49,7 +49,6 @@ "autoprefixer": "^10.4.19", "eslint": "^8.57.0", "eslint-plugin-vue": "^9.27.0", - "husky": "^9.0.11", "jsdom": "^24.1.0", "lint-staged": "^15.2.7", "npm-run-all": "^4.1.5", From f61df9ac662abfc0e2cb80f62d52582d7013a8f8 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 26 Jul 2024 13:05:42 +0200 Subject: [PATCH 3/8] Java pre commit hook checks if mvn is installed and install script is available as a shell and bat script. --- gitHooks/installHooks.bat | 1 + gitHooks/installHooks.sh | 3 +++ gitHooks/scripts/javaPreCommit | 5 +++++ report-viewer/package.json | 2 +- 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 gitHooks/installHooks.bat create mode 100755 gitHooks/installHooks.sh diff --git a/gitHooks/installHooks.bat b/gitHooks/installHooks.bat new file mode 100644 index 0000000000..b8b6f79f21 --- /dev/null +++ b/gitHooks/installHooks.bat @@ -0,0 +1 @@ +git config --local core.hooksPath gitHooks/hooks diff --git a/gitHooks/installHooks.sh b/gitHooks/installHooks.sh new file mode 100755 index 0000000000..6db0f1649f --- /dev/null +++ b/gitHooks/installHooks.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +git config --local core.hooksPath gitHooks/hooks diff --git a/gitHooks/scripts/javaPreCommit b/gitHooks/scripts/javaPreCommit index 829fd33e34..e3a3116e63 100755 --- a/gitHooks/scripts/javaPreCommit +++ b/gitHooks/scripts/javaPreCommit @@ -1,5 +1,10 @@ #!/bin/bash +if ! command -v &> /dev/null #checks if maven is installed +then + exit 0 +fi + #prevents the shell from aborting if maven returns a non zero exit code set +e echo Checking spotless diff --git a/report-viewer/package.json b/report-viewer/package.json index 23de5049a6..f2d35ecfba 100644 --- a/report-viewer/package.json +++ b/report-viewer/package.json @@ -16,7 +16,7 @@ "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false", "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --max-warnings 0", "format": "prettier --write src/", - "prepare": "cd .. && python gitHooks/installHooks.py" + "prepare": "git config --local core.hooksPath gitHooks/hooks" }, "dependencies": { "@fortawesome/fontawesome-svg-core": "^6.6.0", From 490385b3613c4e824b1f717560922cb1e568b8be Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Fri, 2 Aug 2024 14:45:48 +0200 Subject: [PATCH 4/8] Added warning and readme --- README.md | 5 +++++ gitHooks/scripts/javaPreCommit | 1 + 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index a1ccf587e0..997a3caeea 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,11 @@ try { We're happy to incorporate all improvements to JPlag into this codebase. Feel free to fork the project and send pull requests. Please consider our [guidelines for contributions](https://github.com/jplag/JPlag/wiki/3.-Contributing-to-JPlag). +### Git hooks + +The repository contains a pre-commit hook, that prevents commits if fail spotless. +To set up the hooks, call any of the installHooks scrips in gitHooks (gitHooks/installHooks (shell), gitHooks/installHooks.bat (windows), gitHooks/installHooks.py (python)) + ## Contact If you encounter bugs or other issues, please report them [here](https://github.com/jplag/jplag/issues). For other purposes, you can contact us at jplag@ipd.kit.edu . diff --git a/gitHooks/scripts/javaPreCommit b/gitHooks/scripts/javaPreCommit index e3a3116e63..fac82579aa 100755 --- a/gitHooks/scripts/javaPreCommit +++ b/gitHooks/scripts/javaPreCommit @@ -2,6 +2,7 @@ if ! command -v &> /dev/null #checks if maven is installed then + echo "Maven is not installed. Spotless will not be checked" exit 0 fi From ad2e8d0d695a5b2c95fead5b80d73be71820e911 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Mon, 5 Aug 2024 20:29:00 +0200 Subject: [PATCH 5/8] Added check for npm --- gitHooks/scripts/reportViewerPreCommit | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gitHooks/scripts/reportViewerPreCommit b/gitHooks/scripts/reportViewerPreCommit index 8185fec1f5..ccc359cd8f 100755 --- a/gitHooks/scripts/reportViewerPreCommit +++ b/gitHooks/scripts/reportViewerPreCommit @@ -1,3 +1,9 @@ #!/bin/bash +if ! command -v &> /dev/null #checks if npm is installed +then + echo "Npm is not installed. Linter check will be skipped" + exit 0 +fi + npx lint-staged From 133264530a661862b5b927fa7c0327d8d5c59afb Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Mon, 5 Aug 2024 20:29:40 +0200 Subject: [PATCH 6/8] Added correct command to install checks --- gitHooks/scripts/javaPreCommit | 2 +- gitHooks/scripts/reportViewerPreCommit | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gitHooks/scripts/javaPreCommit b/gitHooks/scripts/javaPreCommit index fac82579aa..19076694d7 100755 --- a/gitHooks/scripts/javaPreCommit +++ b/gitHooks/scripts/javaPreCommit @@ -1,6 +1,6 @@ #!/bin/bash -if ! command -v &> /dev/null #checks if maven is installed +if ! command -v mvn &> /dev/null #checks if maven is installed then echo "Maven is not installed. Spotless will not be checked" exit 0 diff --git a/gitHooks/scripts/reportViewerPreCommit b/gitHooks/scripts/reportViewerPreCommit index ccc359cd8f..502b47cb33 100755 --- a/gitHooks/scripts/reportViewerPreCommit +++ b/gitHooks/scripts/reportViewerPreCommit @@ -1,6 +1,6 @@ #!/bin/bash -if ! command -v &> /dev/null #checks if npm is installed +if ! command -v npm &> /dev/null #checks if npm is installed then echo "Npm is not installed. Linter check will be skipped" exit 0 From cf938ec806ad6f3425249775f3df7e4e3f549ab2 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Wed, 7 Aug 2024 14:21:21 +0200 Subject: [PATCH 7/8] Removed the install-hook scripts and added the required call to the wiki. --- README.md | 2 +- gitHooks/installHooks.bat | 1 - gitHooks/installHooks.py | 5 ----- gitHooks/installHooks.sh | 3 --- 4 files changed, 1 insertion(+), 10 deletions(-) delete mode 100644 gitHooks/installHooks.bat delete mode 100755 gitHooks/installHooks.py delete mode 100755 gitHooks/installHooks.sh diff --git a/README.md b/README.md index 997a3caeea..cdfe41ab69 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ Please consider our [guidelines for contributions](https://github.com/jplag/JPla ### Git hooks The repository contains a pre-commit hook, that prevents commits if fail spotless. -To set up the hooks, call any of the installHooks scrips in gitHooks (gitHooks/installHooks (shell), gitHooks/installHooks.bat (windows), gitHooks/installHooks.py (python)) +To set up the hooks, call `git config --local core.hooksPath gitHooks/hooks` once within your local repository. ## Contact If you encounter bugs or other issues, please report them [here](https://github.com/jplag/jplag/issues). diff --git a/gitHooks/installHooks.bat b/gitHooks/installHooks.bat deleted file mode 100644 index b8b6f79f21..0000000000 --- a/gitHooks/installHooks.bat +++ /dev/null @@ -1 +0,0 @@ -git config --local core.hooksPath gitHooks/hooks diff --git a/gitHooks/installHooks.py b/gitHooks/installHooks.py deleted file mode 100755 index 47ce627c8c..0000000000 --- a/gitHooks/installHooks.py +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/python - -import subprocess - -subprocess.run(["git", "config", "--local", "core.hooksPath", "gitHooks/hooks"]) \ No newline at end of file diff --git a/gitHooks/installHooks.sh b/gitHooks/installHooks.sh deleted file mode 100755 index 6db0f1649f..0000000000 --- a/gitHooks/installHooks.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -git config --local core.hooksPath gitHooks/hooks From bda9eaf0671a27dd93059794afac60acb978eb27 Mon Sep 17 00:00:00 2001 From: Alexander Milster Date: Tue, 13 Aug 2024 22:46:31 +0200 Subject: [PATCH 8/8] Moved the git hooks documentation from README to wiki. --- README.md | 5 ----- docs/3.-Contributing-to-JPlag.md | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cdfe41ab69..a1ccf587e0 100644 --- a/README.md +++ b/README.md @@ -182,11 +182,6 @@ try { We're happy to incorporate all improvements to JPlag into this codebase. Feel free to fork the project and send pull requests. Please consider our [guidelines for contributions](https://github.com/jplag/JPlag/wiki/3.-Contributing-to-JPlag). -### Git hooks - -The repository contains a pre-commit hook, that prevents commits if fail spotless. -To set up the hooks, call `git config --local core.hooksPath gitHooks/hooks` once within your local repository. - ## Contact If you encounter bugs or other issues, please report them [here](https://github.com/jplag/jplag/issues). For other purposes, you can contact us at jplag@ipd.kit.edu . diff --git a/docs/3.-Contributing-to-JPlag.md b/docs/3.-Contributing-to-JPlag.md index dc967f659e..de0647876f 100644 --- a/docs/3.-Contributing-to-JPlag.md +++ b/docs/3.-Contributing-to-JPlag.md @@ -20,3 +20,8 @@ Please try to make well-documented and clear structured submissions: Run `mvn clean package assembly:single` instead if you need the full jar which includes all dependencies. 5. You will find the generated JARs in the subdirectory `jplag.cli/target`. +### Git hooks + +The repository contains a pre-commit hook, that prevents commits if fail spotless. +To set up the hooks, call `git config --local core.hooksPath gitHooks/hooks` once within your local repository. +