0

I have a bash script that applies all git patches in a directory (See bottom for the script). This script is run everytime I deploy my website on my server.

I'm now running into an issue where after a few weeks the patch throws an error and exits out the script with error "patch does not apply". Does anyone know if there is a way to ignore broken/old patches and possible just show an error that the script no longer works rather than completely exit out the script causing my website deployment to fail?

for file in ${PROJECT_PATH}/${PATCH_DIR}/*.patch; do
    if [[ -e ${file} ]]; then
        echo -n "Applying patch '${file}' ... "
        ${RUN_AS} git ${GIT_PROJECT_PATH} apply --directory="${PROJECT_PATH}" --unsafe-paths "${file}"
        echo "Done"
    fi
done
Brandy
  • 544
  • 2
  • 11
  • 30

1 Answers1

0

I don't see any reason why it would stop applying the patches. If one failed, you might get some error output and then you said "Done" (which could be a little misguiding, I think) and then the for would continue.

I guess for starters you need to control if the patch was successful or not. something like this (adjust to your needs):

for file in ${PROJECT_PATH}/${PATCH_DIR}/*.patch; do if [[ -e ${file} ]]; then echo -n "Applying patch '${file}' ... " ${RUN_AS} git ${GIT_PROJECT_PATH} apply --directory="${PROJECT_PATH}" --unsafe-paths "${file}" if [ $? -ne 0 ]; then # there was an error echo git apply of patch $file failed on $GIT_PROJECT_PATH/$PROJECT_PATH else echo "Done" fi fi done

Or something along those lines.

eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Note that `cmd; if [ $? -ne 0 ]; then ...` is a long-winded way of writing `if ! cmd; then ...`. Some prefer the separation for various purposes (it's especially useful in bash with $PIPESTATUS), so, fine either way, I just generally prefer the shorter version. – torek Sep 21 '18 at 20:52