Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This script makes git automatically run `bundle install` when a merge conflict with Gemfile.lock occurs. Run it once per project to setup `.gitattributes` and `.gitconfig`
#!/usr/bin/env bash
# Usage: setup-git-bundler-merge-driver
# Help: Configures git to use a custom merge driver to resolve Gemfile.lock
# merge conflicts.
if [ ! -f Gemfile ]; then
echo 'No `Gemfile` found! Aborting'
exit 1
fi
if [[ -z "$(git config merge.bundler.name)" ]]; then
git config merge.bundler.name \
'Resolves Gemfile.lock merge conflicts by running `bundle install`'
echo "Added driver name"
fi
if [[ -z "$(git config merge.bundler.driver)" ]]; then
git config merge.bundler.driver \
'echo Gemfile.lock merge conflict, running bundle install && bundle install --quiet'
echo "Added driver command"
fi
if ! grep "Gemfile.lock merge=bundler" .gitattributes &> /dev/null; then
echo "Gemfile.lock merge=bundler" >> .gitattributes
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.