Skip to content

Instantly share code, notes, and snippets.

@valtoni
Created October 10, 2012 14:04
Show Gist options
  • Save valtoni/3865836 to your computer and use it in GitHub Desktop.
Save valtoni/3865836 to your computer and use it in GitHub Desktop.
[unix] Patching directory: origin to target (exclude .svn dirs)
#!/bin/sh
# IMPORTANT: SOURCE and TARGET are relative to ACTUAL_DIR. Whathever, the patch won't work.
ACTUAL_DIR=$(pwd)
PATCH_FILE="$ACTUAL_DIR/diff.patch"
PATCH_FILE_TMP="$PATCH_FILE.tmp"
SOURCE=$1
TARGET=$2
# Make the patch
diff --exclude=".svn" -uNr $SOURCE $TARGET > $PATCH_FILE_TMP
# Convert windows format to linux format
tr -d '\r' < $PATCH_FILE_TMP > $PATCH_FILE
# Exclude temp file
rm $PATCH_FILE_TMP
# Enter in target dir
cd $TARGET
# Apply patch in target dir
patch -R -p1 < $PATCH_FILE
# Enter in original dir
cd $ACTUAL_DIR
# Remove patch file
rm $PATCH_FILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment