-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot kill git pre-commit hook while lingui command is running #1833
Comments
You can try to catch signals like SIGINT (CTRL+C) in the main process and kill the child process: #!/bin/bash
trap "kill -SIGINT $lingui_pid" SIGINT
# Start the extract process, storing its PID
npm --prefix assets run extract &
lingui_pid=$! The P.S. Didn't test it, so I'm not sure if it's going to work with git hooks. |
Thank you @andrii-bodnar. I learnt about After more tests, I need to add some corrections to my issue. Both lingui commands are problematic:
The problem happens if I enter CTRL+C while one of these commands are running.
I have been able to understand a bit more when running the script directly (by entering If I run the hook script normally with git (e.g. Lastly, I noticed that adding #!/usr/bin/env bash
#
# Git pre-commit hook
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
message()
{
MESSAGE="$1"
COLOR="$2"
echo -e "${COLOR}${MESSAGE}${NC}"
}
error()
{
message "$1" "$RED";
exit 1
}
success() { message "$1" "$GREEN" ; }
cd "$(git rev-parse --show-toplevel)" || error "Cannot change working directory to root of Git repository!"
trap "exit 1" SIGINT
npm --prefix assets run extract
./assets/js/locales/normalize.sh
if npm --prefix assets run compile; then
success "The frontend code messages have been translated."
else
error "Commit failed due to frontend code missing translations!"
fi
if npm --prefix assets run prettier; then
success "The frontend code is properly formatted."
else
error "Commit failed due to frontend code formatting issues!"
fi
if npm --prefix assets run lint; then
success "The frontend code meets the quality requirements."
else
error "Commit failed due to frontend code quality issues!"
fi
if npm --prefix assets test; then
success "The frontend code tests passed."
else
error "Commit failed due to frontend code test failures!"
fi With that modification:
What is happening with the lingui commands? How can we solve this properly? |
lingui extract --clean
has started
Thanks for detailed investigation. Actually, lungui uses under the hood So it's rather regular JS script which is run by node.js. It doesn't spawn it's own child processes or call external tools. So i assume the current behaviour is just a default behaviour for long running scripts in node. |
My #!/usr/bin/env bash
#
# Git pre-commit hook
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
message()
{
MESSAGE="$1"
COLOR="$2"
echo -e "${COLOR}${MESSAGE}${NC}"
}
error()
{
message "$1" "$RED";
exit 1
}
success() { message "$1" "$GREEN" ; }
cd "$(git rev-parse --show-toplevel)" || error "Cannot change working directory to root of Git repository!"
npm --prefix assets run extract
./assets/js/locales/normalize.sh
if npm --prefix assets run compile; then
success "The frontend code messages have been translated."
else
error "Commit failed due to frontend code missing translations!"
fi
if npm --prefix assets run prettier; then
success "The frontend code is properly formatted."
else
error "Commit failed due to frontend code formatting issues!"
fi
if npm --prefix assets run lint; then
success "The frontend code meets the quality requirements."
else
error "Commit failed due to frontend code quality issues!"
fi
if npm --prefix assets test; then
success "The frontend code tests passed."
else
error "Commit failed due to frontend code test failures!"
fi and my {
...
"scripts": {
"build": "react-scripts build",
"compile": "lingui compile --strict",
"deploy": "webpack --mode production",
"eject": "react-scripts eject",
"extract": "lingui extract --clean ",
"lint": "eslint --ext .js,.jsx,.ts,.tsx --max-warnings 0 .",
"prettier": "prettier --check .",
"prettier-write": "prettier --write .",
"start": "react-scripts start",
"test": "jest"
},
...
} So there are 5 commands related to node.js in the git hook script:
Only the lingui commands exhibit the problem so there must be something done differently in lingui, I guess. |
Describe the bug
It is not possible to stop a git pre-commit hook after
lingui extract --clean
has started, even afterlingui extract --clean
has finished.To Reproduce
In one of my project I have the following git pre-commit hook (
.git/hooks/pre-commit
):My
package.json
contains:After the hook script starts executing
npm --prefix assets run extract
, then trying to kill the process with CTRL+C does not do much as the script keeps running. I am forced to let the whole script finish or close the terminal tab which is not practical.Expected behavior
CTRL+C should stop the hook script.
Additional context
Add any other context about the problem here.
lingui --version
: 4.5.0npm list @babel/core
: 7.23.2@lingui/swc-plugin
babel-macro-plugin
.babelrc
) or framework you use (Create React App, NextJs, Vite).babelrc
:The text was updated successfully, but these errors were encountered: