1

I use the git pre-commit hook to run an autoformat-script format-src.sh that is based on clang-format. Some developers use github-desktop where it is not easy possible to install the clang-format package. For this reason i decided to call cygwin bash from the precommit-hook. In cygwin it is easy possible to install the clang-format package with cygwins package manager.

The call of the cygwin shell is done according to: Creating batch file to start cygwin and execute specific command

pre-commit

#!/bin/sh
echo "Format src accordingt to format-src.sh"

CYGWIN_DIR=c:/cygwin64/
PROJ_DIR=/cygdrive/c/Projekte/ExampleProj

eval '$CYGWIN_DIR/bin/mintty $CYGWIN_DIR/bin/bash --login -c "cd $PROJ_DIR; ./format-src.sh"'

My problem ist that the pre-commit hook seems not to wait until the cywin terminal mintty has finished the skript format-src.sh. Therfore the commit finishes while the auto-formater script still runs.

How can i wait until the the script that runs in mintty has finished ?

MaxM.
  • 71
  • 4

1 Answers1

1

I was thinking of using $!. But as it turned out, mintty changed pid when the format-src.sh script fired. We will have to monitor its status from ps.

#!/bin/sh
echo "Format src accordingt to format-src.sh"

CYGWIN_DIR=c:/cygwin64/
PROJ_DIR=/cygdrive/c/Projekte/ExampleProj

eval '$CYGWIN_DIR/bin/mintty $CYGWIN_DIR/bin/bash --login -c "cd $PROJ_DIR; ./format-src.sh"'

echo "Monitor mintty status"
while true; do
    ps -s | grep mintty || break
    sleep 1
done
echo "Cygwin mintty finished"
Taylor G.
  • 661
  • 3
  • 10