Skip to content

Instantly share code, notes, and snippets.

@bruvzg
Created April 12, 2020 18:54
Show Gist options
  • Save bruvzg/943838bfc48fcc8214862356627b16ff to your computer and use it in GitHub Desktop.
Save bruvzg/943838bfc48fcc8214862356627b16ff to your computer and use it in GitHub Desktop.
Godot pre-commit hooks GUI (zenity).
diff --git a/misc/hooks/pre-commit-black b/misc/hooks/pre-commit-black
index 2dcc2e8cf1..3e6ac0fb8d 100755
--- a/misc/hooks/pre-commit-black
+++ b/misc/hooks/pre-commit-black
@@ -102,31 +102,26 @@ printf "and the black formatter rules:\n\n"
$READER "$patch"
printf "\n"
-# Allows us to read user input below, assigns stdin to keyboard
-exec < /dev/tty
-
while true; do
- read -p "Do you want to apply that patch (Y - Apply, N - Do not apply, S - Apply and stage files)? [Y/N/S] " yn
- case $yn in
- [Yy] ) git apply $patch;
+ zenity --question --width=300 --text="Do you want to apply that patch" --ok-label="Apply" --cancel-label="Do not apply"
+ case $? in
+ [0] ) git apply $patch;
printf "The patch was applied. You can now stage the changes and commit again.\n\n";
+ zenity --question --width=300 --text="Do you want to stage files" --ok-label="Yes" --cancel-label="No"
+ if [ "$?" = "0" ]; then
+ git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
+ do git add $file;
+ done
+ printf "The changed files staged. You can now commit.\n\n";
+ fi
break
;;
- [Nn] ) printf "\nYou can apply these changes with:\n git apply $patch\n";
+ * ) printf "\nYou can apply these changes with:\n git apply $patch\n";
printf "(may need to be called from the root directory of your repository)\n";
printf "Aborting commit. Apply changes and commit again or skip checking with";
printf " --no-verify (not recommended).\n\n";
break
;;
- [Ss] ) git apply $patch;
- git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
- do git add $file;
- done
- printf "The patch was applied and the changed files staged. You can now commit.\n\n";
- break
- ;;
- * ) echo "Please answer yes or no."
- ;;
esac
done
exit 1 # we don't commit in any case
diff --git a/misc/hooks/pre-commit-clang-format b/misc/hooks/pre-commit-clang-format
index c5cf4ecbb1..78f25298bb 100755
--- a/misc/hooks/pre-commit-clang-format
+++ b/misc/hooks/pre-commit-clang-format
@@ -120,31 +120,26 @@ printf "and the clang-format rules:\n\n"
$READER "$patch"
printf "\n"
-# Allows us to read user input below, assigns stdin to keyboard
-exec < /dev/tty
-
while true; do
- read -p "Do you want to apply that patch (Y - Apply, N - Do not apply, S - Apply and stage files)? [Y/N/S] " yn
- case $yn in
- [Yy] ) git apply $patch;
+ zenity --question --width=300 --text="Do you want to apply that patch" --ok-label="Apply" --cancel-label="Do not apply"
+ case $? in
+ [0] ) git apply $patch;
printf "The patch was applied. You can now stage the changes and commit again.\n\n";
+ zenity --question --width=300 --text="Do you want to stage files" --ok-label="Yes" --cancel-label="No"
+ if [ "$?" = "0" ]; then
+ git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
+ do git add $file;
+ done
+ printf "The changed files staged. You can now commit.\n\n";
+ fi
break
;;
- [Nn] ) printf "\nYou can apply these changes with:\n git apply $patch\n";
+ * ) printf "\nYou can apply these changes with:\n git apply $patch\n";
printf "(may need to be called from the root directory of your repository)\n";
printf "Aborting commit. Apply changes and commit again or skip checking with";
printf " --no-verify (not recommended).\n\n";
break
;;
- [Ss] ) git apply $patch;
- git diff-index --cached --diff-filter=ACMR --name-only $against -- | while read file;
- do git add $file;
- done
- printf "The patch was applied and the changed files staged. You can now commit.\n\n";
- break
- ;;
- * ) echo "Please answer yes or no."
- ;;
esac
done
exit 1 # we don't commit in any case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment