git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Avoid rename/add conflict when contents are identical
@ 2010-08-09 21:00 Schalk, Ken
  2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
  2010-08-13  1:18 ` Junio C Hamano
  0 siblings, 2 replies; 8+ messages in thread
From: Schalk, Ken @ 2010-08-09 21:00 UTC (permalink / raw)
  To: git@vger.kernel.org

Skip the entire rename/add conflict case if the file added on the
other branch has the same contents as the file being renamed.  This
avoids giving the user an extra copy of the same file and presenting a
conflict that is confusing and pointless.

Here's a simple sequence that generates this kind of conflict:

  git init
  echo content > fileA
  git add fileA
  git commit -m Initial
  git checkout -b abranch
  mv fileA fileB
  git add fileB
  rm fileA
  ln -s fileB fileA
  git add fileA
  git commit -m Linked
  git checkout master
  git mv fileA fileB
  git add fileB
  git commit -m Moved
  git merge --no-commit abranch

Signed-off-by: Ken Schalk <ken.schalk@intel.com>
---
 merge-recursive.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/merge-recursive.c b/merge-recursive.c
index fb6aa4a..57c7a85 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -955,6 +955,18 @@ static int process_renames(struct merge_options *o,
                                                        ren1->pair->two : NULL,
                                                        branch1 == o->branch1 ?
                                                        NULL : ren1->pair->two, 1);
+                       } else if ((dst_other.mode == ren1->pair->two->mode) &&
+                                  sha_eq(dst_other.sha1, ren1->pair->two->sha1)) {
+                               /* Added file on the other side
+                                  identical to the file being
+                                  renamed: clean merge */
+                               update_file(o, 1, ren1->pair->two->sha1, ren1->pair->two->mode, ren1_dst);
+                               if (!o->call_depth)
+                                       update_stages(ren1_dst, NULL,
+                                                       branch1 == o->branch1 ?
+                                                       ren1->pair->two : NULL,
+                                                       branch1 == o->branch1 ?
+                                                       NULL : ren1->pair->two, 1);
                        } else if (!sha_eq(dst_other.sha1, null_sha1)) {
                                const char *new_path;
                                clean_merge = 0;
--
1.7.0

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

end of thread, other threads:[~2010-09-03 18:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-09 21:00 [PATCH] Avoid rename/add conflict when contents are identical Schalk, Ken
2010-08-09 21:24 ` Ævar Arnfjörð Bjarmason
2010-08-13  1:18 ` Junio C Hamano
2010-08-27 22:14   ` Schalk, Ken
2010-08-28 10:12     ` Ævar Arnfjörð Bjarmason
2010-08-31 21:05       ` Schalk, Ken
2010-09-01 20:15       ` Schalk, Ken
2010-09-03 18:29         ` Junio C Hamano

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).