{"thread":{"id":"58209","subject":"Changed diff3 view from 2.36 → 2.67 for vimdiff","startedAt":"2022-07-22T07:53:09Z","lastAt":"2022-07-25T20:43:53Z","messageCount":5,"participants":["Claudio Ebel","Martin Ågren","Fernando Ramos"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"459758","messageId":"99c80fc2-0f94-a607-ca71-c45961c07e2b@web.de","threadId":"58209","inReplyTo":null,"subject":"Changed diff3 view from 2.36 → 2.67 for vimdiff","fromName":"Claudio Ebel","fromEmail":"claudio.ebel@web.de","sentAt":"2022-07-22T07:48:01Z","receivedAt":"2022-07-22T07:53:09Z","isPatch":false,"sender":{"key":"claudio.ebel@web.de","avatar":null},"body":"Hi all,\n\nwhen solving a merge conflict using Git and Vim as mergetool, I get a totally different view than I expected and am used to. In the past, I followed this blog post (https://www.rosipov.com/blog/use-vimdiff-as-git-mergetool/), where the result is a view with four windows: LOCAL | BASE | REMOTE and then the file below. Now I get four windows as well, but LOCAL at the top and then LOCAL | LOCAL | file.\n\nFirst I was not able to figure out if the problem lies within Git or Vim. I removed my global .gitconfig as well as the .vimrc but neither helped. What finally helped was to disguise the HOME directory for Git via this command:\n\n$ git merge octodog\n$ HOME=  git mergetool\n\nMy git version:\n\n$ git --version\ngit version 2.37.1\n\nThen I tried older Git versions, 2.37.0 showed the same behavior but Git 2.36.1 showed the old view.\n\nMinimal working example (for bash):\n\n$ cd $(mktemp -d)\n$ git init\n$ # ––– config mergetool\n$ git config merge.tool vimdiff\n$ git config merge.conflictstyle diff3\n$ git config mergetool.prompt false\n$ # ––– create merge conflict\n$ echo -e 'cat\\ndog\\noctopus\\noctocat' > animals.txt\n$ git add animals.txt\n$ git commit -am 'Initial commit'\n$ git checkout -b octodog\n$ sed -i 's/octopus/octodog/' animals.txt\n$ git commit -am \"Replace octopus with an octodog\"\n$ git checkout master\n$ sed -i 's/octopus/octoman/' animals.txt\n$ git commit -am \"Replace octopus with an octoman\"\n$ # ––– trigger behavior\n$ git merge octodog\n$ git mergetool\n\nHow can I get the old view back? Is this a bug or a feature of Git? Should I write the Vim guys?\n\nThis behavior is independent of directory as well as host, it occurs on a different machine as well.\n\nThanks in advance,\nClaudio\n"},{"id":"459763","messageId":"CAN0heSrCocuKA+8UvU8dH_bsM4Xg8L3M8O4W0buXkUc3uCxpGA@mail.gmail.com","threadId":"58209","inReplyTo":"99c80fc2-0f94-a607-ca71-c45961c07e2b@web.de","subject":"Re: Changed diff3 view from 2.36 → 2.67 for vimdiff","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2022-07-22T10:49:01Z","receivedAt":"2022-07-22T10:49:22Z","isPatch":false,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Hi Claudio,\n\nOn Fri, 22 Jul 2022 at 10:40, Claudio Ebel <claudio.ebel@web.de> wrote:\n>\n> when solving a merge conflict using Git and Vim as mergetool, I get a totally different view than I expected and am used to. In the past, I followed this blog post (https://www.rosipov.com/blog/use-vimdiff-as-git-mergetool/), where the result is a view with four windows: LOCAL | BASE | REMOTE and then the file below. Now I get four windows as well, but LOCAL at the top and then LOCAL | LOCAL | file.\n>\n> First I was not able to figure out if the problem lies within Git or Vim. I removed my global .gitconfig as well as the .vimrc but neither helped. What finally helped was to disguise the HOME directory for Git via this command:\n>\n> $ git merge octodog\n> $ HOME=  git mergetool\n>\n> My git version:\n>\n> $ git --version\n> git version 2.37.1\n>\n> Then I tried older Git versions, 2.37.0 showed the same behavior but Git 2.36.1 showed the old view.\n\nI'm not a vimdiff expert by any means, but having three windows\ncontaining LOCAL seems like a bug to me... For what it's worth, I can't\nreproduce -- everything looks good to me.\n\nThere was some work on vimdiff in the v2.37.0 cycle -- I'm cc-ing the\nauthor of those patches. (He also wrote about the work at [1].)\n\nThere exists at least one vimdiff bugfix [2] in git.git's current\n'master' branch that is not yet in any released version. If you are able\nto build Git from source, you could try that version to see if it fixes\nyour problem. As far as I understand, that patch relates to end-user vim\nsettings, and you did write that you nuked your .vimrc, so maybe that\npatch doesn't quite match your problem, although from the original\nreport [3], it does seem similar.\n\nSince redirecting HOME works, I wonder if you do have some other config\nfile after all. Do you have a ~/.config/git/config file? Maybe,\nsimilarly, you have more than just one vimrc?\n\nThere's also a patch to handle whitespace in paths [4], but it's not yet\nin git.git's master branch (it's only in the 'next' branch so far). From\nyour description, it doesn't quite sound like the failure mode that\npatch author described, though. If you're interested in trying it out,\nyou could either `git am` the patch in [4], or you could try `git merge\nccc7b5148` into, e.g., current master.\n\n[1] https://u92.eu/blog/git-vimdiff/\n[2] https://lore.kernel.org/git/20220708181024.45839-1-greenfoo@u92.eu/\n[3] https://lore.kernel.org/git/CACRpdvnuAYY0U1_3uD8zKgtq05+bgwjzXpZKomro6gqYDNrjGg@mail.gmail.com/\n[4] https://lore.kernel.org/git/pull.1287.v2.git.1657809063728.gitgitgadget@gmail.com/\n\nMartin\n"},{"id":"459794","messageId":"YtsMhb0XUPw2EekJ@zacax395.localdomain","threadId":"58209","inReplyTo":"CAN0heSrCocuKA+8UvU8dH_bsM4Xg8L3M8O4W0buXkUc3uCxpGA@mail.gmail.com","subject":"Re: Changed diff3 view from 2.36 → 2.67 for vimdiff","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-07-22T20:45:57Z","receivedAt":"2022-07-22T20:46:09Z","isPatch":false,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"\n> There exists at least one vimdiff bugfix [2] in git.git's current\n> 'master' branch that is not yet in any released version. If you are able\n> to build Git from source, you could try that version to see if it fixes\n> your problem. As far as I understand, that patch relates to end-user vim\n> settings, and you did write that you nuked your .vimrc, so maybe that\n> patch doesn't quite match your problem, although from the original\n> report [3], it does seem similar.\n\nHi Claudio.\n\nAs Martin just said, this looks *very* similar to the behaviour you would\nexperience if you had vim configured to open splits \"in reverse\" (when compared\nto the default settings).\n\nYou can make this test to confirm whether this is the case or not: try to run\nthis command:\n\n    vim -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" local.txt base.txt remote.txt merged.txt\n\n(note: this is the same command git 2.37 uses when running\n`git mergetool -t vimdiff`)\n\nIt should open 4 windows with the following layout:\n\n    -------------------------------\n    |  local  |  base  |  remote  |\n    -------------------------------\n    |           merged            |\n    -------------------------------\n\nIf you see something different, please then try to run this other command :\n\n    vim -c \"echo | leftabove split | leftabove vertical split | 1b | wincmd l | leftabove vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" local.txt base.txt remote.txt merged.txt\n\n(note: this is the same command git will run in a *future* version)\n\nNotice that this new command is exactly the same as the previous one but\nincluding keyword `leftabove` before all `split` and `vertical split` commands.\n\nIf you run this command and this time it displays the expected layout, you have\ntwo options:\n\n    A) Wait for the next git version where this will be fixed :)\n       (as Martin pointed out, the patch can be found in [1])\n\n    B) Update your .vimrc to include these two lines:\n\n         set nosplitbelow\n         set nosplitright\n\n       ...or, alternatively, update your .vimrc *not* to have these two lines\n       (as both options are disabled by default):\n\n         set splitbelow\n         set splitright\n\n\n> Since redirecting HOME works, I wonder if you do have some other config\n> file after all. Maybe you have more than just one vimrc?\n\nThis is also what I suspect.\n\nYou can make this experiment to confirm this theory:\n\n  1. Run \"vim\" and then \":set splitbelow?\"\n\n  2. Run \"HOME= vim\" and then \":set splitbelow?\"\n\nIf the returned string is different (\"splitbelow\" in one case and \"nosplitbelow\"\nin the other one) it means you have a \".vimrc\" (or something else) somewhere in\nyour $HOME that is changing vim's default settings.\n\nBy the way, you can list all scripts \"sourced\" by a vim instance by running this\ncommand from inside vim:\n\n    :scriptnames\n\nThat will help you find the \"rogue\" script inside your $HOME.\nNote that it could happen that some of the other vim scripts you have sets those\nvariables without you noticing!... in that case you can also change their value\nback *at the end* of your \"~/.vimrc\"\n\n\nFernando.\n\n\n[1] https://lore.kernel.org/git/20220708181024.45839-1-greenfoo@u92.eu/\n\n"},{"id":"459852","messageId":"7dc225d7-eb36-9fb8-5977-6913ac4dd007@web.de","threadId":"58209","inReplyTo":"YtsMhb0XUPw2EekJ@zacax395.localdomain","subject":"Re: Changed diff3 view from 2.36 → 2.67 for vimdiff","fromName":"Claudio Ebel","fromEmail":"claudio.ebel@web.de","sentAt":"2022-07-24T21:59:40Z","receivedAt":"2022-07-24T22:04:55Z","isPatch":false,"sender":{"key":"claudio.ebel@web.de","avatar":null},"body":"Dear Martin, dear Fernando,\n\nfirst of all: Thank you both very much for your super fast and elaborate answers. It's amazing to get responses from the developers themselves! I read the blog post about the new vimdiff layout with delight. I like the new feature very much, especially the decision and implementation of the generic mechanism which is indeed better than the introduction of new vimdiff4, … layouts. I think I'll stick to the “advanced” four tab option for my future merge conflicts, like you suggested in your blog, too.\n\nRegarding the problem, yes, you both were right, I have had a “second rogue” vimrc in my home directory. It has been – as most often – a “layer eight” problem (myself). I have had a ~/.vim directory with a ~/.vim/vimrc file inside. Since I had expected Vim to need an ~/.vimrc file, I had created a symbolic link ~/.vimrc -> ~/.vim/vimrc. “Nuking“ my vimrc had meant for me to delete this symbolic link (~/.vimrc), but as I learned today, the ~/.vim/vimrc file is perfectly fine. You always learn new things! So to really nuke the vimrc, I had to move the .vim directory as well and then git behaved like expected, just like you suggested.\n\nI investigated further and – oh wonder! – I found those two lines in my vimrc:\n\nset splitbelow\nset splitright\n\nUncommenting them brought the good old back behavior back, too. So the problem is solved, great!!!\n\nBy the way, the buggy layout looked exactly like Matthew Klein reported in Martins link [1]. The difference is, obviously, the difference in tools (his --tool=nvimdiff versus mine --tool=vimdiff).\n\n    ------------------------------------------\n    |                                        |\n    |                LOCAL                   |\n    |                                        |\n    ------------------------------------------\n    |             |           |              |\n    |   LOCAL     |   LOCAL   |   MERGED     |\n    |             |           |              |\n    ------------------------------------------\n\nI also managed to compile the newest master branch of git (the Arch User Repository git-git package should be fixed, it's broken at the moment, but I managed to bypass all obstacles) and, as you hinted, this version (git version 2.37.1.223.g6a475b71f8) is not sensitive to the \"splitbelow / splitright\" options!\n\nAfter successfully compiling Git, I'm almost ashamed to ask, but I was NOT able to run the vim command you suggested, Fernando:\n\nvim -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" local.txt base.txt remote.txt merged.txt\n\nbecause there are no such files?! What do I have to do before executing this command? I read the man page and tried it with \"git config mergetool.keepTemporaries true\" and \"git config mergetool.keepBackup true\", but still no such files appear. I am sure I am missing something completely obvious. Even my google-foo failed… Since I solved my problem on many levels (thanks to your great help), executing those vim commands is not important anymore, I just would like to understand…\n\nThank you very much again,\n\nwith best regards,\nClaudio\n\n[1] https://lore.kernel.org/git/CACRpdvnuAYY0U1_3uD8zKgtq05+bgwjzXpZKomro6gqYDNrjGg@mail.gmail.com/\n"},{"id":"459921","messageId":"Yt8AfljwGc6a95Sv@zacax395.localdomain","threadId":"58209","inReplyTo":"7dc225d7-eb36-9fb8-5977-6913ac4dd007@web.de","subject":"Re: Changed diff3 view from 2.36 → 2.67 for vimdiff","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-07-25T20:43:42Z","receivedAt":"2022-07-25T20:43:53Z","isPatch":false,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> \n> After successfully compiling Git, I'm almost ashamed to ask, but I was NOT\n> able to run the vim command you suggested, Fernando:\n> \n> vim -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" local.txt base.txt remote.txt merged.txt\n> \n\nHi Claudio,\n\nNotice that this command was meant to be executed *directly* from the terminal\n(and not from .gitconfig).\n\nIt just opens 4 files that, as you noted, do not exist... but that's ok with\nvim: it will open 4 buffers named after the provided filenames and only save\nthem to disk when running \":w\".\n\nThe result should be something like what is shown in [1], ie. 4 empty buffers\nnamed \"local\", \"base\", \"remote\" and \"merged\" shown with the expected layout.\n\nHope this helps!\n\nFernando.\n\n\n[1] https://postimg.cc/dL8G2mng\n"}]}