Git Image Merge Conflict Tool

01/18/20131 Min Read — In Career, Resources, Testing

You probably won't ever need to create dozens of git repositories that have conflicted image files to diff and resolve, (WINK), but if you ever do, I got you covered:

#!/bin/sh
SCRIPTNAME=$(basename $0)
CURRENT_DIR=$(cd $(dirname $0);pwd)
REPO_PATH="$CURRENT_DIR/image-merge-conflict-test-repo"
if [ -d "$REPO_PATH" ]; then
rm -fr "$REPO_PATH"
fi
mkdir -p "$REPO_PATH" || exit 1
cd "\$REPO_PATH" || exit 1
# Init repository
git init .
cat > .gitignore
.DS_Store
EOF
git add .
git commit -m "Initial commit"
# Commit base image version
curl http://lorempixel.com/400/200/abstract/base/ -o image.jpg
git add .
git commit -m "Base version of image"
# Create another branch from this revision
git branch develop
# Commit modified image version on master
/bin/rm -f image.jpg
sleep 2 && curl http://lorempixel.com/400/200/abstract/master/ -o image.jpg
git add .
git commit -m "Modified image on master"
# Commit another modified image version on develop
git checkout develop
/bin/rm -f image.jpg
sleep 2 && curl http://lorempixel.com/400/200/abstract/develop/ -o image.jpg
git add .
git commit -m "Modified image on develop"
# Create merge conflict state
git checkout master
git merge develop
exit 0