This repository demonstrates how a Bundler lockfile (Gemfile.lock
) can become invalid due to a Git merge.
- e5ddb56 starts with a valid Gemfile, with
dependencies on
aaa
andzzz
,aaa
also depending onzzz
. - 583c0c7 updates
zzz
to a new version 0.2.0 - 6e82847 on a different
update-aaa
branch, updatesaaa
to a new version which limits thezzz
dependency to versions strictly lower than 0.2.0 - 557b284 even though
aaa (0.2.0)
andzzz (0.2.0)
are incompatible, Git is able to merge the two changes because the chunks are not overlapping, thanks to thebbb
,ccc
, andddd
dependencies.
This results in an invalid Gemfile.lock
, and while Bundler outputs a warning, it allows the installation and does not
return a non-zero exit status code.
One solution is to use Git attributes to disallow all merges to Gemfile.lock. This can be seen in the
gitattributes
branch, which defines the merge driver for Gemfile.lock
to be binary
. This
prevents automatic three-way merges from happening, and results in conflicts during merges instead.