git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Subject: How to automatically correct an almost correct auto-merge?
Date: Fri, 16 Dec 2011 21:32:15 +0100	[thread overview]
Message-ID: <20111216203215.GG1868@goldbirke> (raw)

Hi,


Briefly:

Neighboring areas of a file are modified in two branches.  Git merges
the two branches without conflicts, but the result is not semantically
correct.  How can I teach git to produce the correct merge result when
performing the same merge later on?


Longer:

The following commands create a file and two branches, both of them
modifying the file by adding lines in the same area:

git init
cat >file <<\EOF
1

2
EOF
git add file
git commit -m file
git apply <<\EOF
diff --git a/file b/file
index 1c3e7efc..121366a2 100644
--- a/file
+++ b/file
@@ -1,3 +1,5 @@
 1

+a
+
 2
EOF
git commit -a -m a
git checkout -b branch HEAD^
git apply <<\EOF
diff --git a/file b/file
index 1c3e7efc..f2e91d4f 100644
--- a/file
+++ b/file
@@ -1,3 +1,6 @@
 1
+b
+
+c

 2
EOF
git commit -a -m 'b c'
git checkout master


At this point I merge 'branch' and git produces the following result:

$ git merge branch
Auto-merging file
Merge made by the 'recursive' strategy.
 file |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
$ cat file
1
b

c

a

2


Now, these changes and the merge above are the minimal receipe which
corresponds to a real merge I'm having trouble with at dayjob.  Just
imagine that '1' and '2' are the beginning and end of a function, 'b'
is the declaration of a new local variable, and 'a' and 'c' are new
code blocks.  As it happens, the semantically correct result would be
the following:

1
b

a

c

2

i.e. 'a' must be executed before 'c'.

I corrected the merge result manually, but these two branches are
merged a couple of times a day into an integration branch, and they
will likely cook for a few weeks, which means a lot of merges, and a
lot of manual corrections.  So I'm looking for a way to teach git to
produce the semantically correct merge result.  Something like
'rerere' would be great, but of course I can't use 'rerere' in this
case, because there are no merge conflicts at all...

Any ideas?  Did someone deal with similar issues before?


Thanks,
Gábor

             reply	other threads:[~2011-12-16 20:32 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-16 20:32 SZEDER Gábor [this message]
2011-12-16 20:39 ` How to automatically correct an almost correct auto-merge? Seth Robertson
2011-12-17 11:07   ` SZEDER Gábor
2011-12-16 21:32 ` Neal Kreitzinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20111216203215.GG1868@goldbirke \
    --to=szeder@ira.uka.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).