Last active
August 29, 2015 14:16
-
-
Save arthurprogramming/af8c619450e82cb5438b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PROJECTPATH=$1 | |
PATHTOSAVE=$2 | |
if [[ -z $PROJECTPATH ]]; then | |
echo "no project path informed!" | |
exit 1 | |
fi | |
if [[ -z $PATHTOSAVE ]]; then | |
echo "no path to save informed!" | |
exit 1 | |
fi | |
cd $PROJECTPATH | |
BRANCH=`git rev-parse --abbrev-ref HEAD | sed 's/\//--/'` | |
if [ ! -d $PATHTOSAVE$BRANCH ]; then | |
mkdir -p $PATHTOSAVE$BRANCH | |
fi | |
CONTENT=`git diff --no-ext-diff --no-prefix` | |
TMPFILENAME="tmp.patch" | |
SAVE=1 | |
if [[ ! -z $CONTENT ]]; then | |
FILETOSAVE=$PATHTOSAVE$BRANCH"/"`date +'%Y-%m-%d_%H-%M-%S'`".patch" | |
TMPFILE=$PATHTOSAVE$BRANCH"/"$TMPFILENAME | |
echo $CONTENT > $TMPFILE | |
for FILE in `ls $PATHTOSAVE$BRANCH` | |
do | |
if [ $FILE != $TMPFILENAME ]; then | |
DIFF=`diff $PATHTOSAVE$BRANCH"/"$FILE $TMPFILE` | |
if [[ -z $DIFF ]]; then | |
SAVE=0 | |
fi | |
fi | |
done | |
if [ $SAVE == 1 ]; then | |
echo $CONTENT > $FILETOSAVE | |
fi | |
rm $TMPFILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
*/3 * * * * /path/to/savediff.sh /path/to/project/ /path/to/save/