husky precommit want to developer to force make relivant changes in two similar file otherwise commit msg thow error

47 Views Asked by At

if you want when developer changed one file of the project and you want to force to make relevant changes in to another "similar " file with the help of husky and shellScript..

1

There are 1 best solutions below

1
Laxman On

#Inside of pre-commit hook put the following code

#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
FILES=$(git diff --cached --name-only --diff-filter=ACMR )
myarray=($FILES)
file1="src/App.css"
file2="src/App.jsx"
echo ${myarray[@]}
if [[ " ${myarray[*]} " =~ " ${file1} " ]]
then
   if [[ " ${myarray[*]} " =~ " ${file2} " ]]
   then
      echo "both file are present you can continue to commit"
    else
      echo need to change src/App.jsx file also
      exit 1
   fi
else `enter code here`
  echo  "file does not exist you can continue"
fi

# npm test
npx lint-staged