git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Elijah Newren <newren@gmail.com>
To: Matt Neuburg <matt@tidbits.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: possible bug due to directory rename detection
Date: Wed, 14 Apr 2021 21:21:21 -0700	[thread overview]
Message-ID: <CABPp-BFm12ao-M9TVLpde3B7tkuX746t7Qs5V8-hEbshig0ZTw@mail.gmail.com> (raw)
In-Reply-To: <C0E64A34-AAA0-4ECE-8EC5-045815B3413D@tidbits.com>

Hi,

On Wed, Apr 14, 2021 at 5:51 PM Matt Neuburg <matt@tidbits.com> wrote:
>
> git version 2.24.3 (Apple Git-128) running under Big Sur on a MacBook Pro.
>
> Please see
>
>   https://stackoverflow.com/questions/67067686/git-file-level-merge-conflict-caused-by-git-suggesting-the-file-should-perhap
>
> for a complete description of what I saw and why I think it's wrong.
>
> However, I will also reproduce the question here (just copy and paste, in GitHub Markdown format). Notice that I provide a complete `ls` for both branch tips and their merge-base, and since the problem has to do with a file-level merge conflict that I contend is generated by Git itself due to its overly aggressive directory rename detection behavior, that should be sufficient to describe the entire matter.
>
> As I say in a comment on SO:
>
> `git diff --find-renames` from merge-base to master reveals that (as one can also see by eye) the vast preponderance is entirely new stuff in _wordpressed_ or stuff that was moved (renamed) from top level to _wordpressed_. There is exactly one existing rename where an article was moved from _dan_ to _wordpressed_:
>
>     diff --git a/dan/bdd.md b/wordpressed/bdd.md
>
> And yet on just that basis alone, Git assumes that this new article that popped up in _dan_ should have popped up in _wordpressed_ instead?? I'm sorry, I regard this as a Git bug. There needs at the very least to be a way to turn off this "feature", surely.

Yes, it's certainly possible to avoid the conflict.  There's two ways.
First, you can just tell it to automatically accept the directory
renames without conflicting:
  git config merge.directoryRenames true
Or, you can tell it to never use these detected directory renames:
  git config merge.directoryRenames false
The default behavior is equivalent to
  git config merge.directoryRenames conflict

Different people like different behaviors, there's no way to know
which one _you_ prefer.  I know a lot of people running with
merge.directoryRenames set to true.  I once saw someone on this list
who wanted merge.directoryRenames to be false, and it sounds like you
may be the second.  There are almost certainly more folks.  But the
fact that people have different preferences and there's no way to tell
what would be wanted from looking at the history suggests that
reporting a conflict is the only sane thing to do by default.

In case it helps, here's the parts from your output that are relevant...

> Thanks for listening. m.

> To show you the situation, I'm going to show what a `ls` of files and folders looks like in each branch. I'll start with `master`:
>
> ```
> $ git status
> On branch master
> Your branch is up to date with 'origin/master'.
> nothing to commit, working tree clean
>
> $ ls -1 -R
...
> ./dan:
...doesn't have any files, thus isn't tracked by git...
>
> ./wordpressed:
...snipped lots of other files...
> bdd.md


> Okay, now here is `home-base`:
>
> ```
> $ git switch home-base
> Switched to branch 'home-base'
> Your branch is up to date with 'origin/home-base'.
>
> $ ls -1 -R
...
>
> ./dan:
> bdd.md
> homebase.md
...So two files in `dan`; bdd.md and homebase.md


> Finally, for the sake of completeness, I'm going to show you the merge base between `master` and `home-base`:

Yes, it's critical to look at this too.

> ```
> $ git merge-base master home-base
> b5d7355fe42eddad96beb200df2cba65381c288a
> $ git checkout b5d7355fe
> $ ls -1 -R
...
> ./dan:
> bdd.md

So `dan` only had one file: bdd.md

> Now then. Ask yourself, please, what should happen when I try to merge `master` into `home-base`. What are contributions from both sides of the merge? In my view, Git should realize that in `master` a lot of new files appeared in _wordpressed_, and that some of them are renames of files that used to be at the top level. Plus, of course, in `home-base`, a new file _homebase.md_ has appeared in _dan_.

Yes, and in addition every single file in the dan/ directory was moved
into the wordpressed/ directory in master (all one of them in this
case), while home-base added a new file to the old dan/ directory.
Often, folks put files together in a directory because they are
related and want to keep those files together.  When every file in a
directory is moved to some new directory by one side of history, and
the other side of history adds a new file to the old directory,
shouldn't the merge realize that and move the new file to the new
directory?

Some may say 'no', it shouldn't.  Many people say 'yes', it should.
How is git supposed to know?  It can't be based solely on looking at
the history; the relatedness of files in the same directory is some
kind of semantic meaning that people don't record.  So, by default,
git marks it as a conflict and asks you to decide like this:

> $ git switch home-base
> $ git merge master
> CONFLICT (file location): dan/homebase.md added in HEAD inside a directory that was renamed in master, suggesting it should perhaps be moved to wordpressed/homebase.md.
> Automatic merge failed; fix conflicts and then commit the result.

As I mentioned above, you can set merge.directoryRenames if you want
to avoid these conflicts, picking whichever of the two options other
than 'conflict' that you prefer.  Perhaps we should mention the
merge.directoryRenames config variable when one or more warnings of
this type are involved in a merge; otherwise it's not that
discoverable.


Hope that helps,
Elijah

      reply	other threads:[~2021-04-15  4:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-15  0:17 Matt Neuburg
2021-04-15  4:21 ` Elijah Newren [this message]

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=CABPp-BFm12ao-M9TVLpde3B7tkuX746t7Qs5V8-hEbshig0ZTw@mail.gmail.com \
    --to=newren@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=matt@tidbits.com \
    --subject='Re: possible bug due to directory rename detection' \
    /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

Code repositories for project(s) associated with this 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).