git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* git bug - merging JS / Node.js code with "git merge --squash"
@ 2016-12-15  7:12 Alexander Mills
  2016-12-15 18:10 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Mills @ 2016-12-15  7:12 UTC (permalink / raw)
  To: git

@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/

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: git bug - merging JS / Node.js code with "git merge --squash"
  2016-12-15  7:12 git bug - merging JS / Node.js code with "git merge --squash" Alexander Mills
@ 2016-12-15 18:10 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2016-12-15 18:10 UTC (permalink / raw)
  To: Alexander Mills; +Cc: git

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.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-12-15 18:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-15  7:12 git bug - merging JS / Node.js code with "git merge --squash" Alexander Mills
2016-12-15 18:10 ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).