git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Merge after directory rename ?

From
Marcin Wiśnicki <mwisnicki@gmail.com>
Date
Aug 22, 2011, 08:49 UTC
Message-ID
<CAC9GOO8w_zZ8wuRambnGoaS+rKskdjuSZVpF+b4mzdhzK48bjg@mail.gmail.com>
In-Reply-To
<CAMOZ1Bsb7UxYOFpRWh47+130upfD9_E=CMQtZd1NyUWPwWiW4A@mail.gmail.com>
2011/8/22 Michael Witten <mfwitten@gmail.com>:
Show 6 quoted lines
> I assume the smiley is tongue-in-cheek; however, in case it is not: It
> can't be automatic in general; did my examples mean nothing?
>
>> Or at least detect/warn about tree conflict.
>
> Did my examples mean nothing?

Well kind of. Your example was different because you have created dir1 independently on branch1 and master in which case automatic rename wouldn't be expected. If you would've created dir1 before branching and renamed dir1 to dir3 (renamed all files under dir1) then I would expect a rename while merging.

The exact behaviour of merging branch1 to master I want is:
let base = $(git merge-base master branch1)
for each {modified,added,deleted} file in $base..branch1:
  let dir = $(dirname $file)
  if $dir exists in master:
    if $dir existed in $base: [1]
      proceed
    else: # both branches independently introduced same directory
      tree conflict
  else: # no $dir in master
    if $dir existed in $base:
      if all $dir/* files in $base..master were renamed to $newdir/*:
        rename $file [s/$dir/$newdir/]
      else: # $dir was removed
        tree conflict
    else:
       proceed # simple addition

Where "$dir exists" means that a file with path of matching prefix exists. By default tree conflict should be ignored (proceed with merge as today) but user should be able to make it fatal.

[1] It would be better if instead of comparing two trees it would analyze each commit independently to detect shadowed renames: (dir1=>dir2 then new dir1) => still rename.

Show 6 quoted lines
>
>> Directory renames can happen quite frequently when working with Java/C#
>> and it is unreasonable to expect that lazy user will have to keep track of
>> it manually (with huge number of files it's impossible).
>
> Git doesn't know anything about Java/C#; that's the point.

And it shouldn't. Renames can happen with anything, I'm just pointing out that they are quite frequent in Java/C#. You might as well have a C project and rename directory "src" to "sources" and, when merging branch created from before that, expect to get automatic s/src/sources/.

Show 7 quoted lines
> In general, the user could make use of switches (as suggested). In
> particular, perhaps there are merge hooks or merge drivers that could
> be used or implemented for allowing a more environment-specific
> handling of merges, a la GNU's ChangeLog merge driver:
> Also, see the configuration section of `git help merge'. Also look at
> the tool `git mergetool'.
>

Merge drivers are file type specific, mergetool is used to resolve conflicts after merge and I don't see a pre-merge hook :(

Previous: Michael WittenNext: Michael Witten
Message 6 of 8 in “Merge after directory rename ?”
  1. Marcin WiśnickiAug 21, 2011
  2. Michael WittenAug 21, 2011
  3. Michael WittenAug 21, 2011
  4. Marcin WiśnickiAug 22, 2011
  5. Michael WittenAug 22, 2011
  6. Marcin WiśnickiAug 22, 2011
  7. Michael WittenAug 23, 2011
  8. Jeff KingAug 23, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.