Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Last active August 13, 2018 08:41
Show Gist options
  • Save itspriddle/5548930 to your computer and use it in GitHub Desktop.
Save itspriddle/5548930 to your computer and use it in GitHub Desktop.
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