threads / bug / 44708

git bug - merging JS / Node.js code with "git merge --squash"

Subject: git bug - merging JS / Node.js code with "git merge --squash"

## tl;dr

2 messages between Dec 15, 2016 and Dec 15, 2016.

replies: 1people: 2as markdown or json

Alexander Mills· Dec 15, 2016, 07:12 UTC · lore
@git-community
I am on Git git version 2.7.4

This problem is happening on Ubuntu 16.04, but the same problem was also happening when I was running on MacOS.

I am consistently seeing merge bugs, when merging between branches of a mostly Node.js project. I am seeing fairly bad merges that mangle the code in ways that seem to clearly show some sort of Git bug. Some of these merges were for files where there was likely not even a diff between the files. TBH I am no Git expert, but maybe I will learn something from this investigation.

The latest example of a mangled file is here: https://github.com/ORESoftware/suman/blob/staging/suman.conf.js

You can see some repeat code, and also there is a dangling brace which means that the file won't even "compile" with Node.js, using "$ node -c". Notice that this file was *not* a file where I recently had to manually merge code or manually fix a conflict, so I am hoping this is not obvious operator error.

Here is the script I am using to merge between branches: https://github.com/ORESoftware/suman/blob/dev/publish-suman.sh

basically it is doing the merge with this line:
git merge --squash -Xtheirs dev -m "squashing" &&

This is obviously very concerning because I can get very strange bugs that I wouldn't expect, because I just assume that merges go well if they succeed and it's hard to check for failure after that; even in a compile statically typed language it could still prove difficult.

I am doing a check to make sure all my files compile with "node -c" after the merge, but even then Git could create mangled code that would still pass a "node -c" check.

Please let me know if this is a known bug and if there is a good strategy to avoid it.

thanks!
-- 
Alexander D. Mills
(650)269-9502
alexander.d.mills@gmail.com

www.linkedin.com/pub/alexander-mills/b/7a5/418/
Junio C Hamano· Dec 15, 2016, 18:10 UTC · re: Alexander Mills · lore

Re: git bug - merging JS / Node.js code with "git merge --squash"

Alexander Mills <alexander.d.mills@gmail.com> writes:
> basically it is doing the merge with this line:
>
> git merge --squash -Xtheirs dev -m "squashing" &&

The order of command line parameters are "dashed options and their arguments first, then refs (and then pathspecs if exists), so you should make it a habit to move that "dev" at the end of the command line. This does not have anything to do with the issue you are asking for help, though.

I suspect the problem is not in --squash but with -Xtheirs. It is "I give up correctly resolving conflicts and blindly take whatever comes from their side, discarding what I did".

The "git merge" command stops and asks a human to help resolving a conflict using their brain when it needs to because the command knows it itself does not have any but the human user has a better one ;-). -Xtheirs and -Xours disables this safety/sanity.

If you punt, it is expected that you would get garbage.  

For example, your side may have introduced a new function (or renamed an existing one) near where their side made a change that resulted in conflicts. Naturally, your side also would have added new callsites to that new function (you wouldn't be adding an unused function). Imagine in such a scenario that you asked "discard what I did in the conflicted section and blindly take whatever they did". What happens? They may not have done anything near the places you added calls to the new function and these sections of the code would merge cleanly with or without -Xtheirs, but the actual new function you added may be in the conflicted section that you asked to discard, taking their changes.

← back to recent threads