{"thread":{"id":"57629","subject":"[PATCH v7 0/4] vimdiff: new implementation with layout support","startedAt":"2022-03-28T22:30:34Z","lastAt":"2022-04-04T21:53:58Z","messageCount":37,"participants":["Fernando Ramos","Junio C Hamano","Philippe Blain"],"isPatch":true,"patchVersion":7,"patchTotal":4},"messages":[{"id":"452517","messageId":"20220328223019.271270-1-greenfoo@u92.eu","threadId":"57629","inReplyTo":null,"subject":"[PATCH v7 0/4] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:30:15Z","receivedAt":"2022-03-28T22:30:34Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Original cover letter (see v7 changes at the end):\n\nA few weeks ago I presented this RFC [1] where I introduced a new variant of the\nvimdiff merge tool (\"vimdiff4\") that creates three tabs (instead of just one)\nthat look like this:\n\n    ------------------------------------------\n    | <TAB #1> |  TAB #2  |  TAB #3  |       |\n    ------------------------------------------\n    |             |           |              |\n    |   LOCAL     |   BASE    |   REMOTE     |\n    |             |           |              |   <---- Same information\n    ------------------------------------------         presented by the\n    |                                        |         \"standard\" vimdiff\n    |                MERGED                  |         merge tool\n    |                                        |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  | <TAB #2> |  TAB #3  |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    LOCAL           |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         LOCAL are shown\n    |                   |                    |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  |  TAB #2  | <TAB #3> |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    REMOTE          |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         REMOTE are shown\n    |                   |                    |\n    ------------------------------------------\n\n\nThe motivation behind this was that, for non-trivial merges, the three way diff\npresented in the first tab tends to be very confusing and in these cases\nindividual diffs between BASE and LOCAL and between BASE and REMOTE are very\nuseful.\n\nI have been using a \"custom\" merge tool for months to achieve this same result\nby adding these lines to my .gitconfig file:\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c \\\"4wincmd w | wincmd J | tabnew | edit $LOCAL | vertical diffsplit $BASE | tabnew | edit $REMOTE | vertical diffsplit $BASE | 2tabprevious\\\" \\\"$LOCAL\\\" \\\"$BASE\\\" \\\"$REMOTE\\\" \\\"$MERGED\\\"\n        trustExitCode = true\n\n...and, because I found this \"trick\" very useful, I thought it would be a good\nidea to add it as a git built-in merge tool (called \"vimdiff4\" because  1, 2 and\n3 had already been taken) for everyone to use... and that's exactly what the RFC\nI published did.\n\nNow... as you can see in the RFC thread [1], David and Juno suggested that\nmaybe, instead of creating *yet another vimdiff variant*, we should take this\nopportunity to:\n\n  * Come up with a more general way of defining arbitrary vim layouts.\n  \n  * Re-implement \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" using this new mechanism\n    (after all, the only difference among them is that they present different\n    layouts to the user)\n\n  * Add documentation to all of this.\n\nAnd the result of that work is what I'm presenting today :)\n\nSome things I would like to mention:\n\n  1. There are three commits in this patch series:\n\n     - The first one implements the logic to generate new arbitrary layouts and\n       also re-defines \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" on top of it.\n\n     - The second one adds documentation. It is probably a good idea to start\n       reviewing this commit before the first one!\n\n     - The last commit *is not meant to be merged now*. It removes \"vimdiff1\",\n       \"vimdiff2\" and \"vimdiff3\", which is something that should only be done\n       after one or two releases with a deprecation notice and only if everyone\n       agrees to do so :)\n\n  2. \"mergetools/vimdiff\" is now a ~800 lines bash script, but most of it is\n     documentation (which is embedded in the tool itself for easier maintenance)\n     and unit tests.\n     I have only tested it with bash, but I've tried not to use any command not\n     already being used somewhere else, so I expect it to work in the same\n     places it was working before (however, let me know if there are some shell\n     compatibility requirements and I'll try to check them).\n\n  3. Regarding unit tests, \"mergetool/vimdiff\" contains instructions on how to\n     run them (just call the script without arguments after making changes, to\n     make sure you didn't break anything).\n     Right now it prints \"OK\" on all test cases (obviously) [2]\n\n  3. The \"git {diff,merge}tool --tool-help\" command now also prints the\n     documentation for each tool (instead of just its name, as before).\n     You can see an example of the output here ([3] and [4])\n\nFinally, let me say that, while I like what this patch series achieves, I would\nalso *completely* understand if you decide not to merge it due to being a\ncomplex solution to a simple problem that can be solved (as I had been doing up\nuntil today) by just adding three lines to one's .gitconfig.\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c ...(custom complex sequence of vim commands)...\n        trustExitCode = true\n\nLet me know what you think.\n\nThanks.\n\nReferences:\n\n  [1] https://lore.kernel.org/git/20211019212020.25385-1-greenfoo@u92.eu/#r\n  [2] https://pastebin.com/kuQ5pETG\n  [3] https://pastebin.com/yvLWxeiM\n  [4] https://pastebin.com/qNc7qymp\n\n\nNew in v2:\n\n  * Remove deprecation of vimdiff{1,2,3} (they will remain for backwards\n    compatibility, but built on top of the new generic layout mechanism)\n\n  * Remove unnecessary \"IFS=\"\n\n  * Replace DEBUG --> GIT_MERGETOOL_VIMDIFF_DEBUG\n\n  * Stop using \"local\" (turns out it was not necessary)\n\n  * Stop using bash arrays (use arrays of variables instead)\n\n  * Stop using bash substring expansion (use a new \"substring\" function\n    instead).\n\n  * Refactor some of the internal loops to make the code faster. This was needed\n    because the two previous changes (specially the one where I stop using\n    \"substring expansion\") slowed down the script to a point where I had to wait\n    for a few *seconds* before the \"layout\" string was resolved (recursion +\n    bash forks are a recipe for sluggishness). Fortunately we are back to the\n    low hundreds of milliseconds range.\n\n  * Change markers:\n    - File to save: * --> @\n    - New tab     : ; --> +\n    - Vert split  : | --> ,\n    - Horz split  : - --> /\n\n  * Rewrite examples to use as few parenthesis as possible (typically zero)\n    and better explain operators priority.\n\n  * Other fixes to remove problems reported by \"shellcheck --shell=sh\" (which\n    checks syntax agains the POSIX shell spec)\n\n  * Rename \"index_...\" vars to make more obvious what they do.\n\n  * Use \"$\" inside arithmetic expressions $((...))\n    NOTE: \"shellcheck\" issues a warning stating that \"$\" is not needed inside\n    arithmetic expressions.\n\n  * Use \"test -n\" instead of \"! test -z\"\n\n  * Use \"=\" instead of \"==\" in \"test\"\n\n  * Use \"= 0\" instead of \"-eq 0\"\n\n  * Do not use \"eval\" nor \"--\" when copying a file to MERGED\n\n  * Do not use \"-o\" with grep\n\n  * Use <<-\\EOF instead of <<\\ENDOFMESSAGE and remove extra indent in \"here\n    docs\".\n\n  * Also, let me put here some answers to questions made in the replies to\n    version v1 of this patch set:\n\n    > What do backticks do in here?\n    >\n    >     some_var=(\n    >         `# Name`       \"Rick Deckard\"\n    >         `# Age`        \"Unknown\"\n    >         `# Occupation` \"Blade runner\"\n    >     )\n\n    The backticks execute the code inside, which is a comment (everything after\n    a \"#\" is considered a comment by the shell), thus it does nothing.\n\n    The `# ...` trick can be used to insert inline comments in bash. Another\n    example:\n\n        $ ls -l `# long format` -h `# human readable` *.txt\n\n    In any case, as you can see in this new revision, because I'm no longer\n    using bash arrays, this trick to comment each test case is not needed\n    anymore.\n\n    > Why is \"eval\" needed here:\n    >\n    >     eval \"$merge_tool_path\" \\\n    >              -f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n\n    Variable \"$FINAL_CMD\" contains a string that looks like this:\n\n        $ echo $FINAL_CMD\n        -c \"vim cmd 1 | vim cmd 2 | ...\" -c \"tabfirst\"\n\n    We need to call \"vim\" exactly like that, but if we do this...\n\n         $ vim $FINAL_CMD\n\n    ...then \"vim\" will be excev'ed with the following arguments:\n\n        1. -c\n        2. \"vim\n        3. cmd\n        4. 1\n        ...\n\n    ...instead of the desired scenario:\n\n       1. -c\n       2. cmd 1 | cmd 2 | ...\n       3. -c\n       4. tabfirst\n\n     Using \"eval\" fixes this. A shorter example shows how this works:\n\n         $ A=\"1 \\\"2 3\\\"\"\n\n         $ ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '\"2': No such file or directory\n         ls: cannot access '3\"': No such file or directory\n\n         $ eval ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '2 3': No such file or directory\n\n  * Finally, I think I have addressed all comments to v1 *except for two\n    things*:\n\n        1. Moving the documentation to \"Documentation/\" instead of having it\n           embedded inside the \"mergetools/vimdiff\" script.\n\n        2. Move unit tests to the \"test suit\"\n\n    For (1) I would like more details. Is the idea not to print any\n    documentation when running \"git mergetool --tool-help\" and have all the\n    details included in \"git help mergetool\" instead?\n    Right now \"git help mergetool\" does not mention any tool specific details\n    and, instead, redirects the user to \"git mergetool --tool-help\" (that's why\n    I originally placed the new documentation there).\n    In any case, all the doc has been placed on its own commit, so once we\n    decide how to proceed its just a matter of reverting it.\n\n    For (2) I still need to investigate how this is done and prepare a \"v3\" if\n    needed :)\n\n\nNew in v3:\n\n  * Rebase on top of latest master\n\n  * Documentation moved to \"Documentation/\". Running \"git mergetool\n    --tool-help\" now works like before (ie. it just lists all available merge\n    tools) except that a one line reference to a \"man\" entry is also printed for\n    those entries providing one (right now, only vimdiff):\n\n        $ git mergetool --tool-help\n        'git mergetool --tool=<tool>' may be set to one of the following:\n                        araxis\n                        meld\n                        vimdiff\n                                Run 'man git-mergetool--vimdiff' for details\n                        vimdiff1\n                                Run 'man git-mergetool--vimdiff' for details\n                        ...\n\n  * New test file \"t/7609-mergetool--lib.sh\" created. Right now it only\n    contains one test which calls \"mergetools/vimdiff\" with a special\n    environment set, causing layout unit tests to run.\n\n\nNew in v4:\n\n  * Rebase on top of latest master\n\n  * Stop using \"$\" inside arithmetic expressions.\n\n  * Remove \"!/bin/bash\" from the top of the \"vimdiff\" script.\n\n  * Update comment explaining how the \"vimdiff\" script can be run.\n\n  * Fix spaces/tabs.\n\n  * Change the way unit tests are run (now the script is directly sourced\n    instead of calling bash)\n\n  * Remove unnecessary \"case/esac\" structure.\n\n  * Fix typo in documentation\n\n\nNew in v5:\n\n  * Rebase on top of latest master\n\n\nNew in v6:\n\n  * Syntax corrections (spaces around parenthesis)\n\n  * Fix layout definition of \"vimdiff1\"\n\n  * Make clear how the old behaviour of the different variants (vimdiffN) is\n    tested in the built in unit tests\n\n  * Move doc into a subsection inside \"git help mergetool\"\n\n\nNew in v7:\n\n  * Rebase on top of latest master\n\n  * Fix some comments that had not being updated to reflect the latest changes\n\n  * `git mergetool --tool-help` now shows the information associated to each\n    entry in the same line. It also briefly explains what each variant does.\n\n  * Apply patch from Philippe Blain that fixes HTML formatting (thanks!)\n\n  * Add asccidoc directive to hide references to `git-mergetool` when we are\n    already reading documentation from the `git-mergetool` entry\n\n  * Fix \"Vim\", \"Neovim\", \"gVim\" and \"Git\" capitalization in docs\n\n  * Change double and single quotes into backticks in docs where applicable\n\n  * Fix typos in docs\n\n  * Remove \"mergetool.gvimdiff.layout\" and \"mergetool.nvimdiff.layout\". The\n    only one remaining now is \"mergetool.vimdiff.layout\" which defines the\n    layout in all cases, no matter the vim variant we are using.\n\n  * Remove trailing spaces\n\n  * Only list appropiate variants (\"vimdiff\", \"nvim\" and \"gvim\") when running\n    `git difftool --tool-help`\n\n  * Add a short description to all other (already existing) merge/diff tools\n    (Beyond Compare, xxdiff, etc...)\n\n\nFernando Ramos (4):\n  vimdiff: new implementation with layout support\n  vimdiff: integrate layout tests in the unit tests framework ('t'\n    folder)\n  vimdiff: add tool documentation\n  vimdiff: add description to already existing diff/merge tools\n\n Documentation/config/mergetool.txt   |   9 +\n Documentation/git-mergetool.txt      |   8 +\n Documentation/mergetools/vimdiff.txt | 189 +++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/araxis                    |   8 +\n mergetools/bc                        |   8 +\n mergetools/codecompare               |   8 +\n mergetools/deltawalker               |   8 +\n mergetools/diffmerge                 |   8 +\n mergetools/diffuse                   |   8 +\n mergetools/ecmerge                   |   8 +\n mergetools/emerge                    |   8 +\n mergetools/examdiff                  |   8 +\n mergetools/guiffy                    |   8 +\n mergetools/kdiff3                    |   8 +\n mergetools/kompare                   |   8 +\n mergetools/meld                      |   8 +\n mergetools/opendiff                  |   8 +\n mergetools/p4merge                   |   8 +\n mergetools/smerge                    |   8 +\n mergetools/tkdiff                    |   8 +\n mergetools/tortoisemerge             |   8 +\n mergetools/vimdiff                   | 607 +++++++++++++++++++++++++--\n mergetools/winmerge                  |   8 +\n mergetools/xxdiff                    |   8 +\n t/t7609-mergetool--lib.sh            |  14 +\n 26 files changed, 969 insertions(+), 28 deletions(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n create mode 100755 t/t7609-mergetool--lib.sh\n\n-- \n2.35.1\n\n"},{"id":"452518","messageId":"20220328223019.271270-2-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"[PATCH v7 1/4] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:30:16Z","receivedAt":"2022-03-28T22:30:37Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"When running 'git mergetool -t vimdiff', a new configuration option\n('mergetool.vimdiff.layout') can now be used to select how the user\nwants the different windows, tabs and buffers to be displayed.\n\nIf the option is not provided, the layout will be the same one that was\nbeing used before this commit (ie. two rows with LOCAL, BASE and COMMIT\nin the top one and MERGED in the bottom one).\n\nThe 'vimdiff' variants ('vimdiff{1,2,3}') still work but, because they\nrepresented nothing else than different layouts, are now internally\nimplemented as a subcase of 'vimdiff' with the corresponding\npre-configured 'layout'.\n\nAgain, if you don't set \"mergetool.vimdiff.layout\" everything will work\nthe same as before *but* the arguments used to call {n,g,}vim will be\nothers (even if you don't/shouldn't notice it):\n\n  - git mergetool -t vimdiff\n\n    > Before this commit:\n      {n,g,}vim -f -d -c '4wincmd w | wincmd J' $LOCAL $BASE $REMOTE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff1\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'echon \"...\"' $LOCAL $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff2\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'wincmd l' $LOCAL $MERGED $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff3\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'hid | hid | hid' $LOCAL $REMOTE $BASE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | 4b | bufdo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\nDespite being different, I have manually verified that they generate the same\nlayout as before.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/vimdiff | 558 ++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 529 insertions(+), 29 deletions(-)\n\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 96f6209a04..9d1bf4f455 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -1,49 +1,442 @@\n+# This script can be run in two different contexts:\n+#\n+#   - From git, when the user invokes the \"vimdiff\" merge tool. In this context\n+#     this script expects the following environment variables (among others) to\n+#     be defined (which is something \"git\" takes care of):\n+#\n+#       - $BASE\n+#       - $LOCAL\n+#       - $REMOTE\n+#       - $MERGED\n+#\n+#     In this mode, all this script does is to run the next command:\n+#\n+#         vim -f -c ... $LOCAL $BASE $REMOTE $MERGED\n+#\n+#     ...where the \"...\" string depends on the value of the\n+#     \"mergetool.vimdiff.layout\" configuration variable and is used to open vim\n+#     with a certain layout of buffers, windows and tabs.\n+#\n+#   - From a script inside the unit tests framework folder (\"t\" folder) by\n+#     sourcing this script and then manually calling \"run_unit_tests\", which\n+#     will run a battery of unit tests to make sure nothing breaks.\n+#     In this context this script does not expect any particular environment\n+#     variable to be set.\n+\n+\n+################################################################################\n+## Internal functions (not meant to be used outside this script)\n+################################################################################\n+\n+debug_print () {\n+\t# Send message to stderr if global variable GIT_MERGETOOL_VIMDIFF is set\n+\t# to \"true\"\n+\n+\tif test -n \"$GIT_MERGETOOL_VIMDIFF_DEBUG\"\n+\tthen\n+\t\t>&2 echo \"$@\"\n+\tfi\n+}\n+\n+substring () {\n+\t# Return a substring of $1 containing $3 characters starting at\n+\t# zero-based offset $2.\n+\t#\n+\t# Examples:\n+\t#\n+\t#   substring \"Hello world\" 0 4  --> \"Hell\"\n+\t#   substring \"Hello world\" 3 4  --> \"lo w\"\n+\t#   substring \"Hello world\" 3 10 --> \"lo world\"\n+\n+\tSTRING=$1\n+\tSTART=$2\n+\tLEN=$3\n+\n+\techo \"$STRING\" | cut -c$(( START + 1 ))-$(( START + $LEN ))\n+}\n+\n+gen_cmd_aux () {\n+\t# Auxiliary function used from \"gen_cmd()\".\n+\t# Read that other function documentation for more details.\n+\n+\tLAYOUT=$1\n+\tCMD=$2  # This is a second (hidden) argument used for recursion\n+\n+\tdebug_print\n+\tdebug_print \"LAYOUT    : $LAYOUT\"\n+\tdebug_print \"CMD       : $CMD\"\n+\n+\tif test -z \"$CMD\"\n+\tthen\n+\t\tCMD=\"echo\" # vim \"nop\" operator\n+\tfi\n+\n+\tstart=0\n+\tend=${#LAYOUT}\n+\n+\tnested=0\n+\tnested_min=100\n+\n+\n+\t# Step 1:\n+\t#\n+\t# Increase/decrease \"start\"/\"end\" indices respectively to get rid of\n+\t# outer parenthesis.\n+\t#\n+\t# Example:\n+\t#\n+\t#   - BEFORE: (( LOCAL , BASE ) / MERGED )\n+\t#   - AFTER :  ( LOCAL , BASE ) / MERGED\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(echo \"$LAYOUT\" | sed 's:.:&#:g')\n+\tdo\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" -lt \"$nested_min\"\n+\t\tthen\n+\t\t\tnested_min=$nested\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\tdebug_print \"NESTED MIN: $nested_min\"\n+\n+\twhile test \"$nested_min\" -gt \"0\"\n+\tdo\n+\t\tstart=$(( start + 1 ))\n+\t\tend=$(( end - 1 ))\n+\n+\t\tstart_minus_one=$(( start - 1 ))\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$start_minus_one\" 1)\" = \"(\"\n+\t\tdo\n+\t\t\tstart=$(( start + 1 ))\n+\t\t\tstart_minus_one=$(( start_minus_one + 1 ))\n+\t\tdone\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$end\" 1)\" = \")\"\n+\t\tdo\n+\t\t\tend=$(( end - 1 ))\n+\t\tdone\n+\n+\t\tnested_min=$(( nested_min - 1 ))\n+\tdone\n+\n+\tdebug_print \"CLEAN     : $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\")\"\n+\n+\n+\t# Step 2:\n+\t#\n+\t# Search for all valid separators (\"+\", \"/\" or \",\") which are *not*\n+\t# inside parenthesis. Save the index at which each of them makes the\n+\t# first appearance.\n+\n+\tindex_new_tab=\"\"\n+\tindex_horizontal_split=\"\"\n+\tindex_vertical_split=\"\"\n+\n+\tnested=0\n+\ti=$(( start - 1 ))\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:.:&#:g');\n+\tdo\n+\t\ti=$(( i + 1 ))\n+\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" = 0\n+\t\tthen\n+\t\t\tcurrent=$c\n+\n+\t\t\tif test \"$current\" = \"+\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_new_tab\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_new_tab=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \"/\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_horizontal_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_horizontal_split=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \",\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_vertical_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_vertical_split=$i\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\n+\t# Step 3:\n+\t#\n+\t# Process the separator with the highest order of precedence\n+\t# (\";\" has the highest precedence and \"|\" the lowest one).\n+\t#\n+\t# By \"process\" I mean recursively call this function twice: the first\n+\t# one with the substring at the left of the separator and the second one\n+\t# with the one at its right.\n+\n+\tterminate=\"false\"\n+\n+\tif ! test -z \"$index_new_tab\"\n+\tthen\n+\t\tbefore=\"-tabnew\"\n+\t\tafter=\"tabnext\"\n+\t\tindex=$index_new_tab\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_horizontal_split\"\n+\tthen\n+\t\tbefore=\"split\"\n+\t\tafter=\"wincmd j\"\n+\t\tindex=$index_horizontal_split\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_vertical_split\"\n+\tthen\n+\t\tbefore=\"vertical split\"\n+\t\tafter=\"wincmd l\"\n+\t\tindex=$index_vertical_split\n+\t\tterminate=\"true\"\n+\tfi\n+\n+\tif  test \"$terminate\" = \"true\"\n+\tthen\n+\t\tCMD=\"$CMD | $before\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$start\" \"$(( index - start ))\")\" \"$CMD\")\n+\t\tCMD=\"$CMD | $after\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$(( index + 1 ))\" \"$(( ${#LAYOUT} - index ))\")\" \"$CMD\")\n+\t\techo \"$CMD\"\n+\t\treturn\n+\tfi\n+\n+\n+\t# Step 4:\n+\t#\n+\t# If we reach this point, it means there are no separators and we just\n+\t# need to print the command to display the specified buffer\n+\n+\ttarget=$(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:[ @();|-]::g')\n+\n+\tif test \"$target\" = \"LOCAL\"\n+\tthen\n+\t\tCMD=\"$CMD | 1b\"\n+\n+\telif test \"$target\" = \"BASE\"\n+\tthen\n+\t\tCMD=\"$CMD | 2b\"\n+\n+\telif test \"$target\" = \"REMOTE\"\n+\tthen\n+\t\tCMD=\"$CMD | 3b\"\n+\n+\telif test \"$target\" = \"MERGED\"\n+\tthen\n+\t\tCMD=\"$CMD | 4b\"\n+\n+\telse\n+\t\tCMD=\"$CMD | ERROR: >$target<\"\n+\tfi\n+\n+\techo \"$CMD\"\n+\treturn\n+}\n+\n+\n+gen_cmd () {\n+\t# This function returns (in global variable FINAL_CMD) the string that\n+\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n+\t# layout:\n+\t#\n+\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\t#\n+\t# It takes one single argument: a string containing the desired layout\n+\t# definition.\n+\t#\n+\t# The syntax of the \"layout definitions\" is explained in \"Documentation/\n+\t# mergetools/vimdiff.txt\" but you can already intuitively understand how\n+\t# it works by knowing that...\n+\t#\n+\t#   * \"+\" means \"a new vim tab\"\n+\t#   * \"/\" means \"a new vim horizontal split\"\n+\t#   * \",\" means \"a new vim vertical split\"\n+\t#\n+\t# It also returns (in global variable FINAL_TARGET) the name (\"LOCAL\",\n+\t# \"BASE\", \"REMOTE\" or \"MERGED\") of the file that is marked with an \"@\",\n+\t# or \"MERGED\" if none of them is.\n+\t#\n+\t# Example:\n+\t#\n+\t#     gen_cmd \"@LOCAL , REMOTE\"\n+\t#     |\n+\t#     `-> FINAL_CMD    == \"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\t#         FINAL_TARGET == \"LOCAL\"\n+\n+\tLAYOUT=$1\n+\n+\n+\t# Search for a \"@\" in one of the files identifiers (\"LOCAL\", \"BASE\",\n+\t# \"REMOTE\", \"MERGED\"). If not found, use \"MERGE\" as the default file\n+\t# where changes will be saved.\n+\n+\tif echo \"$LAYOUT\" | grep @LOCAL >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"LOCAL\"\n+\telif echo \"$LAYOUT\" | grep @BASE >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"BASE\"\n+\telse\n+\t\tFINAL_TARGET=\"MERGED\"\n+\tfi\n+\n+\n+\t# Obtain the first part of vim \"-c\" option to obtain the desired layout\n+\n+\tCMD=$(gen_cmd_aux \"$LAYOUT\")\n+\n+\n+\t# Adjust the just obtained script depending on whether more than one\n+\t# windows are visible or not\n+\n+\tif echo \"$LAYOUT\" | grep \",\\|/\" >/dev/null\n+\tthen\n+\t\tCMD=\"$CMD | tabdo windo diffthis\"\n+\telse\n+\t\tCMD=\"$CMD | bufdo diffthis\"\n+\tfi\n+\n+\n+\t# Add an extra \"-c\" option to move to the first tab (notice that we\n+\t# can't simply append the command to the previous \"-c\" string as\n+\t# explained here: https://github.com/vim/vim/issues/9076\n+\n+\tFINAL_CMD=\"-c \\\"$CMD\\\" -c \\\"tabfirst\\\"\"\n+}\n+\n+\n+################################################################################\n+## API functions (called from \"git-mergetool--lib.sh\")\n+################################################################################\n+\n diff_cmd () {\n \t\"$merge_tool_path\" -R -f -d \\\n \t\t-c 'wincmd l' -c 'cd $GIT_PREFIX' \"$LOCAL\" \"$REMOTE\"\n }\n \n+\n merge_cmd () {\n+\tlayout=$(git config mergetool.vimdiff.layout)\n+\n \tcase \"$1\" in\n \t*vimdiff)\n-\t\tif $base_present\n+\t\tif test -z \"$layout\"\n \t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n-\t\t\t\t\"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\t# Default layout when none is specified\n+\t\t\tlayout=\"(LOCAL,BASE,REMOTE)/MERGED\"\n \t\tfi\n \t\t;;\n \t*vimdiff1)\n-\t\t\"$merge_tool_path\" -f -d \\\n-\t\t\t-c 'echon \"Resolve conflicts leftward then save. Use :cq to abort.\"' \\\n-\t\t\t\"$LOCAL\" \"$REMOTE\"\n-\t\tret=\"$?\"\n-\t\tif test \"$ret\" -eq 0\n-\t\tthen\n-\t\t\tcp -- \"$LOCAL\" \"$MERGED\"\n-\t\tfi\n-\t\treturn \"$ret\"\n+\t\tlayout=\"@LOCAL,REMOTE\"\n \t\t;;\n \t*vimdiff2)\n-\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tlayout=\"LOCAL,MERGED,REMOTE\"\n \t\t;;\n \t*vimdiff3)\n-\t\tif $base_present\n-\t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n-\t\tfi\n+\t\tlayout=\"MERGED\"\n \t\t;;\n \tesac\n+\n+\tgen_cmd \"$layout\"\n+\n+\tdebug_print \"\"\n+\tdebug_print \"FINAL CMD : $FINAL_CMD\"\n+\tdebug_print \"FINAL TAR : $FINAL_TARGET\"\n+\n+\tif $base_present\n+\tthen\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\telse\n+\t\t# If there is no BASE (example: a merge conflict in a new file\n+\t\t# with the same name created in both braches which didn't exist\n+\t\t# before), close all BASE windows using vim's \"quit\" command\n+\n+\t\tFINAL_CMD=$(echo \"$FINAL_CMD\" | \\\n+\t\t\tsed -e 's:2b:quit:g' -e 's:3b:2b:g' -e 's:4b:3b:g')\n+\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n+\tfi\n+\n+\tret=\"$?\"\n+\n+\tif test \"$ret\" -eq 0\n+\tthen\n+\t\tcase \"$FINAL_TARGET\" in\n+\t\tLOCAL)\n+\t\t\tsource_path=\"$LOCAL\"\n+\t\t\t;;\n+\t\tREMOTE)\n+\t\t\tsource_path=\"$REMOTE\"\n+\t\t\t;;\n+\t\tMERGED|*)\n+\t\t\t# Do nothing\n+\t\t\tsource_path=\n+\t\t\t;;\n+\t\tesac\n+\n+\t\tif test -n \"$source_path\"\n+\t\tthen\n+\t\t\tcp \"$source_path\" \"$MERGED\"\n+\t\tfi\n+\tfi\n+\n+\treturn \"$ret\"\n }\n \n-translate_merge_tool_path() {\n+\n+translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n \t\techo nvim\n@@ -57,14 +450,121 @@ translate_merge_tool_path() {\n \tesac\n }\n \n+\n exit_code_trustable () {\n \ttrue\n }\n \n+\n list_tool_variants () {\n-\tfor prefix in '' g n; do\n-\t\tfor suffix in '' 1 2 3; do\n-\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\tif test \"$TOOL_MODE\" = \"diff\"\n+\tthen\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\techo \"${prefix}vimdiff\"\n \t\tdone\n+\telse\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\tfor suffix in '' 1 2 3\n+\t\t\tdo\n+\t\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\t\t\tdone\n+\t\tdone\n+\tfi\n+}\n+\n+\n+################################################################################\n+## Unit tests (called from scripts inside the \"t\" folder)\n+################################################################################\n+\n+run_unit_tests () {\n+\t# Function to make sure that we don't break anything when modifying this\n+\t# script.\n+\n+\tNUMBER_OF_TEST_CASES=16\n+\n+\tTEST_CASE_01=\"(LOCAL,BASE,REMOTE)/MERGED\"   # default behaviour\n+\tTEST_CASE_02=\"@LOCAL,REMOTE\"                # when using vimdiff1\n+\tTEST_CASE_03=\"LOCAL,MERGED,REMOTE\"          # when using vimdiff2\n+\tTEST_CASE_04=\"MERGED\"                       # when using vimdiff3\n+\tTEST_CASE_05=\"LOCAL/MERGED/REMOTE\"\n+\tTEST_CASE_06=\"(LOCAL/REMOTE),MERGED\"\n+\tTEST_CASE_07=\"MERGED,(LOCAL/REMOTE)\"\n+\tTEST_CASE_08=\"(LOCAL,REMOTE)/MERGED\"\n+\tTEST_CASE_09=\"MERGED/(LOCAL,REMOTE)\"\n+\tTEST_CASE_10=\"(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_11=\"(LOCAL,BASE,REMOTE)/MERGED+BASE,LOCAL+BASE,REMOTE+(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_12=\"((LOCAL,REMOTE)/BASE),MERGED\"\n+\tTEST_CASE_13=\"((LOCAL,REMOTE)/BASE),((LOCAL/REMOTE),MERGED)\"\n+\tTEST_CASE_14=\"BASE,REMOTE+BASE,LOCAL\"\n+\tTEST_CASE_15=\"  ((  (LOCAL , BASE , REMOTE) / MERGED))   +(BASE)   , LOCAL+ BASE , REMOTE+ (((LOCAL / BASE / REMOTE)) ,    MERGED   )  \"\n+\tTEST_CASE_16=\"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL / BASE / REMOTE),MERGED\"\n+\n+\tEXPECTED_CMD_01=\"-c \\\"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_02=\"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_03=\"-c \\\"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_04=\"-c \\\"echo | 4b | bufdo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_05=\"-c \\\"echo | split | 1b | wincmd j | split | 4b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_06=\"-c \\\"echo | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_07=\"-c \\\"echo | vertical split | 4b | wincmd l | split | 1b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_08=\"-c \\\"echo | split | vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_09=\"-c \\\"echo | split | 4b | wincmd j | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_10=\"-c \\\"echo | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_11=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_12=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_13=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_14=\"-c \\\"echo | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_15=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_16=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\n+\tEXPECTED_TARGET_01=\"MERGED\"\n+\tEXPECTED_TARGET_02=\"LOCAL\"\n+\tEXPECTED_TARGET_03=\"MERGED\"\n+\tEXPECTED_TARGET_04=\"MERGED\"\n+\tEXPECTED_TARGET_05=\"MERGED\"\n+\tEXPECTED_TARGET_06=\"MERGED\"\n+\tEXPECTED_TARGET_07=\"MERGED\"\n+\tEXPECTED_TARGET_08=\"MERGED\"\n+\tEXPECTED_TARGET_09=\"MERGED\"\n+\tEXPECTED_TARGET_10=\"MERGED\"\n+\tEXPECTED_TARGET_11=\"MERGED\"\n+\tEXPECTED_TARGET_12=\"MERGED\"\n+\tEXPECTED_TARGET_13=\"MERGED\"\n+\tEXPECTED_TARGET_14=\"MERGED\"\n+\tEXPECTED_TARGET_15=\"MERGED\"\n+\tEXPECTED_TARGET_16=\"MERGED\"\n+\n+\tat_least_one_ko=\"false\"\n+\n+\tfor i in $(seq -w 1 99)\n+\tdo\n+\t\tif test \"$i\" -gt $NUMBER_OF_TEST_CASES\n+\t\tthen\n+\t\t\tbreak\n+\t\tfi\n+\n+\t\tgen_cmd \"$(eval echo \\${TEST_CASE_\"$i\"})\"\n+\n+\t\tif test \"$FINAL_CMD\" = \"$(eval echo \\${EXPECTED_CMD_\"$i\"})\" \\\n+\t\t\t&& test \"$FINAL_TARGET\" = \"$(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\tthen\n+\t\t\tprintf \"Test Case #%02d: OK\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\telse\n+\t\t\tprintf \"Test Case #%02d: KO !!!!\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\t\techo \"  FINAL_CMD              : $FINAL_CMD\"\n+\t\t\techo \"  FINAL_CMD (expected)   : $(eval echo \\${EXPECTED_CMD_\"$i\"})\"\n+\t\t\techo \"  FINAL_TARGET           : $FINAL_TARGET\"\n+\t\t\techo \"  FINAL_TARGET (expected): $(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\t\tat_least_one_ko=\"true\"\n+\t\tfi\n \tdone\n+\n+\tif test \"$at_least_one_ko\" = \"true\"\n+\tthen\n+\t\treturn 255\n+\telse\n+\t\treturn 0\n+\tfi\n }\n-- \n2.35.1\n\n"},{"id":"452519","messageId":"20220328223019.271270-3-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"[PATCH v7 2/4] vimdiff: integrate layout tests in the unit tests framework ('t' folder)","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:30:17Z","receivedAt":"2022-03-28T22:30:42Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Create a new test case file for the different available merge tools.\nRight now it only tests the 'mergetool.vimdiff.layout' option. Other\nmerge tools might be interested in adding their own tests here too.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n t/t7609-mergetool--lib.sh | 14 ++++++++++++++\n 1 file changed, 14 insertions(+)\n create mode 100755 t/t7609-mergetool--lib.sh\n\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nnew file mode 100755\nindex 0000000000..d848fe6442\n--- /dev/null\n+++ b/t/t7609-mergetool--lib.sh\n@@ -0,0 +1,14 @@\n+#!/bin/sh\n+\n+test_description='git mergetool\n+\n+Testing basic merge tools options'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n+\t. $GIT_BUILD_DIR/mergetools/vimdiff &&\n+\trun_unit_tests\n+'\n+\n+test_done\n-- \n2.35.1\n\n"},{"id":"452520","messageId":"20220328223019.271270-5-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"[PATCH v7 4/4] vimdiff: add description to already existing diff/merge tools","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:30:19Z","receivedAt":"2022-03-28T22:30:53Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"---\n mergetools/araxis        | 8 ++++++++\n mergetools/bc            | 8 ++++++++\n mergetools/codecompare   | 8 ++++++++\n mergetools/deltawalker   | 8 ++++++++\n mergetools/diffmerge     | 8 ++++++++\n mergetools/diffuse       | 8 ++++++++\n mergetools/ecmerge       | 8 ++++++++\n mergetools/emerge        | 8 ++++++++\n mergetools/examdiff      | 8 ++++++++\n mergetools/guiffy        | 8 ++++++++\n mergetools/kdiff3        | 8 ++++++++\n mergetools/kompare       | 8 ++++++++\n mergetools/meld          | 8 ++++++++\n mergetools/opendiff      | 8 ++++++++\n mergetools/p4merge       | 8 ++++++++\n mergetools/smerge        | 8 ++++++++\n mergetools/tkdiff        | 8 ++++++++\n mergetools/tortoisemerge | 8 ++++++++\n mergetools/winmerge      | 8 ++++++++\n mergetools/xxdiff        | 8 ++++++++\n 20 files changed, 160 insertions(+)\n\ndiff --git a/mergetools/araxis b/mergetools/araxis\nindex e2407b65b7..eb32a7da95 100644\n--- a/mergetools/araxis\n+++ b/mergetools/araxis\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -wait -2 \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \techo compare\n }\ndiff --git a/mergetools/bc b/mergetools/bc\nindex 26c19d46a5..2922667ddd 100644\n--- a/mergetools/bc\n+++ b/mergetools/bc\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif type bcomp >/dev/null 2>/dev/null\n \tthen\ndiff --git a/mergetools/codecompare b/mergetools/codecompare\nindex 9f60e8da65..610963d377 100644\n--- a/mergetools/codecompare\n+++ b/mergetools/codecompare\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif merge_mode\n \tthen\ndiff --git a/mergetools/deltawalker b/mergetools/deltawalker\nindex ee6f374bce..efae4c285c 100644\n--- a/mergetools/deltawalker\n+++ b/mergetools/deltawalker\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# Adding $(pwd)/ in front of $MERGED should not be necessary.\n \t# However without it, DeltaWalker (at least v1.9.8 on Windows)\n@@ -16,6 +20,10 @@ merge_cmd () {\n \tfi >/dev/null 2>&1\n }\n \n+merge_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path () {\n \techo DeltaWalker\n }\ndiff --git a/mergetools/diffmerge b/mergetools/diffmerge\nindex 9b6355b98a..9b5b62d1ca 100644\n--- a/mergetools/diffmerge\n+++ b/mergetools/diffmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/diffuse b/mergetools/diffuse\nindex 5a3ae8b569..ebfaba5172 100644\n--- a/mergetools/diffuse\n+++ b/mergetools/diffuse\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,3 +17,7 @@ merge_cmd () {\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\ndiff --git a/mergetools/ecmerge b/mergetools/ecmerge\nindex 6c5101c4f7..0d4d609874 100644\n--- a/mergetools/ecmerge\n+++ b/mergetools/ecmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" --default --mode=diff2 \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t--default --mode=merge2 --to=\"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/emerge b/mergetools/emerge\nindex d1ce513ff5..fc6892cc95 100644\n--- a/mergetools/emerge\n+++ b/mergetools/emerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -f emerge-files-command \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -17,6 +21,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n translate_merge_tool_path() {\n \techo emacs\n }\ndiff --git a/mergetools/examdiff b/mergetools/examdiff\nindex e72b06fc4d..6f53ca9161 100644\n--- a/mergetools/examdiff\n+++ b/mergetools/examdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" -nh\n }\n \n+diff_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -11,6 +15,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"ExamDiff.com\" \"ExamDiff Pro\"\n }\ndiff --git a/mergetools/guiffy b/mergetools/guiffy\nindex 8b23a13c41..3ed07efd16 100644\n--- a/mergetools/guiffy\n+++ b/mergetools/guiffy\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kdiff3 b/mergetools/kdiff3\nindex 520cb914a1..ee8b3a0570 100644\n--- a/mergetools/kdiff3\n+++ b/mergetools/kdiff3\n@@ -4,6 +4,10 @@ diff_cmd () {\n \t\t\"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -22,6 +26,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kompare b/mergetools/kompare\nindex e8c0bfa678..4ce23dbe8b 100644\n--- a/mergetools/kompare\n+++ b/mergetools/kompare\n@@ -2,10 +2,18 @@ can_merge () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+merge_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/meld b/mergetools/meld\nindex aab4ebb935..8ec0867e03 100644\n--- a/mergetools/meld\n+++ b/mergetools/meld\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Meld (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tcheck_meld_for_features\n \n@@ -20,6 +24,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Meld (requires a graphical session) with optional \\`auto merge\\` (see \\`git help mergetool\\`'s \\`CONFIGURATION\\` section)\"\n+}\n+\n # Get meld help message\n init_meld_help_msg () {\n \tif test -z \"$meld_help_msg\"\ndiff --git a/mergetools/opendiff b/mergetools/opendiff\nindex b608dd6de3..44adf8f951 100644\n--- a/mergetools/opendiff\n+++ b/mergetools/opendiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t-merge \"$MERGED\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/p4merge b/mergetools/p4merge\nindex 7a5b291dd2..f3cb197e58 100644\n--- a/mergetools/p4merge\n+++ b/mergetools/p4merge\n@@ -19,6 +19,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif ! $base_present\n \tthen\n@@ -34,3 +38,7 @@ create_empty_file () {\n \n \tprintf \"%s\" \"$empty_file\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/smerge b/mergetools/smerge\nindex 9c2e6f6fd7..5410835a6b 100644\n--- a/mergetools/smerge\n+++ b/mergetools/smerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -10,3 +14,7 @@ merge_cmd () {\n \t\t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tkdiff b/mergetools/tkdiff\nindex eee5cb57e3..66906a720d 100644\n--- a/mergetools/tkdiff\n+++ b/mergetools/tkdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -14,3 +18,7 @@ merge_cmd () {\n exit_code_trustable () {\n \ttrue\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tortoisemerge b/mergetools/tortoisemerge\nindex d7ab666a59..507edcd444 100644\n--- a/mergetools/tortoisemerge\n+++ b/mergetools/tortoisemerge\n@@ -2,6 +2,10 @@ can_diff () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -30,3 +34,7 @@ translate_merge_tool_path() {\n \t\techo tortoisemerge\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/winmerge b/mergetools/winmerge\nindex 74d03259fd..36c72dde6e 100644\n--- a/mergetools/winmerge\n+++ b/mergetools/winmerge\n@@ -3,6 +3,10 @@ diff_cmd () {\n \treturn 0\n }\n \n+diff_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# mergetool.winmerge.trustExitCode is implicitly false.\n \t# touch $BACKUP so that we can check_unchanged.\n@@ -13,3 +17,7 @@ merge_cmd () {\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"WinMergeU.exe\" \"WinMerge\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/xxdiff b/mergetools/xxdiff\nindex d5ce467995..cd205f9842 100644\n--- a/mergetools/xxdiff\n+++ b/mergetools/xxdiff\n@@ -12,6 +12,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -28,3 +32,7 @@ merge_cmd () {\n \t\t\t--merged-file \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n-- \n2.35.1\n\n"},{"id":"452521","messageId":"20220328223019.271270-4-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"[PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:30:18Z","receivedAt":"2022-03-28T22:30:53Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Running 'git {merge,diff}tool --tool-help' now also prints usage\ninformation about the vimdiff tool (and its variantes) instead of just\nits name.\n\nTwo new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\nadded to the set of functions that each merge tool (ie. scripts found\ninside \"mergetools/\") can overwrite to provided tool specific\ninformation.\n\nRight now, only 'mergetools/vimdiff' implements these functions, but\nother tools are encouraged to do so in the future, specially if they\ntake configuration options not explained anywhere else (as it is the\ncase with the 'vimdiff' tool and the new 'layout' option)\n\nIn addition, a section has been added to\n\"Documentation/git-mergetool.txt\" to explain the new \"layout\"\nconfiguration option with examples.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n Documentation/config/mergetool.txt   |   9 ++\n Documentation/git-mergetool.txt      |   8 ++\n Documentation/mergetools/vimdiff.txt | 189 +++++++++++++++++++++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/vimdiff                   |  53 ++++++++\n 5 files changed, 268 insertions(+), 1 deletion(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n\ndiff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\nindex cafbbef46a..13f1b234db 100644\n--- a/Documentation/config/mergetool.txt\n+++ b/Documentation/config/mergetool.txt\n@@ -45,6 +45,15 @@ mergetool.meld.useAutoMerge::\n \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n \tdefault value.\n \n+mergetool.vimdiff.layout::\n+\tThe vimdiff backend uses this variable to control how its split\n+\twindows look like. Applies even if you are using Neovim (`nvim`) or\n+\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n+ifndef::git-mergetool[]\n+\t(on linkgit:git-mergetool[1])\n+endif::[]\n+\tfor details.\n+\n mergetool.hideResolved::\n \tDuring a merge Git will automatically resolve as many conflicts as\n \tpossible and write the 'MERGED' file containing conflict markers around\ndiff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt\nindex e587c7763a..f784027bc1 100644\n--- a/Documentation/git-mergetool.txt\n+++ b/Documentation/git-mergetool.txt\n@@ -101,6 +101,7 @@ success of the resolution after the custom tool has exited.\n \n CONFIGURATION\n -------------\n+:git-mergetool: 1\n include::config/mergetool.txt[]\n \n TEMPORARY FILES\n@@ -113,6 +114,13 @@ Setting the `mergetool.keepBackup` configuration variable to `false`\n causes `git mergetool` to automatically remove the backup as files\n are successfully merged.\n \n+BACKEND SPECIFIC HINTS\n+----------------------\n+\n+vimdiff\n+~~~~~~~\n+include::mergetools/vimdiff.txt[]\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nnew file mode 100644\nindex 0000000000..f63fc48c29\n--- /dev/null\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -0,0 +1,189 @@\n+Description\n+^^^^^^^^^^^\n+\n+When specifying `--tool=vimdiff` in `git mergetool` Git will open Vim with a 4\n+windows layout distributed in the following way:\n+\n+    ------------------------------------------\n+    |             |           |              |\n+    |   LOCAL     |   BASE    |   REMOTE     |\n+    |             |           |              |\n+    ------------------------------------------\n+    |                                        |\n+    |                MERGED                  |\n+    |                                        |\n+    ------------------------------------------\n+\n+`LOCAL`, `BASE` and `REMOTE` are read-only buffers showing the contents of the\n+conflicting file in specific commits (\"commit you are merging into\", \"common\n+ancestor commit\" and \"commit you are merging from\" respectively)\n+\n+`MERGED` is a writable buffer where you have to resolve the conflicts (using the\n+other read-only buffers as a reference). Once you are done, save and exit Vim as\n+usual (`:wq`) or, if you want to abort, exit using `:cq`.\n+\n+Layout configuration\n+^^^^^^^^^^^^^^^^^^^^\n+\n+You can change the windows layout used by Vim by setting configuration variable\n+`mergetool.vimdiff.layout` which accepts a string where the following separators\n+have special meaning:\n+\n+  - `+` is used to \"open a new tab\"\n+  - `,` is used to \"open a new vertical split\"\n+  - `/` is used to \"open a new horizontal split\"\n+  - `@` is used to indicate which is the file containing the final version after\n+    solving the conflicts. If not present, `MERGED` will be used by default.\n+\n+The precedence of the operators is this one (you can use parentheses to change\n+it):\n+\n+    `@` > `+` > `/` > `,`\n+\n+Let's see some examples to understand how it works:\n+\n+* `layout = \"(LOCAL,BASE,REMOTE)/MERGED\"`\n++\n+--\n+This is exactly the same as the default layout we have already seen.\n+\n+Note that `/` has precedence over `,` and thus the parenthesis are not\n+needed in this case. The next layout definition is equivalent:\n+\n+    layout = \"LOCAL,BASE,REMOTE / MERGED\"\n+--\n+* `layout = \"LOCAL,MERGED,REMOTE\"`\n++\n+--\n+If, for some reason, we are not interested in the `BASE` buffer.\n+\n+           ------------------------------------------\n+           |             |           |              |\n+           |             |           |              |\n+           |   LOCAL     |   MERGED  |   REMOTE     |\n+           |             |           |              |\n+           |             |           |              |\n+           ------------------------------------------\n+--\n+* `layout = \"MERGED\"`\n++\n+--\n+Only the `MERGED` buffer will be shown. Note, however, that all the other\n+ones are still loaded in vim, and you can access them with the \"buffers\"\n+command.\n+\n+           ------------------------------------------\n+           |                                        |\n+           |                                        |\n+           |                 MERGED                 |\n+           |                                        |\n+           |                                        |\n+           ------------------------------------------\n+--\n+* `layout = \"@LOCAL,REMOTE\"`\n++\n+--\n+When `MERGED` is not present in the layout, you must \"mark\" one of the\n+buffers with an asterisk. That will become the buffer you need to edit and\n+save after resolving the conflicts.\n+\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     LOCAL         |    REMOTE          |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"`\n++\n+--\n+Three tabs will open: the first one is a copy of the default layout, while\n+the other two only show the differences between (`BASE` and `LOCAL`) and\n+(`BASE` and `REMOTE`) respectively.\n+\n+           ------------------------------------------\n+           | <TAB #1> |  TAB #2  |  TAB #3  |       |\n+           ------------------------------------------\n+           |             |           |              |\n+           |   LOCAL     |   BASE    |   REMOTE     |\n+           |             |           |              |\n+           ------------------------------------------\n+           |                                        |\n+           |                MERGED                  |\n+           |                                        |\n+           ------------------------------------------\n+\n+           ------------------------------------------\n+           |  TAB #1  | <TAB #2> |  TAB #3  |       |\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     BASE          |    LOCAL           |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+\n+           ------------------------------------------\n+           |  TAB #1  |  TAB #2  | <TAB #3> |       |\n+           ------------------------------------------\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           |     BASE          |    REMOTE          |\n+           |                   |                    |\n+           |                   |                    |\n+           |                   |                    |\n+           ------------------------------------------\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"`\n++\n+--\n+Same as the previous example, but adds a fourth tab with the same\n+information as the first tab, with a different layout.\n+\n+           ---------------------------------------------\n+           |  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n+           ---------------------------------------------\n+           |       LOCAL         |                     |\n+           |---------------------|                     |\n+           |       BASE          |        MERGED       |\n+           |---------------------|                     |\n+           |       REMOTE        |                     |\n+           ---------------------------------------------\n+\n+Note how in the third tab definition we need to use parenthesis to make `,`\n+have precedence over `/`.\n+--\n+\n+Variants\n+^^^^^^^^\n+\n+Instead of `--tool=vimdiff`, you can also use one of these other variants:\n+\n+  * `--tool=gvimdiff`, to open gVim instead of Vim.\n+\n+  * `--tool=nvimdiff`, to open Neovim instead of Vim.\n+\n+When using these variants, in order to specify a custom layout you will have to\n+set configuration variables `mergetool.gvimdiff.layout` and\n+`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n+\n+In addition, for backwards compatibility with previous Git versions, you can\n+also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:\n+`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.\n+In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n+`--tool=[g,n,]vimdiff` and setting configuration variable\n+`mergetool.[g,n,]vimdiff.layout` to...\n+\n+  * `x=1`: `\"@LOCAL, REMOTE\"`\n+  * `x=2`: `\"LOCAL, MERGED, REMOTE\"`\n+  * `x=3`: `\"MERGED\"`\n+\n+Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n+MERGED and REMOTE).\n+\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 542a6a75eb..9f99201bcc 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -63,7 +63,7 @@ $(list_tool_variants)\"\n \t\t\t\t\tpreamble=\n \t\t\t\tfi\n \t\t\t\tshown_any=yes\n-\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n+\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n \t\t\tfi\n \t\tdone\n \n@@ -162,10 +162,18 @@ setup_tool () {\n \t\treturn 1\n \t}\n \n+\tdiff_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \tmerge_cmd () {\n \t\treturn 1\n \t}\n \n+\tmerge_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \thide_resolved_enabled () {\n \t\treturn 0\n \t}\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 9d1bf4f455..461a89b6f9 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -365,6 +365,25 @@ diff_cmd () {\n }\n \n \n+diff_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim\"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session)\"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n merge_cmd () {\n \tlayout=$(git config mergetool.vimdiff.layout)\n \n@@ -436,6 +455,40 @@ merge_cmd () {\n }\n \n \n+merge_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim \"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session) \"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim \"\n+\t\t;;\n+\tesac\n+\n+\tcase \"$TOOL\" in\n+\t*1)\n+\t\techo \"with a 2 panes layout (LOCAL and REMOTE)\"\n+\t\t;;\n+\t*2)\n+\t\techo \"with a 3 panes layout (LOCAL, MERGED and REMOTE)\"\n+\t\t;;\n+\t*3)\n+\t\techo \"where only the MERGED file is shown\"\n+\t\t;;\n+\t*)\n+\t\techo \"with a custom layout (see \\`git help mergetool\\`'s \\`BACKEND SPECIFIC HINTS\\` section)\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n-- \n2.35.1\n\n"},{"id":"452522","messageId":"YkI5Afkyr9H6teMw@zacax395.localdomain","threadId":"57629","inReplyTo":"20220328223019.271270-4-greenfoo@u92.eu","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-28T22:39:08Z","receivedAt":"2022-03-28T22:39:18Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"When applying this patch I still get \"indent with spaces\" errors:\n\n    .git/rebase-apply/patch:121: indent with spaces.\n               ------------------------------------------\n    .git/rebase-apply/patch:122: indent with spaces.\n               |             |           |              |\n    .git/rebase-apply/patch:123: indent with spaces.\n               |             |           |              |\n    .git/rebase-apply/patch:124: indent with spaces.\n               |   LOCAL     |   MERGED  |   REMOTE     |\n    .git/rebase-apply/patch:125: indent with spaces.\n               |             |           |              |\n    warning: squelched 61 whitespace errors\n    warning: 66 lines add whitespace errors.\n\nThe thing is these are no real errors (I really want to use spaces here).\n\nAm I doing something wrong?\n"},{"id":"452539","messageId":"xmqqy20ty3k6.fsf@gitster.g","threadId":"57629","inReplyTo":"YkI5Afkyr9H6teMw@zacax395.localdomain","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-29T01:01:45Z","receivedAt":"2022-03-29T01:01:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Ramos <greenfoo@u92.eu> writes:\n\n> When applying this patch I still get \"indent with spaces\" errors:\n>\n>     .git/rebase-apply/patch:121: indent with spaces.\n>                ------------------------------------------\n>     .git/rebase-apply/patch:122: indent with spaces.\n>                |             |           |              |\n>     .git/rebase-apply/patch:123: indent with spaces.\n>                |             |           |              |\n>     .git/rebase-apply/patch:124: indent with spaces.\n>                |   LOCAL     |   MERGED  |   REMOTE     |\n>     .git/rebase-apply/patch:125: indent with spaces.\n>                |             |           |              |\n>     warning: squelched 61 whitespace errors\n>     warning: 66 lines add whitespace errors.\n>\n> The thing is these are no real errors (I really want to use spaces here).\n>\n> Am I doing something wrong?\n\nYes, the project does not want you to use spaces here.  Doesn't\nAsciiDoc do the right thing if you used a tab instead of indenting\nwith 8 spaces?\n"},{"id":"452559","messageId":"20220329125400.63337-1-levraiphilippeblain@gmail.com","threadId":"57629","inReplyTo":"xmqqy20ty3k6.fsf@gitster.g","subject":"[PATCH] fixup! vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T12:54:00Z","receivedAt":"2022-03-29T12:55:34Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n\nHi Junio, Fernando,\n\nI think the canonical Asciidoc way would be to use a listing block\n(start and end the block with '----', and not indenting the lines\nat all, as is done in a few places in the docs), but in this case\nthe parser gets confused about the several dashes in the content of\nthe block. So we can use a \"literal block\" instead [1].\n\n[1] https://docs.asciidoctor.org/asciidoc/latest/verbatim/literal-blocks/\n\n Documentation/mergetools/vimdiff.txt | 174 ++++++++++++++-------------\n 1 file changed, 90 insertions(+), 84 deletions(-)\n\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nindex f63fc48c29..1cc9c133f9 100644\n--- a/Documentation/mergetools/vimdiff.txt\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -3,17 +3,17 @@ Description\n \n When specifying `--tool=vimdiff` in `git mergetool` Git will open Vim with a 4\n windows layout distributed in the following way:\n-\n-    ------------------------------------------\n-    |             |           |              |\n-    |   LOCAL     |   BASE    |   REMOTE     |\n-    |             |           |              |\n-    ------------------------------------------\n-    |                                        |\n-    |                MERGED                  |\n-    |                                        |\n-    ------------------------------------------\n-\n+....\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n `LOCAL`, `BASE` and `REMOTE` are read-only buffers showing the contents of the\n conflicting file in specific commits (\"commit you are merging into\", \"common\n ancestor commit\" and \"commit you are merging from\" respectively)\n@@ -56,14 +56,15 @@ needed in this case. The next layout definition is equivalent:\n +\n --\n If, for some reason, we are not interested in the `BASE` buffer.\n-\n-           ------------------------------------------\n-           |             |           |              |\n-           |             |           |              |\n-           |   LOCAL     |   MERGED  |   REMOTE     |\n-           |             |           |              |\n-           |             |           |              |\n-           ------------------------------------------\n+....\n+------------------------------------------\n+|             |           |              |\n+|             |           |              |\n+|   LOCAL     |   MERGED  |   REMOTE     |\n+|             |           |              |\n+|             |           |              |\n+------------------------------------------\n+....\n --\n * `layout = \"MERGED\"`\n +\n@@ -71,14 +72,15 @@ If, for some reason, we are not interested in the `BASE` buffer.\n Only the `MERGED` buffer will be shown. Note, however, that all the other\n ones are still loaded in vim, and you can access them with the \"buffers\"\n command.\n-\n-           ------------------------------------------\n-           |                                        |\n-           |                                        |\n-           |                 MERGED                 |\n-           |                                        |\n-           |                                        |\n-           ------------------------------------------\n+....\n+------------------------------------------\n+|                                        |\n+|                                        |\n+|                 MERGED                 |\n+|                                        |\n+|                                        |\n+------------------------------------------\n+....\n --\n * `layout = \"@LOCAL,REMOTE\"`\n +\n@@ -86,16 +88,17 @@ command.\n When `MERGED` is not present in the layout, you must \"mark\" one of the\n buffers with an asterisk. That will become the buffer you need to edit and\n save after resolving the conflicts.\n-\n-           ------------------------------------------\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           |     LOCAL         |    REMOTE          |\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           ------------------------------------------\n+....\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     LOCAL         |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n --\n * `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"`\n +\n@@ -103,59 +106,62 @@ save after resolving the conflicts.\n Three tabs will open: the first one is a copy of the default layout, while\n the other two only show the differences between (`BASE` and `LOCAL`) and\n (`BASE` and `REMOTE`) respectively.\n-\n-           ------------------------------------------\n-           | <TAB #1> |  TAB #2  |  TAB #3  |       |\n-           ------------------------------------------\n-           |             |           |              |\n-           |   LOCAL     |   BASE    |   REMOTE     |\n-           |             |           |              |\n-           ------------------------------------------\n-           |                                        |\n-           |                MERGED                  |\n-           |                                        |\n-           ------------------------------------------\n-\n-           ------------------------------------------\n-           |  TAB #1  | <TAB #2> |  TAB #3  |       |\n-           ------------------------------------------\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           |     BASE          |    LOCAL           |\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           ------------------------------------------\n-\n-           ------------------------------------------\n-           |  TAB #1  |  TAB #2  | <TAB #3> |       |\n-           ------------------------------------------\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           |     BASE          |    REMOTE          |\n-           |                   |                    |\n-           |                   |                    |\n-           |                   |                    |\n-           ------------------------------------------\n+....\n+------------------------------------------\n+| <TAB #1> |  TAB #2  |  TAB #3  |       |\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  | <TAB #2> |  TAB #3  |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    LOCAL           |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  |  TAB #2  | <TAB #3> |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n --\n * `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"`\n +\n --\n Same as the previous example, but adds a fourth tab with the same\n information as the first tab, with a different layout.\n-\n-           ---------------------------------------------\n-           |  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n-           ---------------------------------------------\n-           |       LOCAL         |                     |\n-           |---------------------|                     |\n-           |       BASE          |        MERGED       |\n-           |---------------------|                     |\n-           |       REMOTE        |                     |\n-           ---------------------------------------------\n-\n+....\n+---------------------------------------------\n+|  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n+---------------------------------------------\n+|       LOCAL         |                     |\n+|---------------------|                     |\n+|       BASE          |        MERGED       |\n+|---------------------|                     |\n+|       REMOTE        |                     |\n+---------------------------------------------\n+....\n Note how in the third tab definition we need to use parenthesis to make `,`\n have precedence over `/`.\n --\n-- \n2.29.2\n\n"},{"id":"452572","messageId":"1bc25dd7-fca6-eab9-c850-3dc2b2dc9e8c@gmail.com","threadId":"57629","inReplyTo":"20220328223019.271270-4-greenfoo@u92.eu","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T14:07:34Z","receivedAt":"2022-03-29T14:07:42Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-28 à 18:30, Fernando Ramos a écrit :\n> Running 'git {merge,diff}tool --tool-help' now also prints usage\n> information about the vimdiff tool (and its variantes) instead of just\n> its name.\n> \n> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n> added to the set of functions that each merge tool (ie. scripts found\n> inside \"mergetools/\") can overwrite to provided tool specific\n> information.\n> \n> Right now, only 'mergetools/vimdiff' implements these functions, but\n> other tools are encouraged to do so in the future, specially if they\n> take configuration options not explained anywhere else (as it is the\n> case with the 'vimdiff' tool and the new 'layout' option)\n> \n> In addition, a section has been added to\n> \"Documentation/git-mergetool.txt\" to explain the new \"layout\"\n> configuration option with examples.\n> \n> Signed-off-by: Fernando Ramos <greenfoo@u92.eu>\n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n\nThanks :) I think the project convention is to also use the \n'Co-authored-by' trailer as well :) \n\n> ---\n>  Documentation/config/mergetool.txt   |   9 ++\n>  Documentation/git-mergetool.txt      |   8 ++\n>  Documentation/mergetools/vimdiff.txt | 189 +++++++++++++++++++++++++++\n>  git-mergetool--lib.sh                |  10 +-\n>  mergetools/vimdiff                   |  53 ++++++++\n>  5 files changed, 268 insertions(+), 1 deletion(-)\n>  create mode 100644 Documentation/mergetools/vimdiff.txt\n> \n> diff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\n> index cafbbef46a..13f1b234db 100644\n> --- a/Documentation/config/mergetool.txt\n> +++ b/Documentation/config/mergetool.txt\n> @@ -45,6 +45,15 @@ mergetool.meld.useAutoMerge::\n>  \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n>  \tdefault value.\n>  \n> +mergetool.vimdiff.layout::\n> +\tThe vimdiff backend uses this variable to control how its split\n> +\twindows look like. Applies even if you are using Neovim (`nvim`) or\n> +\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n> +ifndef::git-mergetool[]\n> +\t(on linkgit:git-mergetool[1])\n\nsmall nit: \"in linkgit:git-mergetool[1]\" would read slightly better I think,\nbut that may be just me... and I think I would drop the parentheses.\n\n> +endif::[]\n> +\tfor details.\n> +\n\n> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\n> index 542a6a75eb..9f99201bcc 100644\n> --- a/git-mergetool--lib.sh\n> +++ b/git-mergetool--lib.sh\n> @@ -63,7 +63,7 @@ $(list_tool_variants)\"\n>  \t\t\t\t\tpreamble=\n>  \t\t\t\tfi\n>  \t\t\t\tshown_any=yes\n> -\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n> +\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n>  \t\t\tfi\n\nI tried this and it looks much better on a single line, nice!\n\nI also noticed that the list of available tools is embedded in 'git help config'\n(see the rule for \"mergetools-list.made\" in Documentation/Makefile). I looked \nat the generated 'git-config.html' and it is not ideal; it would be better if \nthe tool names would be enclosed in backticks. I tried the following tweak:\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex ed656db2ae..a2201680a2 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -333,10 +333,10 @@ mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n \t$(QUIET_GEN) \\\n \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n+\t\tshow_tool_names can_diff \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-diff.txt && \\\n \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n+\t\tshow_tool_names can_merge \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-merge.txt && \\\n \tdate >$@\n \n TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\n\n\nand it mostly works, though with the Asciidoc HTML backend, \"emerge\" is not correctly\nformatted, I get:\n\n‘emerge`: Use Emacs’ Emerge\n\nand in the man page the backticks are kept litereally.It works correctly \nwith Asciidoctor though, both in HTML and man page ...\n"},{"id":"452573","messageId":"374f45ff-ca55-780c-3b26-8b7c6a761725@gmail.com","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"Re: [PATCH v7 0/4] vimdiff: new implementation with layout support","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T14:10:15Z","receivedAt":"2022-03-29T14:10:21Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-28 à 18:30, Fernando Ramos a écrit :\n> Original cover letter (see v7 changes at the end):\n> \n\nJust a small suggestion, it is customary on this list\nto send later versions of a series as a reply to the cover\nletter of the previous iteration. This keeps the whole series\nin a single thread, and also allows tools like 'b4' [1] to apply\nthe latest iteration when given any message-id in the thread.\n\nCheers,\nPhilippe.\n\n\n[1] https://pypi.org/project/b4/\n"},{"id":"452579","messageId":"xmqqtubgwxsq.fsf@gitster.g","threadId":"57629","inReplyTo":"20220329125400.63337-1-levraiphilippeblain@gmail.com","subject":"Re: [PATCH] fixup! vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-29T16:03:49Z","receivedAt":"2022-03-29T16:03:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n> ---\n>\n> Hi Junio, Fernando,\n>\n> I think the canonical Asciidoc way would be to use a listing block\n> (start and end the block with '----', and not indenting the lines\n> at all, as is done in a few places in the docs), but in this case\n> the parser gets confused about the several dashes in the content of\n> the block. So we can use a \"literal block\" instead [1].\n>\n> [1] https://docs.asciidoctor.org/asciidoc/latest/verbatim/literal-blocks/\n\nThanks, will queue on top (without squashing) for now, expecting\nthat Fernando may want to send in another round of updates (and if\nit turns out that this is the only fix-up we need, then we can just\nsquash it in later before merging the topic to 'next').\n\n"},{"id":"452581","messageId":"xmqqmth8wwcf.fsf@gitster.g","threadId":"57629","inReplyTo":"1bc25dd7-fca6-eab9-c850-3dc2b2dc9e8c@gmail.com","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-29T16:35:12Z","receivedAt":"2022-03-29T16:35:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n>> Running 'git {merge,diff}tool --tool-help' now also prints usage\n>> information about the vimdiff tool (and its variantes) instead of just\n>> its name.\n>> \n>> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n>> added to the set of functions that each merge tool (ie. scripts found\n>> inside \"mergetools/\") can overwrite to provided tool specific\n>> information.\n>> \n>> Right now, only 'mergetools/vimdiff' implements these functions, but\n>> other tools are encouraged to do so in the future, specially if they\n>> take configuration options not explained anywhere else (as it is the\n>> case with the 'vimdiff' tool and the new 'layout' option)\n>> \n>> In addition, a section has been added to\n>> \"Documentation/git-mergetool.txt\" to explain the new \"layout\"\n>> configuration option with examples.\n>> \n>> Signed-off-by: Fernando Ramos <greenfoo@u92.eu>\n>> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n>\n> Thanks :) I think the project convention is to also use the \n> 'Co-authored-by' trailer as well :) \n\nIf co-authors closely worked together (possibly but not necessarily\noutside the public view), exchanging drafts and agreeing on the\nfinal version before sending it to the list, by one approving the\nother's final draft, Co-authored-by may be appropriate.\n\nI am not sure if that is what happened.\n\nI would prefer to see more use of Helped-by when suggestions for\nimprovements were made, possibly but not necessarily in a concrete\n\"squashable patch\" form, the original author accepted before sending\nthe new version out, and the party who made suggestions saw the\nupdated version at the same time as the general public.\n\nIn addition, especially if it was not co-authored, the chain of\nsign-off should mirror how the patches flowed.  If philippe helped\nto improve Fernando's original idea, and Fernando assembled this\nversion before sending it out to the list, then \n\n    Helped-by: Philippe\n    Signed-off-by: Philippe\n    Signed-off-by: Fernando\n\nPhilippe's sign-off would help when his contribution is so big that\nit by itself makes a copyrightable work, which may be the case.  If\nnot (e.g. when pointing out trivial typo or grammo), it is simpler\nto omit it.\n\nIf this were truly co-authored, then replace \"Helped-by\" in the\nabove sequence with \"Co-authored-by\".\n\n>> +mergetool.vimdiff.layout::\n>> +\tThe vimdiff backend uses this variable to control how its split\n>> +\twindows look like. Applies even if you are using Neovim (`nvim`) or\n>> +\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n>> +ifndef::git-mergetool[]\n>> +\t(on linkgit:git-mergetool[1])\n>\n> small nit: \"in linkgit:git-mergetool[1]\" would read slightly better I think,\n> but that may be just me... and I think I would drop the parentheses.\n\nI agree on both counts.\n\n>>  \t\t\t\tshown_any=yes\n>> -\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n>> +\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n>>  \t\t\tfi\n>\n> I tried this and it looks much better on a single line, nice!\n\nYou mean that the output on a single line is better than multiple lines?\n\n> I also noticed that the list of available tools is embedded in 'git help config'\n> (see the rule for \"mergetools-list.made\" in Documentation/Makefile). I looked \n> at the generated 'git-config.html' and it is not ideal; it would be better if \n> the tool names would be enclosed in backticks. I tried the following tweak:\n>\n> diff --git a/Documentation/Makefile b/Documentation/Makefile\n> index ed656db2ae..a2201680a2 100644\n> --- a/Documentation/Makefile\n> +++ b/Documentation/Makefile\n> @@ -333,10 +333,10 @@ mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n>  \t$(QUIET_GEN) \\\n>  \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n>  \t\t. ../git-mergetool--lib.sh && \\\n> -\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n> +\t\tshow_tool_names can_diff \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-diff.txt && \\\n\nIf you are piping the output into a sed command, then you discard\nthe exit status of the upstream of the pipe, so \" || :\" at the end\nof the shell command can be discarded, no?\n\n>  \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n>  \t\t. ../git-mergetool--lib.sh && \\\n> -\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n> +\t\tshow_tool_names can_merge \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-merge.txt && \\\n>  \tdate >$@\n\nDitto.\n\nIn any case, the raw output from the command are of the form\n\n    * <name of the tool> <explanation>\n\nIs the idea that you want to enclose the <name of the tool> part\ninside `literal`?\n\nI do not know if the inclusion of <explanation> part in the output\nis sensible in the first place (without this series, we only showed\nthe possible values, right), but if we wanted to do this, shouldn't\nwe be doing, instead of doing\n\n    * araxis\tUse Araxis Merge\n\nmore like\n\n    araxis;;\n\t\tUse Araxis\n\nI wonder.  The logical structure of each line is unclear with the\ncurrent output (the asterisk is meaningful in that it tells that the\nline is an item in a bulleted list, but among the words on the rest\nof the line, the first line is special only by convention, so in a\nmanpage for example, it looks like a gramatically correct sentence\n\"Use Araxis Merge\" is somehow prefixed by a stray word that does not\nbegin with uppercase).\n\n"},{"id":"452582","messageId":"xmqqh77gww6c.fsf@gitster.g","threadId":"57629","inReplyTo":"20220328223019.271270-5-greenfoo@u92.eu","subject":"Re: [PATCH v7 4/4] vimdiff: add description to already existing diff/merge tools","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-29T16:38:51Z","receivedAt":"2022-03-29T16:38:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Ramos <greenfoo@u92.eu> writes:\n\n> ---\n\nMissing log message and sign off.  \"add description\" tells us what\nit did, which is easily visible in the patch text already.  The log\nmessage should say why we are adding them, and the rationale has to\nbe better than \"adding is better than not adding\".  E.g. \"in output\nof X and Y, we only show the names without explanation on what they\nare, which is not helpful enough\" would be a helpful log message.\n\nDoesn't the change in [3/4] to include these strings in generated\nmergetools-*.txt file depend on this in place?\n\nThanks.\n"},{"id":"452586","messageId":"d0a0d00b-5c1a-4a0c-a91c-b03403578f80@gmail.com","threadId":"57629","inReplyTo":"xmqqmth8wwcf.fsf@gitster.g","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T17:08:30Z","receivedAt":"2022-03-29T17:08:46Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Junio,\n\nLe 2022-03-29 à 12:35, Junio C Hamano a écrit :\n> Philippe Blain <levraiphilippeblain@gmail.com> writes:\n> \n>>> Running 'git {merge,diff}tool --tool-help' now also prints usage\n>>> information about the vimdiff tool (and its variantes) instead of just\n>>> its name.\n>>>\n>>> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n>>> added to the set of functions that each merge tool (ie. scripts found\n>>> inside \"mergetools/\") can overwrite to provided tool specific\n>>> information.\n>>>\n>>> Right now, only 'mergetools/vimdiff' implements these functions, but\n>>> other tools are encouraged to do so in the future, specially if they\n>>> take configuration options not explained anywhere else (as it is the\n>>> case with the 'vimdiff' tool and the new 'layout' option)\n>>>\n>>> In addition, a section has been added to\n>>> \"Documentation/git-mergetool.txt\" to explain the new \"layout\"\n>>> configuration option with examples.\n>>>\n>>> Signed-off-by: Fernando Ramos <greenfoo@u92.eu>\n>>> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n>>\n>> Thanks :) I think the project convention is to also use the \n>> 'Co-authored-by' trailer as well :) \n> \n> If co-authors closely worked together (possibly but not necessarily\n> outside the public view), exchanging drafts and agreeing on the\n> final version before sending it to the list, by one approving the\n> other's final draft, Co-authored-by may be appropriate.\n> \n> I am not sure if that is what happened.\n> \n> I would prefer to see more use of Helped-by when suggestions for\n> improvements were made, possibly but not necessarily in a concrete\n> \"squashable patch\" form, the original author accepted before sending\n> the new version out, and the party who made suggestions saw the\n> updated version at the same time as the general public.\n> \n> In addition, especially if it was not co-authored, the chain of\n> sign-off should mirror how the patches flowed.  If philippe helped\n> to improve Fernando's original idea, and Fernando assembled this\n> version before sending it out to the list, then \n> \n>     Helped-by: Philippe\n>     Signed-off-by: Philippe\n>     Signed-off-by: Fernando\n> \n> Philippe's sign-off would help when his contribution is so big that\n> it by itself makes a copyrightable work, which may be the case.  If\n> not (e.g. when pointing out trivial typo or grammo), it is simpler\n> to omit it.\n> \n> If this were truly co-authored, then replace \"Helped-by\" in the\n> above sequence with \"Co-authored-by\".\n\nThanks for clarifying all that (whatever happened to the \"Mailing\nlist etiquette series [1]... it would be nice to revive this:).\n\nI did not mean to \"claim\" co-authorship by the way, I agree that \n\"Helped-by\" is more appropriate in this case. I included my sign-off\nmostly by accident as my 'ci' Git alias in this project is 'commit --sign-off' ;)\n\n> \n>>> +mergetool.vimdiff.layout::\n>>> +\tThe vimdiff backend uses this variable to control how its split\n>>> +\twindows look like. Applies even if you are using Neovim (`nvim`) or\n>>> +\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n>>> +ifndef::git-mergetool[]\n>>> +\t(on linkgit:git-mergetool[1])\n>>\n>> small nit: \"in linkgit:git-mergetool[1]\" would read slightly better I think,\n>> but that may be just me... and I think I would drop the parentheses.\n> \n> I agree on both counts.\n> \n>>>  \t\t\t\tshown_any=yes\n>>> -\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n>>> +\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n>>>  \t\t\tfi\n>>\n>> I tried this and it looks much better on a single line, nice!\n> \n> You mean that the output on a single line is better than multiple lines?\n\nYes.\n\n> \n>> I also noticed that the list of available tools is embedded in 'git help config'\n>> (see the rule for \"mergetools-list.made\" in Documentation/Makefile). I looked \n>> at the generated 'git-config.html' and it is not ideal; it would be better if \n>> the tool names would be enclosed in backticks. I tried the following tweak:\n>>\n>> diff --git a/Documentation/Makefile b/Documentation/Makefile\n>> index ed656db2ae..a2201680a2 100644\n>> --- a/Documentation/Makefile\n>> +++ b/Documentation/Makefile\n>> @@ -333,10 +333,10 @@ mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n>>  \t$(QUIET_GEN) \\\n>>  \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n>>  \t\t. ../git-mergetool--lib.sh && \\\n>> -\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n>> +\t\tshow_tool_names can_diff \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-diff.txt && \\\n> \n> If you are piping the output into a sed command, then you discard\n> the exit status of the upstream of the pipe, so \" || :\" at the end\n> of the shell command can be discarded, no?\n\nYes, you are right.\n\n> \n>>  \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n>>  \t\t. ../git-mergetool--lib.sh && \\\n>> -\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n>> +\t\tshow_tool_names can_merge \"* \" || :' | sed -e \"s/* \\([a-z0-9]*\\)/* \\`\\1\\`:/\" >mergetools-merge.txt && \\\n>>  \tdate >$@\n> \n> Ditto.\n> \n> In any case, the raw output from the command are of the form\n> \n>     * <name of the tool> <explanation>\n> \n> Is the idea that you want to enclose the <name of the tool> part\n> inside `literal`?\n\nYes, exactly, and add ': ' after the name of the tool. This makes the\nHTML doc for 'git-config' more nicely formatted.\n\n> \n> I do not know if the inclusion of <explanation> part in the output\n> is sensible in the first place (without this series, we only showed\n> the possible values, right), \n\nRight. I think it is a very nice addition, as several mergetool \"names\"\nare not the same as the program name or the executable name, so I think\nit's nice for the user to spell out exactly which software we are refering\nto :) \n\n> but if we wanted to do this, shouldn't\n> we be doing, instead of doing\n> \n>     * araxis\tUse Araxis Merge\n> \n> more like\n> \n>     araxis;;\n> \t\tUse Araxis\n> \n> I wonder.  The logical structure of each line is unclear with the\n> current output (the asterisk is meaningful in that it tells that the\n> line is an item in a bulleted list, but among the words on the rest\n> of the line, the first line is special only by convention, so in a\n> manpage for example, it looks like a gramatically correct sentence\n> \"Use Araxis Merge\" is somehow prefixed by a stray word that does not\n> begin with uppercase).\n> \n\nOK, I see you mean using an Asciidoc \"description list\" [2]. I agree \nwith you that it would be more semantically correct. So, let's use this\ninstead:\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex ed656db2ae..de0b5fed42 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -333,10 +333,10 @@ mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n \t$(QUIET_GEN) \\\n \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n+\t\tshow_tool_names can_diff' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-diff.txt && \\\n \t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n+\t\tshow_tool_names can_merge' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-merge.txt && \\\n \tdate >$@\n \n TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\n\n[1] https://lore.kernel.org/git/20210512233412.10737-1-dwh@linuxprogrammer.org/\n[2] https://docs.asciidoctor.org/asciidoc/latest/lists/description/\n"},{"id":"452589","messageId":"f56a7a0b-8525-c4cc-7bc7-5ac4bba59206@gmail.com","threadId":"57629","inReplyTo":"xmqqh77gww6c.fsf@gitster.g","subject":"Re: [PATCH v7 4/4] vimdiff: add description to already existing diff/merge tools","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T17:24:25Z","receivedAt":"2022-03-29T17:24:33Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Junio, Fernando,\n\nLe 2022-03-29 à 12:38, Junio C Hamano a écrit :\n> Fernando Ramos <greenfoo@u92.eu> writes:\n> \n>> ---\n> \n> Missing log message and sign off.  \"add description\" tells us what\n> it did, which is easily visible in the patch text already.  The log\n> message should say why we are adding them, and the rationale has to\n> be better than \"adding is better than not adding\".  E.g. \"in output\n> of X and Y, we only show the names without explanation on what they\n> are, which is not helpful enough\" would be a helpful log message.\n\nI might add that the prefix of the commit message title should be changed\nto 'mergetools: ' \n\n> \n> Doesn't the change in [3/4] to include these strings in generated\n> mergetools-*.txt file depend on this in place?\n> \n> Thanks.\n> \n\nThe list of available values are already generated in the  mergetools-diff.txt and\nmergetools-merge.txt files before this series. After 3/4 we also\ninclude the description of the values. In 3/4 descriptions are only added for\nvimdiff and friends, so the rest of the tools would simply be listed without \ndescriptions. After 4/4 all tools have a description.\n"},{"id":"452591","messageId":"1363db57-74de-226a-468f-69feffde6ba5@gmail.com","threadId":"57629","inReplyTo":"20220328223019.271270-4-greenfoo@u92.eu","subject":"Re: [PATCH v7 3/4] vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-29T17:29:52Z","receivedAt":"2022-03-29T17:29:57Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-28 à 18:30, Fernando Ramos a écrit :\n> +\n> diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\n> index 542a6a75eb..9f99201bcc 100644\n> --- a/git-mergetool--lib.sh\n> +++ b/git-mergetool--lib.sh\n> @@ -63,7 +63,7 @@ $(list_tool_variants)\"\n>  \t\t\t\t\tpreamble=\n>  \t\t\t\tfi\n>  \t\t\t\tshown_any=yes\n> -\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n> +\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n>  \t\t\tfi\n>  \t\tdone\n>  \n\nWhile responding to Junio I tried removing the definition of\n'diff_cmd_help' for araxis and it is still listed as \"Use Araxis\"\nin the list of values under \"merge.guitool\" in git-config.{1,html}.\n\nI think that \"diff_mode\" that you use in the command substitution does\nnot work for our usage in the documentation Makefile, as in that case\nTOOL_MODE is not defined. So a more complete tweak to the Makefile\nwould be:\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex ed656db2ae..c2667de7b3 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -331,12 +331,12 @@ $(mergetools_txt): mergetools-list.made\n \n mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n \t$(QUIET_GEN) \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=diff && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t\tshow_tool_names can_diff' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-diff.txt && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=merge && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n+\t\tshow_tool_names can_merge' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-merge.txt && \\\n \tdate >$@\n \n TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\n"},{"id":"452596","messageId":"xmqqmth8twxr.fsf@gitster.g","threadId":"57629","inReplyTo":"f56a7a0b-8525-c4cc-7bc7-5ac4bba59206@gmail.com","subject":"Re: [PATCH v7 4/4] vimdiff: add description to already existing diff/merge tools","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-03-29T18:50:40Z","receivedAt":"2022-03-29T18:50:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n> Hi Junio, Fernando,\n>\n> Le 2022-03-29 à 12:38, Junio C Hamano a écrit :\n>> Fernando Ramos <greenfoo@u92.eu> writes:\n>> \n>>> ---\n>> \n>> Missing log message and sign off.  \"add description\" tells us what\n>> it did, which is easily visible in the patch text already.  The log\n>> message should say why we are adding them, and the rationale has to\n>> be better than \"adding is better than not adding\".  E.g. \"in output\n>> of X and Y, we only show the names without explanation on what they\n>> are, which is not helpful enough\" would be a helpful log message.\n>\n> I might add that the prefix of the commit message title should be changed\n> to 'mergetools: ' \n>\n>> \n>> Doesn't the change in [3/4] to include these strings in generated\n>> mergetools-*.txt file depend on this in place?\n>> \n>> Thanks.\n>> \n>\n> The list of available values are already generated in the  mergetools-diff.txt and\n> mergetools-merge.txt files before this series. After 3/4 we also\n> include the description of the values. In 3/4 descriptions are only added for\n> vimdiff and friends, so the rest of the tools would simply be listed without \n> descriptions. After 4/4 all tools have a description.\n\nOK.  I wonder how that affects our discussion to switch to the\ndescription list?  This adds what appears as the description.\nBefore this step, it would be <dl>...</dl> inside which <dt> appears\nbut not <dd>.\n"},{"id":"452608","messageId":"YkN95Lj/WjGilTTy@zacax395.localdomain","threadId":"57629","inReplyTo":"374f45ff-ca55-780c-3b26-8b7c6a761725@gmail.com","subject":"Re: [PATCH v7 0/4] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T21:45:08Z","receivedAt":"2022-03-29T21:45:22Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> Just a small suggestion, it is customary on this list\n> to send later versions of a series as a reply to the cover\n> letter of the previous iteration. This keeps the whole series\n> in a single thread, and also allows tools like 'b4' [1] to apply\n> the latest iteration when given any message-id in the thread.\n\nThanks, I really appreciate this.\n\nIt's really hard to find the correct way to interact with different mailing\nlists from different projects.\n\nMaybe a monitoring bot could send an email with all the mailing list rules to\nsomeone sending a message for the first time?\n"},{"id":"452615","messageId":"YkOKrNMpOgfxTTWa@zacax395.localdomain","threadId":"57629","inReplyTo":"xmqqmth8twxr.fsf@gitster.g","subject":"Re: [PATCH v7 4/4] vimdiff: add description to already existing diff/merge tools","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:39:40Z","receivedAt":"2022-03-29T22:39:49Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"I'll prepare v8 with all the previously discussed changes so that we can\ncontinue the discussion there :)\n\n"},{"id":"452617","messageId":"20220329224439.290948-1-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220328223019.271270-1-greenfoo@u92.eu","subject":"[PATCH v8 0/5] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:34Z","receivedAt":"2022-03-29T22:44:48Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Original cover letter (see v8 changes at the end):\n\nA few weeks ago I presented this RFC [1] where I introduced a new variant of the\nvimdiff merge tool (\"vimdiff4\") that creates three tabs (instead of just one)\nthat look like this:\n\n    ------------------------------------------\n    | <TAB #1> |  TAB #2  |  TAB #3  |       |\n    ------------------------------------------\n    |             |           |              |\n    |   LOCAL     |   BASE    |   REMOTE     |\n    |             |           |              |   <---- Same information\n    ------------------------------------------         presented by the\n    |                                        |         \"standard\" vimdiff\n    |                MERGED                  |         merge tool\n    |                                        |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  | <TAB #2> |  TAB #3  |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    LOCAL           |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         LOCAL are shown\n    |                   |                    |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  |  TAB #2  | <TAB #3> |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    REMOTE          |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         REMOTE are shown\n    |                   |                    |\n    ------------------------------------------\n\n\nThe motivation behind this was that, for non-trivial merges, the three way diff\npresented in the first tab tends to be very confusing and in these cases\nindividual diffs between BASE and LOCAL and between BASE and REMOTE are very\nuseful.\n\nI have been using a \"custom\" merge tool for months to achieve this same result\nby adding these lines to my .gitconfig file:\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c \\\"4wincmd w | wincmd J | tabnew | edit $LOCAL | vertical diffsplit $BASE | tabnew | edit $REMOTE | vertical diffsplit $BASE | 2tabprevious\\\" \\\"$LOCAL\\\" \\\"$BASE\\\" \\\"$REMOTE\\\" \\\"$MERGED\\\"\n        trustExitCode = true\n\n...and, because I found this \"trick\" very useful, I thought it would be a good\nidea to add it as a git built-in merge tool (called \"vimdiff4\" because  1, 2 and\n3 had already been taken) for everyone to use... and that's exactly what the RFC\nI published did.\n\nNow... as you can see in the RFC thread [1], David and Juno suggested that\nmaybe, instead of creating *yet another vimdiff variant*, we should take this\nopportunity to:\n\n  * Come up with a more general way of defining arbitrary vim layouts.\n  \n  * Re-implement \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" using this new mechanism\n    (after all, the only difference among them is that they present different\n    layouts to the user)\n\n  * Add documentation to all of this.\n\nAnd the result of that work is what I'm presenting today :)\n\nSome things I would like to mention:\n\n  1. There are three commits in this patch series:\n\n     - The first one implements the logic to generate new arbitrary layouts and\n       also re-defines \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" on top of it.\n\n     - The second one adds documentation. It is probably a good idea to start\n       reviewing this commit before the first one!\n\n     - The last commit *is not meant to be merged now*. It removes \"vimdiff1\",\n       \"vimdiff2\" and \"vimdiff3\", which is something that should only be done\n       after one or two releases with a deprecation notice and only if everyone\n       agrees to do so :)\n\n  2. \"mergetools/vimdiff\" is now a ~800 lines bash script, but most of it is\n     documentation (which is embedded in the tool itself for easier maintenance)\n     and unit tests.\n     I have only tested it with bash, but I've tried not to use any command not\n     already being used somewhere else, so I expect it to work in the same\n     places it was working before (however, let me know if there are some shell\n     compatibility requirements and I'll try to check them).\n\n  3. Regarding unit tests, \"mergetool/vimdiff\" contains instructions on how to\n     run them (just call the script without arguments after making changes, to\n     make sure you didn't break anything).\n     Right now it prints \"OK\" on all test cases (obviously) [2]\n\n  3. The \"git {diff,merge}tool --tool-help\" command now also prints the\n     documentation for each tool (instead of just its name, as before).\n     You can see an example of the output here ([3] and [4])\n\nFinally, let me say that, while I like what this patch series achieves, I would\nalso *completely* understand if you decide not to merge it due to being a\ncomplex solution to a simple problem that can be solved (as I had been doing up\nuntil today) by just adding three lines to one's .gitconfig.\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c ...(custom complex sequence of vim commands)...\n        trustExitCode = true\n\nLet me know what you think.\n\nThanks.\n\nReferences:\n\n  [1] https://lore.kernel.org/git/20211019212020.25385-1-greenfoo@u92.eu/#r\n  [2] https://pastebin.com/kuQ5pETG\n  [3] https://pastebin.com/yvLWxeiM\n  [4] https://pastebin.com/qNc7qymp\n\n\nNew in v2:\n\n  * Remove deprecation of vimdiff{1,2,3} (they will remain for backwards\n    compatibility, but built on top of the new generic layout mechanism)\n\n  * Remove unnecessary \"IFS=\"\n\n  * Replace DEBUG --> GIT_MERGETOOL_VIMDIFF_DEBUG\n\n  * Stop using \"local\" (turns out it was not necessary)\n\n  * Stop using bash arrays (use arrays of variables instead)\n\n  * Stop using bash substring expansion (use a new \"substring\" function\n    instead).\n\n  * Refactor some of the internal loops to make the code faster. This was needed\n    because the two previous changes (specially the one where I stop using\n    \"substring expansion\") slowed down the script to a point where I had to wait\n    for a few *seconds* before the \"layout\" string was resolved (recursion +\n    bash forks are a recipe for sluggishness). Fortunately we are back to the\n    low hundreds of milliseconds range.\n\n  * Change markers:\n    - File to save: * --> @\n    - New tab     : ; --> +\n    - Vert split  : | --> ,\n    - Horz split  : - --> /\n\n  * Rewrite examples to use as few parenthesis as possible (typically zero)\n    and better explain operators priority.\n\n  * Other fixes to remove problems reported by \"shellcheck --shell=sh\" (which\n    checks syntax agains the POSIX shell spec)\n\n  * Rename \"index_...\" vars to make more obvious what they do.\n\n  * Use \"$\" inside arithmetic expressions $((...))\n    NOTE: \"shellcheck\" issues a warning stating that \"$\" is not needed inside\n    arithmetic expressions.\n\n  * Use \"test -n\" instead of \"! test -z\"\n\n  * Use \"=\" instead of \"==\" in \"test\"\n\n  * Use \"= 0\" instead of \"-eq 0\"\n\n  * Do not use \"eval\" nor \"--\" when copying a file to MERGED\n\n  * Do not use \"-o\" with grep\n\n  * Use <<-\\EOF instead of <<\\ENDOFMESSAGE and remove extra indent in \"here\n    docs\".\n\n  * Also, let me put here some answers to questions made in the replies to\n    version v1 of this patch set:\n\n    > What do backticks do in here?\n    >\n    >     some_var=(\n    >         `# Name`       \"Rick Deckard\"\n    >         `# Age`        \"Unknown\"\n    >         `# Occupation` \"Blade runner\"\n    >     )\n\n    The backticks execute the code inside, which is a comment (everything after\n    a \"#\" is considered a comment by the shell), thus it does nothing.\n\n    The `# ...` trick can be used to insert inline comments in bash. Another\n    example:\n\n        $ ls -l `# long format` -h `# human readable` *.txt\n\n    In any case, as you can see in this new revision, because I'm no longer\n    using bash arrays, this trick to comment each test case is not needed\n    anymore.\n\n    > Why is \"eval\" needed here:\n    >\n    >     eval \"$merge_tool_path\" \\\n    >              -f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n\n    Variable \"$FINAL_CMD\" contains a string that looks like this:\n\n        $ echo $FINAL_CMD\n        -c \"vim cmd 1 | vim cmd 2 | ...\" -c \"tabfirst\"\n\n    We need to call \"vim\" exactly like that, but if we do this...\n\n         $ vim $FINAL_CMD\n\n    ...then \"vim\" will be excev'ed with the following arguments:\n\n        1. -c\n        2. \"vim\n        3. cmd\n        4. 1\n        ...\n\n    ...instead of the desired scenario:\n\n       1. -c\n       2. cmd 1 | cmd 2 | ...\n       3. -c\n       4. tabfirst\n\n     Using \"eval\" fixes this. A shorter example shows how this works:\n\n         $ A=\"1 \\\"2 3\\\"\"\n\n         $ ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '\"2': No such file or directory\n         ls: cannot access '3\"': No such file or directory\n\n         $ eval ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '2 3': No such file or directory\n\n  * Finally, I think I have addressed all comments to v1 *except for two\n    things*:\n\n        1. Moving the documentation to \"Documentation/\" instead of having it\n           embedded inside the \"mergetools/vimdiff\" script.\n\n        2. Move unit tests to the \"test suit\"\n\n    For (1) I would like more details. Is the idea not to print any\n    documentation when running \"git mergetool --tool-help\" and have all the\n    details included in \"git help mergetool\" instead?\n    Right now \"git help mergetool\" does not mention any tool specific details\n    and, instead, redirects the user to \"git mergetool --tool-help\" (that's why\n    I originally placed the new documentation there).\n    In any case, all the doc has been placed on its own commit, so once we\n    decide how to proceed its just a matter of reverting it.\n\n    For (2) I still need to investigate how this is done and prepare a \"v3\" if\n    needed :)\n\n\nNew in v3:\n\n  * Rebase on top of latest master\n\n  * Documentation moved to \"Documentation/\". Running \"git mergetool\n    --tool-help\" now works like before (ie. it just lists all available merge\n    tools) except that a one line reference to a \"man\" entry is also printed for\n    those entries providing one (right now, only vimdiff):\n\n        $ git mergetool --tool-help\n        'git mergetool --tool=<tool>' may be set to one of the following:\n                        araxis\n                        meld\n                        vimdiff\n                                Run 'man git-mergetool--vimdiff' for details\n                        vimdiff1\n                                Run 'man git-mergetool--vimdiff' for details\n                        ...\n\n  * New test file \"t/7609-mergetool--lib.sh\" created. Right now it only\n    contains one test which calls \"mergetools/vimdiff\" with a special\n    environment set, causing layout unit tests to run.\n\n\nNew in v4:\n\n  * Rebase on top of latest master\n\n  * Stop using \"$\" inside arithmetic expressions.\n\n  * Remove \"!/bin/bash\" from the top of the \"vimdiff\" script.\n\n  * Update comment explaining how the \"vimdiff\" script can be run.\n\n  * Fix spaces/tabs.\n\n  * Change the way unit tests are run (now the script is directly sourced\n    instead of calling bash)\n\n  * Remove unnecessary \"case/esac\" structure.\n\n  * Fix typo in documentation\n\n\nNew in v5:\n\n  * Rebase on top of latest master\n\n\nNew in v6:\n\n  * Syntax corrections (spaces around parenthesis)\n\n  * Fix layout definition of \"vimdiff1\"\n\n  * Make clear how the old behaviour of the different variants (vimdiffN) is\n    tested in the built in unit tests\n\n  * Move doc into a subsection inside \"git help mergetool\"\n\n\nNew in v7:\n\n  * Rebase on top of latest master\n\n  * Fix some comments that had not being updated to reflect the latest changes\n\n  * `git mergetool --tool-help` now shows the information associated to each\n    entry in the same line. It also briefly explains what each variant does.\n\n  * Apply patch from Philippe Blain that fixes HTML formatting (thanks!)\n\n  * Add asccidoc directive to hide references to `git-mergetool` when we are\n    already reading documentation from the `git-mergetool` entry\n\n  * Fix \"Vim\", \"Neovim\", \"gVim\" and \"Git\" capitalization in docs\n\n  * Change double and single quotes into backticks in docs where applicable\n\n  * Fix typos in docs\n\n  * Remove \"mergetool.gvimdiff.layout\" and \"mergetool.nvimdiff.layout\". The\n    only one remaining now is \"mergetool.vimdiff.layout\" which defines the\n    layout in all cases, no matter the vim variant we are using.\n\n  * Remove trailing spaces\n\n  * Only list appropiate variants (\"vimdiff\", \"nvim\" and \"gvim\") when running\n    `git difftool --tool-help`\n\n  * Add a short description to all other (already existing) merge/diff tools\n    (Beyond Compare, xxdiff, etc...)\n\n\nNew in v8:\n\n  * Rebase on top of latest master\n\n  * Remove spaces from indented blocks of documentation\n\n  * Fix missing commit message in one of the commits\n\n  * Added \"Helped-by\" signature to the doc commit\n\n  * Change sentence in docs to make it syntactically correct\n\n  * Add commit from Philippe Blain to also print the tool description when\n    running ` git help config` (thanks!)\n\nFernando Ramos (5):\n  vimdiff: new implementation with layout support\n  vimdiff: integrate layout tests in the unit tests framework ('t'\n    folder)\n  vimdiff: add tool documentation\n  mergetools: add description to all diff/merge tools\n  mergetools: add tools description to `git help config`\n\n Documentation/Makefile               |   8 +-\n Documentation/config/mergetool.txt   |   9 +\n Documentation/git-mergetool.txt      |   8 +\n Documentation/mergetools/vimdiff.txt | 194 +++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/araxis                    |   8 +\n mergetools/bc                        |   8 +\n mergetools/codecompare               |   8 +\n mergetools/deltawalker               |   8 +\n mergetools/diffmerge                 |   8 +\n mergetools/diffuse                   |   8 +\n mergetools/ecmerge                   |   8 +\n mergetools/emerge                    |   8 +\n mergetools/examdiff                  |   8 +\n mergetools/guiffy                    |   8 +\n mergetools/kdiff3                    |   8 +\n mergetools/kompare                   |   8 +\n mergetools/meld                      |   8 +\n mergetools/opendiff                  |   8 +\n mergetools/p4merge                   |   8 +\n mergetools/smerge                    |   8 +\n mergetools/tkdiff                    |   8 +\n mergetools/tortoisemerge             |   8 +\n mergetools/vimdiff                   | 607 +++++++++++++++++++++++++--\n mergetools/winmerge                  |   8 +\n mergetools/xxdiff                    |   8 +\n t/t7609-mergetool--lib.sh            |  14 +\n 27 files changed, 978 insertions(+), 32 deletions(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n create mode 100755 t/t7609-mergetool--lib.sh\n\n-- \n2.35.1\n\n"},{"id":"452618","messageId":"20220329224439.290948-2-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v8 1/5] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:35Z","receivedAt":"2022-03-29T22:44:55Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"When running 'git mergetool -t vimdiff', a new configuration option\n('mergetool.vimdiff.layout') can now be used to select how the user\nwants the different windows, tabs and buffers to be displayed.\n\nIf the option is not provided, the layout will be the same one that was\nbeing used before this commit (ie. two rows with LOCAL, BASE and COMMIT\nin the top one and MERGED in the bottom one).\n\nThe 'vimdiff' variants ('vimdiff{1,2,3}') still work but, because they\nrepresented nothing else than different layouts, are now internally\nimplemented as a subcase of 'vimdiff' with the corresponding\npre-configured 'layout'.\n\nAgain, if you don't set \"mergetool.vimdiff.layout\" everything will work\nthe same as before *but* the arguments used to call {n,g,}vim will be\nothers (even if you don't/shouldn't notice it):\n\n  - git mergetool -t vimdiff\n\n    > Before this commit:\n      {n,g,}vim -f -d -c '4wincmd w | wincmd J' $LOCAL $BASE $REMOTE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff1\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'echon \"...\"' $LOCAL $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff2\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'wincmd l' $LOCAL $MERGED $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff3\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'hid | hid | hid' $LOCAL $REMOTE $BASE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | 4b | bufdo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\nDespite being different, I have manually verified that they generate the same\nlayout as before.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/vimdiff | 558 ++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 529 insertions(+), 29 deletions(-)\n\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 96f6209a04..9d1bf4f455 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -1,49 +1,442 @@\n+# This script can be run in two different contexts:\n+#\n+#   - From git, when the user invokes the \"vimdiff\" merge tool. In this context\n+#     this script expects the following environment variables (among others) to\n+#     be defined (which is something \"git\" takes care of):\n+#\n+#       - $BASE\n+#       - $LOCAL\n+#       - $REMOTE\n+#       - $MERGED\n+#\n+#     In this mode, all this script does is to run the next command:\n+#\n+#         vim -f -c ... $LOCAL $BASE $REMOTE $MERGED\n+#\n+#     ...where the \"...\" string depends on the value of the\n+#     \"mergetool.vimdiff.layout\" configuration variable and is used to open vim\n+#     with a certain layout of buffers, windows and tabs.\n+#\n+#   - From a script inside the unit tests framework folder (\"t\" folder) by\n+#     sourcing this script and then manually calling \"run_unit_tests\", which\n+#     will run a battery of unit tests to make sure nothing breaks.\n+#     In this context this script does not expect any particular environment\n+#     variable to be set.\n+\n+\n+################################################################################\n+## Internal functions (not meant to be used outside this script)\n+################################################################################\n+\n+debug_print () {\n+\t# Send message to stderr if global variable GIT_MERGETOOL_VIMDIFF is set\n+\t# to \"true\"\n+\n+\tif test -n \"$GIT_MERGETOOL_VIMDIFF_DEBUG\"\n+\tthen\n+\t\t>&2 echo \"$@\"\n+\tfi\n+}\n+\n+substring () {\n+\t# Return a substring of $1 containing $3 characters starting at\n+\t# zero-based offset $2.\n+\t#\n+\t# Examples:\n+\t#\n+\t#   substring \"Hello world\" 0 4  --> \"Hell\"\n+\t#   substring \"Hello world\" 3 4  --> \"lo w\"\n+\t#   substring \"Hello world\" 3 10 --> \"lo world\"\n+\n+\tSTRING=$1\n+\tSTART=$2\n+\tLEN=$3\n+\n+\techo \"$STRING\" | cut -c$(( START + 1 ))-$(( START + $LEN ))\n+}\n+\n+gen_cmd_aux () {\n+\t# Auxiliary function used from \"gen_cmd()\".\n+\t# Read that other function documentation for more details.\n+\n+\tLAYOUT=$1\n+\tCMD=$2  # This is a second (hidden) argument used for recursion\n+\n+\tdebug_print\n+\tdebug_print \"LAYOUT    : $LAYOUT\"\n+\tdebug_print \"CMD       : $CMD\"\n+\n+\tif test -z \"$CMD\"\n+\tthen\n+\t\tCMD=\"echo\" # vim \"nop\" operator\n+\tfi\n+\n+\tstart=0\n+\tend=${#LAYOUT}\n+\n+\tnested=0\n+\tnested_min=100\n+\n+\n+\t# Step 1:\n+\t#\n+\t# Increase/decrease \"start\"/\"end\" indices respectively to get rid of\n+\t# outer parenthesis.\n+\t#\n+\t# Example:\n+\t#\n+\t#   - BEFORE: (( LOCAL , BASE ) / MERGED )\n+\t#   - AFTER :  ( LOCAL , BASE ) / MERGED\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(echo \"$LAYOUT\" | sed 's:.:&#:g')\n+\tdo\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" -lt \"$nested_min\"\n+\t\tthen\n+\t\t\tnested_min=$nested\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\tdebug_print \"NESTED MIN: $nested_min\"\n+\n+\twhile test \"$nested_min\" -gt \"0\"\n+\tdo\n+\t\tstart=$(( start + 1 ))\n+\t\tend=$(( end - 1 ))\n+\n+\t\tstart_minus_one=$(( start - 1 ))\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$start_minus_one\" 1)\" = \"(\"\n+\t\tdo\n+\t\t\tstart=$(( start + 1 ))\n+\t\t\tstart_minus_one=$(( start_minus_one + 1 ))\n+\t\tdone\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$end\" 1)\" = \")\"\n+\t\tdo\n+\t\t\tend=$(( end - 1 ))\n+\t\tdone\n+\n+\t\tnested_min=$(( nested_min - 1 ))\n+\tdone\n+\n+\tdebug_print \"CLEAN     : $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\")\"\n+\n+\n+\t# Step 2:\n+\t#\n+\t# Search for all valid separators (\"+\", \"/\" or \",\") which are *not*\n+\t# inside parenthesis. Save the index at which each of them makes the\n+\t# first appearance.\n+\n+\tindex_new_tab=\"\"\n+\tindex_horizontal_split=\"\"\n+\tindex_vertical_split=\"\"\n+\n+\tnested=0\n+\ti=$(( start - 1 ))\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:.:&#:g');\n+\tdo\n+\t\ti=$(( i + 1 ))\n+\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" = 0\n+\t\tthen\n+\t\t\tcurrent=$c\n+\n+\t\t\tif test \"$current\" = \"+\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_new_tab\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_new_tab=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \"/\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_horizontal_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_horizontal_split=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \",\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_vertical_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_vertical_split=$i\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\n+\t# Step 3:\n+\t#\n+\t# Process the separator with the highest order of precedence\n+\t# (\";\" has the highest precedence and \"|\" the lowest one).\n+\t#\n+\t# By \"process\" I mean recursively call this function twice: the first\n+\t# one with the substring at the left of the separator and the second one\n+\t# with the one at its right.\n+\n+\tterminate=\"false\"\n+\n+\tif ! test -z \"$index_new_tab\"\n+\tthen\n+\t\tbefore=\"-tabnew\"\n+\t\tafter=\"tabnext\"\n+\t\tindex=$index_new_tab\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_horizontal_split\"\n+\tthen\n+\t\tbefore=\"split\"\n+\t\tafter=\"wincmd j\"\n+\t\tindex=$index_horizontal_split\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_vertical_split\"\n+\tthen\n+\t\tbefore=\"vertical split\"\n+\t\tafter=\"wincmd l\"\n+\t\tindex=$index_vertical_split\n+\t\tterminate=\"true\"\n+\tfi\n+\n+\tif  test \"$terminate\" = \"true\"\n+\tthen\n+\t\tCMD=\"$CMD | $before\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$start\" \"$(( index - start ))\")\" \"$CMD\")\n+\t\tCMD=\"$CMD | $after\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$(( index + 1 ))\" \"$(( ${#LAYOUT} - index ))\")\" \"$CMD\")\n+\t\techo \"$CMD\"\n+\t\treturn\n+\tfi\n+\n+\n+\t# Step 4:\n+\t#\n+\t# If we reach this point, it means there are no separators and we just\n+\t# need to print the command to display the specified buffer\n+\n+\ttarget=$(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:[ @();|-]::g')\n+\n+\tif test \"$target\" = \"LOCAL\"\n+\tthen\n+\t\tCMD=\"$CMD | 1b\"\n+\n+\telif test \"$target\" = \"BASE\"\n+\tthen\n+\t\tCMD=\"$CMD | 2b\"\n+\n+\telif test \"$target\" = \"REMOTE\"\n+\tthen\n+\t\tCMD=\"$CMD | 3b\"\n+\n+\telif test \"$target\" = \"MERGED\"\n+\tthen\n+\t\tCMD=\"$CMD | 4b\"\n+\n+\telse\n+\t\tCMD=\"$CMD | ERROR: >$target<\"\n+\tfi\n+\n+\techo \"$CMD\"\n+\treturn\n+}\n+\n+\n+gen_cmd () {\n+\t# This function returns (in global variable FINAL_CMD) the string that\n+\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n+\t# layout:\n+\t#\n+\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\t#\n+\t# It takes one single argument: a string containing the desired layout\n+\t# definition.\n+\t#\n+\t# The syntax of the \"layout definitions\" is explained in \"Documentation/\n+\t# mergetools/vimdiff.txt\" but you can already intuitively understand how\n+\t# it works by knowing that...\n+\t#\n+\t#   * \"+\" means \"a new vim tab\"\n+\t#   * \"/\" means \"a new vim horizontal split\"\n+\t#   * \",\" means \"a new vim vertical split\"\n+\t#\n+\t# It also returns (in global variable FINAL_TARGET) the name (\"LOCAL\",\n+\t# \"BASE\", \"REMOTE\" or \"MERGED\") of the file that is marked with an \"@\",\n+\t# or \"MERGED\" if none of them is.\n+\t#\n+\t# Example:\n+\t#\n+\t#     gen_cmd \"@LOCAL , REMOTE\"\n+\t#     |\n+\t#     `-> FINAL_CMD    == \"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\t#         FINAL_TARGET == \"LOCAL\"\n+\n+\tLAYOUT=$1\n+\n+\n+\t# Search for a \"@\" in one of the files identifiers (\"LOCAL\", \"BASE\",\n+\t# \"REMOTE\", \"MERGED\"). If not found, use \"MERGE\" as the default file\n+\t# where changes will be saved.\n+\n+\tif echo \"$LAYOUT\" | grep @LOCAL >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"LOCAL\"\n+\telif echo \"$LAYOUT\" | grep @BASE >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"BASE\"\n+\telse\n+\t\tFINAL_TARGET=\"MERGED\"\n+\tfi\n+\n+\n+\t# Obtain the first part of vim \"-c\" option to obtain the desired layout\n+\n+\tCMD=$(gen_cmd_aux \"$LAYOUT\")\n+\n+\n+\t# Adjust the just obtained script depending on whether more than one\n+\t# windows are visible or not\n+\n+\tif echo \"$LAYOUT\" | grep \",\\|/\" >/dev/null\n+\tthen\n+\t\tCMD=\"$CMD | tabdo windo diffthis\"\n+\telse\n+\t\tCMD=\"$CMD | bufdo diffthis\"\n+\tfi\n+\n+\n+\t# Add an extra \"-c\" option to move to the first tab (notice that we\n+\t# can't simply append the command to the previous \"-c\" string as\n+\t# explained here: https://github.com/vim/vim/issues/9076\n+\n+\tFINAL_CMD=\"-c \\\"$CMD\\\" -c \\\"tabfirst\\\"\"\n+}\n+\n+\n+################################################################################\n+## API functions (called from \"git-mergetool--lib.sh\")\n+################################################################################\n+\n diff_cmd () {\n \t\"$merge_tool_path\" -R -f -d \\\n \t\t-c 'wincmd l' -c 'cd $GIT_PREFIX' \"$LOCAL\" \"$REMOTE\"\n }\n \n+\n merge_cmd () {\n+\tlayout=$(git config mergetool.vimdiff.layout)\n+\n \tcase \"$1\" in\n \t*vimdiff)\n-\t\tif $base_present\n+\t\tif test -z \"$layout\"\n \t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n-\t\t\t\t\"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\t# Default layout when none is specified\n+\t\t\tlayout=\"(LOCAL,BASE,REMOTE)/MERGED\"\n \t\tfi\n \t\t;;\n \t*vimdiff1)\n-\t\t\"$merge_tool_path\" -f -d \\\n-\t\t\t-c 'echon \"Resolve conflicts leftward then save. Use :cq to abort.\"' \\\n-\t\t\t\"$LOCAL\" \"$REMOTE\"\n-\t\tret=\"$?\"\n-\t\tif test \"$ret\" -eq 0\n-\t\tthen\n-\t\t\tcp -- \"$LOCAL\" \"$MERGED\"\n-\t\tfi\n-\t\treturn \"$ret\"\n+\t\tlayout=\"@LOCAL,REMOTE\"\n \t\t;;\n \t*vimdiff2)\n-\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tlayout=\"LOCAL,MERGED,REMOTE\"\n \t\t;;\n \t*vimdiff3)\n-\t\tif $base_present\n-\t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n-\t\tfi\n+\t\tlayout=\"MERGED\"\n \t\t;;\n \tesac\n+\n+\tgen_cmd \"$layout\"\n+\n+\tdebug_print \"\"\n+\tdebug_print \"FINAL CMD : $FINAL_CMD\"\n+\tdebug_print \"FINAL TAR : $FINAL_TARGET\"\n+\n+\tif $base_present\n+\tthen\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\telse\n+\t\t# If there is no BASE (example: a merge conflict in a new file\n+\t\t# with the same name created in both braches which didn't exist\n+\t\t# before), close all BASE windows using vim's \"quit\" command\n+\n+\t\tFINAL_CMD=$(echo \"$FINAL_CMD\" | \\\n+\t\t\tsed -e 's:2b:quit:g' -e 's:3b:2b:g' -e 's:4b:3b:g')\n+\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n+\tfi\n+\n+\tret=\"$?\"\n+\n+\tif test \"$ret\" -eq 0\n+\tthen\n+\t\tcase \"$FINAL_TARGET\" in\n+\t\tLOCAL)\n+\t\t\tsource_path=\"$LOCAL\"\n+\t\t\t;;\n+\t\tREMOTE)\n+\t\t\tsource_path=\"$REMOTE\"\n+\t\t\t;;\n+\t\tMERGED|*)\n+\t\t\t# Do nothing\n+\t\t\tsource_path=\n+\t\t\t;;\n+\t\tesac\n+\n+\t\tif test -n \"$source_path\"\n+\t\tthen\n+\t\t\tcp \"$source_path\" \"$MERGED\"\n+\t\tfi\n+\tfi\n+\n+\treturn \"$ret\"\n }\n \n-translate_merge_tool_path() {\n+\n+translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n \t\techo nvim\n@@ -57,14 +450,121 @@ translate_merge_tool_path() {\n \tesac\n }\n \n+\n exit_code_trustable () {\n \ttrue\n }\n \n+\n list_tool_variants () {\n-\tfor prefix in '' g n; do\n-\t\tfor suffix in '' 1 2 3; do\n-\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\tif test \"$TOOL_MODE\" = \"diff\"\n+\tthen\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\techo \"${prefix}vimdiff\"\n \t\tdone\n+\telse\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\tfor suffix in '' 1 2 3\n+\t\t\tdo\n+\t\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\t\t\tdone\n+\t\tdone\n+\tfi\n+}\n+\n+\n+################################################################################\n+## Unit tests (called from scripts inside the \"t\" folder)\n+################################################################################\n+\n+run_unit_tests () {\n+\t# Function to make sure that we don't break anything when modifying this\n+\t# script.\n+\n+\tNUMBER_OF_TEST_CASES=16\n+\n+\tTEST_CASE_01=\"(LOCAL,BASE,REMOTE)/MERGED\"   # default behaviour\n+\tTEST_CASE_02=\"@LOCAL,REMOTE\"                # when using vimdiff1\n+\tTEST_CASE_03=\"LOCAL,MERGED,REMOTE\"          # when using vimdiff2\n+\tTEST_CASE_04=\"MERGED\"                       # when using vimdiff3\n+\tTEST_CASE_05=\"LOCAL/MERGED/REMOTE\"\n+\tTEST_CASE_06=\"(LOCAL/REMOTE),MERGED\"\n+\tTEST_CASE_07=\"MERGED,(LOCAL/REMOTE)\"\n+\tTEST_CASE_08=\"(LOCAL,REMOTE)/MERGED\"\n+\tTEST_CASE_09=\"MERGED/(LOCAL,REMOTE)\"\n+\tTEST_CASE_10=\"(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_11=\"(LOCAL,BASE,REMOTE)/MERGED+BASE,LOCAL+BASE,REMOTE+(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_12=\"((LOCAL,REMOTE)/BASE),MERGED\"\n+\tTEST_CASE_13=\"((LOCAL,REMOTE)/BASE),((LOCAL/REMOTE),MERGED)\"\n+\tTEST_CASE_14=\"BASE,REMOTE+BASE,LOCAL\"\n+\tTEST_CASE_15=\"  ((  (LOCAL , BASE , REMOTE) / MERGED))   +(BASE)   , LOCAL+ BASE , REMOTE+ (((LOCAL / BASE / REMOTE)) ,    MERGED   )  \"\n+\tTEST_CASE_16=\"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL / BASE / REMOTE),MERGED\"\n+\n+\tEXPECTED_CMD_01=\"-c \\\"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_02=\"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_03=\"-c \\\"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_04=\"-c \\\"echo | 4b | bufdo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_05=\"-c \\\"echo | split | 1b | wincmd j | split | 4b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_06=\"-c \\\"echo | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_07=\"-c \\\"echo | vertical split | 4b | wincmd l | split | 1b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_08=\"-c \\\"echo | split | vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_09=\"-c \\\"echo | split | 4b | wincmd j | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_10=\"-c \\\"echo | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_11=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_12=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_13=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_14=\"-c \\\"echo | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_15=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_16=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\n+\tEXPECTED_TARGET_01=\"MERGED\"\n+\tEXPECTED_TARGET_02=\"LOCAL\"\n+\tEXPECTED_TARGET_03=\"MERGED\"\n+\tEXPECTED_TARGET_04=\"MERGED\"\n+\tEXPECTED_TARGET_05=\"MERGED\"\n+\tEXPECTED_TARGET_06=\"MERGED\"\n+\tEXPECTED_TARGET_07=\"MERGED\"\n+\tEXPECTED_TARGET_08=\"MERGED\"\n+\tEXPECTED_TARGET_09=\"MERGED\"\n+\tEXPECTED_TARGET_10=\"MERGED\"\n+\tEXPECTED_TARGET_11=\"MERGED\"\n+\tEXPECTED_TARGET_12=\"MERGED\"\n+\tEXPECTED_TARGET_13=\"MERGED\"\n+\tEXPECTED_TARGET_14=\"MERGED\"\n+\tEXPECTED_TARGET_15=\"MERGED\"\n+\tEXPECTED_TARGET_16=\"MERGED\"\n+\n+\tat_least_one_ko=\"false\"\n+\n+\tfor i in $(seq -w 1 99)\n+\tdo\n+\t\tif test \"$i\" -gt $NUMBER_OF_TEST_CASES\n+\t\tthen\n+\t\t\tbreak\n+\t\tfi\n+\n+\t\tgen_cmd \"$(eval echo \\${TEST_CASE_\"$i\"})\"\n+\n+\t\tif test \"$FINAL_CMD\" = \"$(eval echo \\${EXPECTED_CMD_\"$i\"})\" \\\n+\t\t\t&& test \"$FINAL_TARGET\" = \"$(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\tthen\n+\t\t\tprintf \"Test Case #%02d: OK\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\telse\n+\t\t\tprintf \"Test Case #%02d: KO !!!!\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\t\techo \"  FINAL_CMD              : $FINAL_CMD\"\n+\t\t\techo \"  FINAL_CMD (expected)   : $(eval echo \\${EXPECTED_CMD_\"$i\"})\"\n+\t\t\techo \"  FINAL_TARGET           : $FINAL_TARGET\"\n+\t\t\techo \"  FINAL_TARGET (expected): $(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\t\tat_least_one_ko=\"true\"\n+\t\tfi\n \tdone\n+\n+\tif test \"$at_least_one_ko\" = \"true\"\n+\tthen\n+\t\treturn 255\n+\telse\n+\t\treturn 0\n+\tfi\n }\n-- \n2.35.1\n\n"},{"id":"452619","messageId":"20220329224439.290948-3-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v8 2/5] vimdiff: integrate layout tests in the unit tests framework ('t' folder)","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:36Z","receivedAt":"2022-03-29T22:44:58Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Create a new test case file for the different available merge tools.\nRight now it only tests the 'mergetool.vimdiff.layout' option. Other\nmerge tools might be interested in adding their own tests here too.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n t/t7609-mergetool--lib.sh | 14 ++++++++++++++\n 1 file changed, 14 insertions(+)\n create mode 100755 t/t7609-mergetool--lib.sh\n\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nnew file mode 100755\nindex 0000000000..d848fe6442\n--- /dev/null\n+++ b/t/t7609-mergetool--lib.sh\n@@ -0,0 +1,14 @@\n+#!/bin/sh\n+\n+test_description='git mergetool\n+\n+Testing basic merge tools options'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n+\t. $GIT_BUILD_DIR/mergetools/vimdiff &&\n+\trun_unit_tests\n+'\n+\n+test_done\n-- \n2.35.1\n\n"},{"id":"452620","messageId":"20220329224439.290948-4-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v8 3/5] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:37Z","receivedAt":"2022-03-29T22:45:00Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Running 'git {merge,diff}tool --tool-help' now also prints usage\ninformation about the vimdiff tool (and its variantes) instead of just\nits name.\n\nTwo new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\nadded to the set of functions that each merge tool (ie. scripts found\ninside \"mergetools/\") can overwrite to provided tool specific\ninformation.\n\nRight now, only 'mergetools/vimdiff' implements these functions, but\nother tools are encouraged to do so in the future, specially if they\ntake configuration options not explained anywhere else (as it is the\ncase with the 'vimdiff' tool and the new 'layout' option)\n\nIn addition, a section has been added to\n\"Documentation/git-mergetool.txt\" to explain the new \"layout\"\nconfiguration option with examples.\n\nHelped-by: Philippe Blain <levraiphilippeblain@gmail.com>\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n Documentation/config/mergetool.txt   |   9 ++\n Documentation/git-mergetool.txt      |   8 ++\n Documentation/mergetools/vimdiff.txt | 194 +++++++++++++++++++++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/vimdiff                   |  53 ++++++++\n 5 files changed, 273 insertions(+), 1 deletion(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n\ndiff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\nindex cafbbef46a..90b3809700 100644\n--- a/Documentation/config/mergetool.txt\n+++ b/Documentation/config/mergetool.txt\n@@ -45,6 +45,15 @@ mergetool.meld.useAutoMerge::\n \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n \tdefault value.\n \n+mergetool.vimdiff.layout::\n+\tThe vimdiff backend uses this variable to control how its split\n+\twindows look like. Applies even if you are using Neovim (`nvim`) or\n+\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n+ifndef::git-mergetool[]\n+\tin linkgit:git-mergetool[1].\n+endif::[]\n+\tfor details.\n+\n mergetool.hideResolved::\n \tDuring a merge Git will automatically resolve as many conflicts as\n \tpossible and write the 'MERGED' file containing conflict markers around\ndiff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt\nindex e587c7763a..f784027bc1 100644\n--- a/Documentation/git-mergetool.txt\n+++ b/Documentation/git-mergetool.txt\n@@ -101,6 +101,7 @@ success of the resolution after the custom tool has exited.\n \n CONFIGURATION\n -------------\n+:git-mergetool: 1\n include::config/mergetool.txt[]\n \n TEMPORARY FILES\n@@ -113,6 +114,13 @@ Setting the `mergetool.keepBackup` configuration variable to `false`\n causes `git mergetool` to automatically remove the backup as files\n are successfully merged.\n \n+BACKEND SPECIFIC HINTS\n+----------------------\n+\n+vimdiff\n+~~~~~~~\n+include::mergetools/vimdiff.txt[]\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nnew file mode 100644\nindex 0000000000..2d631e9b1f\n--- /dev/null\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -0,0 +1,194 @@\n+Description\n+^^^^^^^^^^^\n+\n+When specifying `--tool=vimdiff` in `git mergetool` Git will open Vim with a 4\n+windows layout distributed in the following way:\n+....\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n+`LOCAL`, `BASE` and `REMOTE` are read-only buffers showing the contents of the\n+conflicting file in specific commits (\"commit you are merging into\", \"common\n+ancestor commit\" and \"commit you are merging from\" respectively)\n+\n+`MERGED` is a writable buffer where you have to resolve the conflicts (using the\n+other read-only buffers as a reference). Once you are done, save and exit Vim as\n+usual (`:wq`) or, if you want to abort, exit using `:cq`.\n+\n+Layout configuration\n+^^^^^^^^^^^^^^^^^^^^\n+\n+You can change the windows layout used by Vim by setting configuration variable\n+`mergetool.vimdiff.layout` which accepts a string where the following separators\n+have special meaning:\n+\n+  - `+` is used to \"open a new tab\"\n+  - `,` is used to \"open a new vertical split\"\n+  - `/` is used to \"open a new horizontal split\"\n+  - `@` is used to indicate which is the file containing the final version after\n+    solving the conflicts. If not present, `MERGED` will be used by default.\n+\n+The precedence of the operators is this one (you can use parentheses to change\n+it):\n+\n+    `@` > `+` > `/` > `,`\n+\n+Let's see some examples to understand how it works:\n+\n+* `layout = \"(LOCAL,BASE,REMOTE)/MERGED\"`\n++\n+--\n+This is exactly the same as the default layout we have already seen.\n+\n+Note that `/` has precedence over `,` and thus the parenthesis are not\n+needed in this case. The next layout definition is equivalent:\n+\n+    layout = \"LOCAL,BASE,REMOTE / MERGED\"\n+--\n+* `layout = \"LOCAL,MERGED,REMOTE\"`\n++\n+--\n+If, for some reason, we are not interested in the `BASE` buffer.\n+....\n+------------------------------------------\n+|             |           |              |\n+|             |           |              |\n+|   LOCAL     |   MERGED  |   REMOTE     |\n+|             |           |              |\n+|             |           |              |\n+------------------------------------------\n+....\n+--\n+* `layout = \"MERGED\"`\n++\n+--\n+Only the `MERGED` buffer will be shown. Note, however, that all the other\n+ones are still loaded in vim, and you can access them with the \"buffers\"\n+command.\n+....\n+------------------------------------------\n+|                                        |\n+|                                        |\n+|                 MERGED                 |\n+|                                        |\n+|                                        |\n+------------------------------------------\n+....\n+--\n+* `layout = \"@LOCAL,REMOTE\"`\n++\n+--\n+When `MERGED` is not present in the layout, you must \"mark\" one of the\n+buffers with an asterisk. That will become the buffer you need to edit and\n+save after resolving the conflicts.\n+....\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     LOCAL         |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"`\n++\n+--\n+Three tabs will open: the first one is a copy of the default layout, while\n+the other two only show the differences between (`BASE` and `LOCAL`) and\n+(`BASE` and `REMOTE`) respectively.\n+....\n+------------------------------------------\n+| <TAB #1> |  TAB #2  |  TAB #3  |       |\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  | <TAB #2> |  TAB #3  |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    LOCAL           |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  |  TAB #2  | <TAB #3> |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"`\n++\n+--\n+Same as the previous example, but adds a fourth tab with the same\n+information as the first tab, with a different layout.\n+....\n+---------------------------------------------\n+|  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n+---------------------------------------------\n+|       LOCAL         |                     |\n+|---------------------|                     |\n+|       BASE          |        MERGED       |\n+|---------------------|                     |\n+|       REMOTE        |                     |\n+---------------------------------------------\n+....\n+Note how in the third tab definition we need to use parenthesis to make `,`\n+have precedence over `/`.\n+--\n+\n+Variants\n+^^^^^^^^\n+\n+Instead of `--tool=vimdiff`, you can also use one of these other variants:\n+\n+  * `--tool=gvimdiff`, to open gVim instead of Vim.\n+\n+  * `--tool=nvimdiff`, to open Neovim instead of Vim.\n+\n+When using these variants, in order to specify a custom layout you will have to\n+set configuration variables `mergetool.gvimdiff.layout` and\n+`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n+\n+In addition, for backwards compatibility with previous Git versions, you can\n+also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:\n+`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.\n+In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n+`--tool=[g,n,]vimdiff` and setting configuration variable\n+`mergetool.[g,n,]vimdiff.layout` to...\n+\n+  * `x=1`: `\"@LOCAL, REMOTE\"`\n+  * `x=2`: `\"LOCAL, MERGED, REMOTE\"`\n+  * `x=3`: `\"MERGED\"`\n+\n+Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n+MERGED and REMOTE).\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 542a6a75eb..9f99201bcc 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -63,7 +63,7 @@ $(list_tool_variants)\"\n \t\t\t\t\tpreamble=\n \t\t\t\tfi\n \t\t\t\tshown_any=yes\n-\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n+\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n \t\t\tfi\n \t\tdone\n \n@@ -162,10 +162,18 @@ setup_tool () {\n \t\treturn 1\n \t}\n \n+\tdiff_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \tmerge_cmd () {\n \t\treturn 1\n \t}\n \n+\tmerge_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \thide_resolved_enabled () {\n \t\treturn 0\n \t}\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 9d1bf4f455..461a89b6f9 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -365,6 +365,25 @@ diff_cmd () {\n }\n \n \n+diff_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim\"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session)\"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n merge_cmd () {\n \tlayout=$(git config mergetool.vimdiff.layout)\n \n@@ -436,6 +455,40 @@ merge_cmd () {\n }\n \n \n+merge_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim \"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session) \"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim \"\n+\t\t;;\n+\tesac\n+\n+\tcase \"$TOOL\" in\n+\t*1)\n+\t\techo \"with a 2 panes layout (LOCAL and REMOTE)\"\n+\t\t;;\n+\t*2)\n+\t\techo \"with a 3 panes layout (LOCAL, MERGED and REMOTE)\"\n+\t\t;;\n+\t*3)\n+\t\techo \"where only the MERGED file is shown\"\n+\t\t;;\n+\t*)\n+\t\techo \"with a custom layout (see \\`git help mergetool\\`'s \\`BACKEND SPECIFIC HINTS\\` section)\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n-- \n2.35.1\n\n"},{"id":"452621","messageId":"20220329224439.290948-5-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v8 4/5] mergetools: add description to all diff/merge tools","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:38Z","receivedAt":"2022-03-29T22:45:08Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"The output of `git mergetool --tool-help` and `git difftool --tool-help`\nonly showed the `alias` of each available merge/diff tool.\n\nIt is not always obvious what tool these `aliases` end up using (ex:\n`opendiff` runs `FileMerge` and `bc` runs `Beyond Compare`).\n\nThis commit adds a short description to each of them to help the user\nidentify the `alias` they want.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/araxis        | 8 ++++++++\n mergetools/bc            | 8 ++++++++\n mergetools/codecompare   | 8 ++++++++\n mergetools/deltawalker   | 8 ++++++++\n mergetools/diffmerge     | 8 ++++++++\n mergetools/diffuse       | 8 ++++++++\n mergetools/ecmerge       | 8 ++++++++\n mergetools/emerge        | 8 ++++++++\n mergetools/examdiff      | 8 ++++++++\n mergetools/guiffy        | 8 ++++++++\n mergetools/kdiff3        | 8 ++++++++\n mergetools/kompare       | 8 ++++++++\n mergetools/meld          | 8 ++++++++\n mergetools/opendiff      | 8 ++++++++\n mergetools/p4merge       | 8 ++++++++\n mergetools/smerge        | 8 ++++++++\n mergetools/tkdiff        | 8 ++++++++\n mergetools/tortoisemerge | 8 ++++++++\n mergetools/winmerge      | 8 ++++++++\n mergetools/xxdiff        | 8 ++++++++\n 20 files changed, 160 insertions(+)\n\ndiff --git a/mergetools/araxis b/mergetools/araxis\nindex e2407b65b7..eb32a7da95 100644\n--- a/mergetools/araxis\n+++ b/mergetools/araxis\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -wait -2 \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \techo compare\n }\ndiff --git a/mergetools/bc b/mergetools/bc\nindex 26c19d46a5..2922667ddd 100644\n--- a/mergetools/bc\n+++ b/mergetools/bc\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif type bcomp >/dev/null 2>/dev/null\n \tthen\ndiff --git a/mergetools/codecompare b/mergetools/codecompare\nindex 9f60e8da65..610963d377 100644\n--- a/mergetools/codecompare\n+++ b/mergetools/codecompare\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif merge_mode\n \tthen\ndiff --git a/mergetools/deltawalker b/mergetools/deltawalker\nindex ee6f374bce..efae4c285c 100644\n--- a/mergetools/deltawalker\n+++ b/mergetools/deltawalker\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# Adding $(pwd)/ in front of $MERGED should not be necessary.\n \t# However without it, DeltaWalker (at least v1.9.8 on Windows)\n@@ -16,6 +20,10 @@ merge_cmd () {\n \tfi >/dev/null 2>&1\n }\n \n+merge_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path () {\n \techo DeltaWalker\n }\ndiff --git a/mergetools/diffmerge b/mergetools/diffmerge\nindex 9b6355b98a..9b5b62d1ca 100644\n--- a/mergetools/diffmerge\n+++ b/mergetools/diffmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/diffuse b/mergetools/diffuse\nindex 5a3ae8b569..ebfaba5172 100644\n--- a/mergetools/diffuse\n+++ b/mergetools/diffuse\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,3 +17,7 @@ merge_cmd () {\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\ndiff --git a/mergetools/ecmerge b/mergetools/ecmerge\nindex 6c5101c4f7..0d4d609874 100644\n--- a/mergetools/ecmerge\n+++ b/mergetools/ecmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" --default --mode=diff2 \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t--default --mode=merge2 --to=\"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/emerge b/mergetools/emerge\nindex d1ce513ff5..fc6892cc95 100644\n--- a/mergetools/emerge\n+++ b/mergetools/emerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -f emerge-files-command \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -17,6 +21,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n translate_merge_tool_path() {\n \techo emacs\n }\ndiff --git a/mergetools/examdiff b/mergetools/examdiff\nindex e72b06fc4d..6f53ca9161 100644\n--- a/mergetools/examdiff\n+++ b/mergetools/examdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" -nh\n }\n \n+diff_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -11,6 +15,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"ExamDiff.com\" \"ExamDiff Pro\"\n }\ndiff --git a/mergetools/guiffy b/mergetools/guiffy\nindex 8b23a13c41..3ed07efd16 100644\n--- a/mergetools/guiffy\n+++ b/mergetools/guiffy\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kdiff3 b/mergetools/kdiff3\nindex 520cb914a1..ee8b3a0570 100644\n--- a/mergetools/kdiff3\n+++ b/mergetools/kdiff3\n@@ -4,6 +4,10 @@ diff_cmd () {\n \t\t\"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -22,6 +26,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kompare b/mergetools/kompare\nindex e8c0bfa678..4ce23dbe8b 100644\n--- a/mergetools/kompare\n+++ b/mergetools/kompare\n@@ -2,10 +2,18 @@ can_merge () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+merge_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/meld b/mergetools/meld\nindex aab4ebb935..8ec0867e03 100644\n--- a/mergetools/meld\n+++ b/mergetools/meld\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Meld (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tcheck_meld_for_features\n \n@@ -20,6 +24,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Meld (requires a graphical session) with optional \\`auto merge\\` (see \\`git help mergetool\\`'s \\`CONFIGURATION\\` section)\"\n+}\n+\n # Get meld help message\n init_meld_help_msg () {\n \tif test -z \"$meld_help_msg\"\ndiff --git a/mergetools/opendiff b/mergetools/opendiff\nindex b608dd6de3..44adf8f951 100644\n--- a/mergetools/opendiff\n+++ b/mergetools/opendiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t-merge \"$MERGED\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/p4merge b/mergetools/p4merge\nindex 7a5b291dd2..f3cb197e58 100644\n--- a/mergetools/p4merge\n+++ b/mergetools/p4merge\n@@ -19,6 +19,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif ! $base_present\n \tthen\n@@ -34,3 +38,7 @@ create_empty_file () {\n \n \tprintf \"%s\" \"$empty_file\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/smerge b/mergetools/smerge\nindex 9c2e6f6fd7..5410835a6b 100644\n--- a/mergetools/smerge\n+++ b/mergetools/smerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -10,3 +14,7 @@ merge_cmd () {\n \t\t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tkdiff b/mergetools/tkdiff\nindex eee5cb57e3..66906a720d 100644\n--- a/mergetools/tkdiff\n+++ b/mergetools/tkdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -14,3 +18,7 @@ merge_cmd () {\n exit_code_trustable () {\n \ttrue\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tortoisemerge b/mergetools/tortoisemerge\nindex d7ab666a59..507edcd444 100644\n--- a/mergetools/tortoisemerge\n+++ b/mergetools/tortoisemerge\n@@ -2,6 +2,10 @@ can_diff () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -30,3 +34,7 @@ translate_merge_tool_path() {\n \t\techo tortoisemerge\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/winmerge b/mergetools/winmerge\nindex 74d03259fd..36c72dde6e 100644\n--- a/mergetools/winmerge\n+++ b/mergetools/winmerge\n@@ -3,6 +3,10 @@ diff_cmd () {\n \treturn 0\n }\n \n+diff_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# mergetool.winmerge.trustExitCode is implicitly false.\n \t# touch $BACKUP so that we can check_unchanged.\n@@ -13,3 +17,7 @@ merge_cmd () {\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"WinMergeU.exe\" \"WinMerge\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/xxdiff b/mergetools/xxdiff\nindex d5ce467995..cd205f9842 100644\n--- a/mergetools/xxdiff\n+++ b/mergetools/xxdiff\n@@ -12,6 +12,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -28,3 +32,7 @@ merge_cmd () {\n \t\t\t--merged-file \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n-- \n2.35.1\n\n"},{"id":"452622","messageId":"20220329224439.290948-6-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v8 5/5] mergetools: add tools description to `git help config`","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-29T22:44:39Z","receivedAt":"2022-03-29T22:45:11Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Now the output of `git help config` not only shows the name of each\ntool (as before) but also a short description (as it is the case when\nrunning `git mergetool --tool-help` or ` git difftool --tool-help`)\n\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n Documentation/Makefile | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex 1eb9192dae..faed285462 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -302,12 +302,12 @@ $(mergetools_txt): mergetools-list.made\n \n mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n \t$(QUIET_GEN) \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=diff && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t\tshow_tool_names can_diff' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-diff.txt && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=merge && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n+\t\tshow_tool_names can_merge' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-merge.txt && \\\n \tdate >$@\n \n TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\n-- \n2.35.1\n\n"},{"id":"452661","messageId":"da6472b4-65e6-a3ca-8d8b-892afb6f0fac@gmail.com","threadId":"57629","inReplyTo":"20220329224439.290948-6-greenfoo@u92.eu","subject":"Re: [PATCH v8 5/5] mergetools: add tools description to `git help config`","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-30T12:43:50Z","receivedAt":"2022-03-30T12:46:01Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-29 à 18:44, Fernando Ramos a écrit :\n> Now the output of `git help config` not only shows the name of each\n> tool (as before) but also a short description (as it is the case when\n> running `git mergetool --tool-help` or ` git difftool --tool-help`)\n> \n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n\nThis commit is authored by you but is missing your sign off. \nAlso, I did not give my sign-off on this patch (that can't be assumed, \nit always has to be expressively given).\n\nWhen people provide \"in mail\" diffs like I did in [1] and [2], it's usually meant\nto be squashed into a commit of the series. In this case I think it would\nbe best squashed in 3/4, since as I explained in [3], the description of\neach merge tool is already included in the 'git config' documentation after your\n3/4, the below patch to the Makefile just makes it an Asciidoc \"description list\"\n(and formats the merge tool names between backticks) instead of a plain list\nas it was before.\n\nGranted, after 3/4 only vimdiff and friends have a description, but that can be \nexplained in the commit message, and the rest of the descriptions are added in 4/4.\n\n> ---\n>  Documentation/Makefile | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n> \n> diff --git a/Documentation/Makefile b/Documentation/Makefile\n> index 1eb9192dae..faed285462 100644\n> --- a/Documentation/Makefile\n> +++ b/Documentation/Makefile\n> @@ -302,12 +302,12 @@ $(mergetools_txt): mergetools-list.made\n>  \n>  mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n>  \t$(QUIET_GEN) \\\n> -\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n> +\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=diff && \\\n>  \t\t. ../git-mergetool--lib.sh && \\\n> -\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n> -\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n> +\t\tshow_tool_names can_diff' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-diff.txt && \\\n> +\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=merge && \\\n>  \t\t. ../git-mergetool--lib.sh && \\\n> -\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n> +\t\tshow_tool_names can_merge' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-merge.txt && \\\n>  \tdate >$@\n>  \n>  TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\n> \n\nCheers,\n\nPhilippe.\n\n[1] https://lore.kernel.org/git/1363db57-74de-226a-468f-69feffde6ba5@gmail.com/\n[2] https://lore.kernel.org/git/d0a0d00b-5c1a-4a0c-a91c-b03403578f80@gmail.com/\n[3] https://lore.kernel.org/git/f56a7a0b-8525-c4cc-7bc7-5ac4bba59206@gmail.com/\n"},{"id":"452687","messageId":"YkSij31hyi29g7v2@zacax395.localdomain","threadId":"57629","inReplyTo":"da6472b4-65e6-a3ca-8d8b-892afb6f0fac@gmail.com","subject":"Re: [PATCH v8 5/5] mergetools: add tools description to `git help config`","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T18:33:51Z","receivedAt":"2022-03-30T18:37:00Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> This commit is authored by you but is missing your sign off.\n> Also, I did not give my sign-off on this patch (that can't be assumed,\n> it always has to be expressively given).\n\nI see, sorry. As this patch is a verbatim copy of the one you provided in the\nlast message I thought it was not appropriate to put my name on it (as it does\nnot contain any line created by me)... but now I know that in these cases the\nright thing to do is to squash into the commit being commented on and add a\n\"Helped-by:\" note. Right?\n\nI'll fix this in v9.\n\nJust to double check, please confirm this is what you want me to do:\n\n  1. Squash 5/5 into  3/5\n\n  2. Update the commit message to:\n\n     2.1 Explain that the description is also added to the output of `git help\n         config`\n\n     2.2 Remove your name from \"Signed-off-by:\"\n\n     2.3 Keep you name in \"Helped-by:\"\n\nThanks!\n\n\nPS: I must confess this whole process of sending patches to the git mailing\nlist brings me back memories from \"Asterix: The 12 Tasks\" [1] :) :) :)\n\n[1] https://www.youtube.com/watch?v=ZHRGjfEQpy4\n"},{"id":"452689","messageId":"de847041-acad-2a01-6a4f-36ed7318e01c@gmail.com","threadId":"57629","inReplyTo":"YkSij31hyi29g7v2@zacax395.localdomain","subject":"Re: [PATCH v8 5/5] mergetools: add tools description to `git help config`","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-03-30T18:45:59Z","receivedAt":"2022-03-30T18:46:16Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-30 à 14:33, Fernando Ramos a écrit :\n>> This commit is authored by you but is missing your sign off.\n>> Also, I did not give my sign-off on this patch (that can't be assumed,\n>> it always has to be expressively given).\n> \n> I see, sorry. As this patch is a verbatim copy of the one you provided in the\n> last message I thought it was not appropriate to put my name on it (as it does\n> not contain any line created by me)... but now I know that in these cases the\n> right thing to do is to squash into the commit being commented on and add a\n> \"Helped-by:\" note. Right?\n\nYes, right. :)\n\n> \n> I'll fix this in v9.\n> \n> Just to double check, please confirm this is what you want me to do:\n> \n>   1. Squash 5/5 into  3/5\n\nyes. \n\n> \n>   2. Update the commit message to:\n> \n>      2.1 Explain that the description is also added to the output of `git help\n>          config`\n\nYes. For example, this is how I would phrase it, be free to copy \n(maybe as the second-to-last paragraph?):\n\nNote that the function 'show_tool_names', used in the implmentation of\n'git mergetool --tool-help', is also used in Documentation/Makefile to\ngenerate the list of allowed values for the configuration variables \n'{diff,merge}.{gui,}tool'. Adjust the rule so its output is an Asciidoc\n\"description list\" instead of a plain list, with the tool name as the item\nand the newly added tool description as the description.\n\n> \n>      2.2 Remove your name from \"Signed-off-by:\"\n> \n>      2.3 Keep you name in \"Helped-by:\"\n\nyes and yes.\n\n> \n> Thanks!\n> \n> \n> PS: I must confess this whole process of sending patches to the git mailing\n> list brings me back memories from \"Asterix: The 12 Tasks\" [1] :) :) :)\n\nYes, it can be hard. I prefer using Gitgitgadget most of the time [1].\n\n[1] https://gitgitgadget.github.io/\n"},{"id":"452693","messageId":"20220330191909.294610-1-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220329224439.290948-1-greenfoo@u92.eu","subject":"[PATCH v9 0/4] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T19:19:05Z","receivedAt":"2022-03-30T19:19:42Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Original cover letter (see v9 changes at the end):\n\nA few weeks ago I presented this RFC [1] where I introduced a new variant of the\nvimdiff merge tool (\"vimdiff4\") that creates three tabs (instead of just one)\nthat look like this:\n\n    ------------------------------------------\n    | <TAB #1> |  TAB #2  |  TAB #3  |       |\n    ------------------------------------------\n    |             |           |              |\n    |   LOCAL     |   BASE    |   REMOTE     |\n    |             |           |              |   <---- Same information\n    ------------------------------------------         presented by the\n    |                                        |         \"standard\" vimdiff\n    |                MERGED                  |         merge tool\n    |                                        |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  | <TAB #2> |  TAB #3  |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    LOCAL           |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         LOCAL are shown\n    |                   |                    |\n    ------------------------------------------\n    \n    ------------------------------------------\n    |  TAB #1  |  TAB #2  | <TAB #3> |       |\n    ------------------------------------------\n    |                   |                    |\n    |                   |                    |\n    |                   |                    |\n    |     BASE          |    REMOTE          |   <---- Only differences\n    |                   |                    |         between BASE and\n    |                   |                    |         REMOTE are shown\n    |                   |                    |\n    ------------------------------------------\n\n\nThe motivation behind this was that, for non-trivial merges, the three way diff\npresented in the first tab tends to be very confusing and in these cases\nindividual diffs between BASE and LOCAL and between BASE and REMOTE are very\nuseful.\n\nI have been using a \"custom\" merge tool for months to achieve this same result\nby adding these lines to my .gitconfig file:\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c \\\"4wincmd w | wincmd J | tabnew | edit $LOCAL | vertical diffsplit $BASE | tabnew | edit $REMOTE | vertical diffsplit $BASE | 2tabprevious\\\" \\\"$LOCAL\\\" \\\"$BASE\\\" \\\"$REMOTE\\\" \\\"$MERGED\\\"\n        trustExitCode = true\n\n...and, because I found this \"trick\" very useful, I thought it would be a good\nidea to add it as a git built-in merge tool (called \"vimdiff4\" because  1, 2 and\n3 had already been taken) for everyone to use... and that's exactly what the RFC\nI published did.\n\nNow... as you can see in the RFC thread [1], David and Juno suggested that\nmaybe, instead of creating *yet another vimdiff variant*, we should take this\nopportunity to:\n\n  * Come up with a more general way of defining arbitrary vim layouts.\n  \n  * Re-implement \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" using this new mechanism\n    (after all, the only difference among them is that they present different\n    layouts to the user)\n\n  * Add documentation to all of this.\n\nAnd the result of that work is what I'm presenting today :)\n\nSome things I would like to mention:\n\n  1. There are three commits in this patch series:\n\n     - The first one implements the logic to generate new arbitrary layouts and\n       also re-defines \"vimdiff1\", \"vimdiff2\" and \"vimdiff3\" on top of it.\n\n     - The second one adds documentation. It is probably a good idea to start\n       reviewing this commit before the first one!\n\n     - The last commit *is not meant to be merged now*. It removes \"vimdiff1\",\n       \"vimdiff2\" and \"vimdiff3\", which is something that should only be done\n       after one or two releases with a deprecation notice and only if everyone\n       agrees to do so :)\n\n  2. \"mergetools/vimdiff\" is now a ~800 lines bash script, but most of it is\n     documentation (which is embedded in the tool itself for easier maintenance)\n     and unit tests.\n     I have only tested it with bash, but I've tried not to use any command not\n     already being used somewhere else, so I expect it to work in the same\n     places it was working before (however, let me know if there are some shell\n     compatibility requirements and I'll try to check them).\n\n  3. Regarding unit tests, \"mergetool/vimdiff\" contains instructions on how to\n     run them (just call the script without arguments after making changes, to\n     make sure you didn't break anything).\n     Right now it prints \"OK\" on all test cases (obviously) [2]\n\n  3. The \"git {diff,merge}tool --tool-help\" command now also prints the\n     documentation for each tool (instead of just its name, as before).\n     You can see an example of the output here ([3] and [4])\n\nFinally, let me say that, while I like what this patch series achieves, I would\nalso *completely* understand if you decide not to merge it due to being a\ncomplex solution to a simple problem that can be solved (as I had been doing up\nuntil today) by just adding three lines to one's .gitconfig.\n\n  [mergetool \"supermerge\"]\n        cmd = vim -f -d -c ...(custom complex sequence of vim commands)...\n        trustExitCode = true\n\nLet me know what you think.\n\nThanks.\n\nReferences:\n\n  [1] https://lore.kernel.org/git/20211019212020.25385-1-greenfoo@u92.eu/#r\n  [2] https://pastebin.com/kuQ5pETG\n  [3] https://pastebin.com/yvLWxeiM\n  [4] https://pastebin.com/qNc7qymp\n\n\nNew in v2:\n\n  * Remove deprecation of vimdiff{1,2,3} (they will remain for backwards\n    compatibility, but built on top of the new generic layout mechanism)\n\n  * Remove unnecessary \"IFS=\"\n\n  * Replace DEBUG --> GIT_MERGETOOL_VIMDIFF_DEBUG\n\n  * Stop using \"local\" (turns out it was not necessary)\n\n  * Stop using bash arrays (use arrays of variables instead)\n\n  * Stop using bash substring expansion (use a new \"substring\" function\n    instead).\n\n  * Refactor some of the internal loops to make the code faster. This was needed\n    because the two previous changes (specially the one where I stop using\n    \"substring expansion\") slowed down the script to a point where I had to wait\n    for a few *seconds* before the \"layout\" string was resolved (recursion +\n    bash forks are a recipe for sluggishness). Fortunately we are back to the\n    low hundreds of milliseconds range.\n\n  * Change markers:\n    - File to save: * --> @\n    - New tab     : ; --> +\n    - Vert split  : | --> ,\n    - Horz split  : - --> /\n\n  * Rewrite examples to use as few parenthesis as possible (typically zero)\n    and better explain operators priority.\n\n  * Other fixes to remove problems reported by \"shellcheck --shell=sh\" (which\n    checks syntax agains the POSIX shell spec)\n\n  * Rename \"index_...\" vars to make more obvious what they do.\n\n  * Use \"$\" inside arithmetic expressions $((...))\n    NOTE: \"shellcheck\" issues a warning stating that \"$\" is not needed inside\n    arithmetic expressions.\n\n  * Use \"test -n\" instead of \"! test -z\"\n\n  * Use \"=\" instead of \"==\" in \"test\"\n\n  * Use \"= 0\" instead of \"-eq 0\"\n\n  * Do not use \"eval\" nor \"--\" when copying a file to MERGED\n\n  * Do not use \"-o\" with grep\n\n  * Use <<-\\EOF instead of <<\\ENDOFMESSAGE and remove extra indent in \"here\n    docs\".\n\n  * Also, let me put here some answers to questions made in the replies to\n    version v1 of this patch set:\n\n    > What do backticks do in here?\n    >\n    >     some_var=(\n    >         `# Name`       \"Rick Deckard\"\n    >         `# Age`        \"Unknown\"\n    >         `# Occupation` \"Blade runner\"\n    >     )\n\n    The backticks execute the code inside, which is a comment (everything after\n    a \"#\" is considered a comment by the shell), thus it does nothing.\n\n    The `# ...` trick can be used to insert inline comments in bash. Another\n    example:\n\n        $ ls -l `# long format` -h `# human readable` *.txt\n\n    In any case, as you can see in this new revision, because I'm no longer\n    using bash arrays, this trick to comment each test case is not needed\n    anymore.\n\n    > Why is \"eval\" needed here:\n    >\n    >     eval \"$merge_tool_path\" \\\n    >              -f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n\n    Variable \"$FINAL_CMD\" contains a string that looks like this:\n\n        $ echo $FINAL_CMD\n        -c \"vim cmd 1 | vim cmd 2 | ...\" -c \"tabfirst\"\n\n    We need to call \"vim\" exactly like that, but if we do this...\n\n         $ vim $FINAL_CMD\n\n    ...then \"vim\" will be excev'ed with the following arguments:\n\n        1. -c\n        2. \"vim\n        3. cmd\n        4. 1\n        ...\n\n    ...instead of the desired scenario:\n\n       1. -c\n       2. cmd 1 | cmd 2 | ...\n       3. -c\n       4. tabfirst\n\n     Using \"eval\" fixes this. A shorter example shows how this works:\n\n         $ A=\"1 \\\"2 3\\\"\"\n\n         $ ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '\"2': No such file or directory\n         ls: cannot access '3\"': No such file or directory\n\n         $ eval ls $A\n         ls: cannot access '1': No such file or directory\n         ls: cannot access '2 3': No such file or directory\n\n  * Finally, I think I have addressed all comments to v1 *except for two\n    things*:\n\n        1. Moving the documentation to \"Documentation/\" instead of having it\n           embedded inside the \"mergetools/vimdiff\" script.\n\n        2. Move unit tests to the \"test suit\"\n\n    For (1) I would like more details. Is the idea not to print any\n    documentation when running \"git mergetool --tool-help\" and have all the\n    details included in \"git help mergetool\" instead?\n    Right now \"git help mergetool\" does not mention any tool specific details\n    and, instead, redirects the user to \"git mergetool --tool-help\" (that's why\n    I originally placed the new documentation there).\n    In any case, all the doc has been placed on its own commit, so once we\n    decide how to proceed its just a matter of reverting it.\n\n    For (2) I still need to investigate how this is done and prepare a \"v3\" if\n    needed :)\n\n\nNew in v3:\n\n  * Rebase on top of latest master\n\n  * Documentation moved to \"Documentation/\". Running \"git mergetool\n    --tool-help\" now works like before (ie. it just lists all available merge\n    tools) except that a one line reference to a \"man\" entry is also printed for\n    those entries providing one (right now, only vimdiff):\n\n        $ git mergetool --tool-help\n        'git mergetool --tool=<tool>' may be set to one of the following:\n                        araxis\n                        meld\n                        vimdiff\n                                Run 'man git-mergetool--vimdiff' for details\n                        vimdiff1\n                                Run 'man git-mergetool--vimdiff' for details\n                        ...\n\n  * New test file \"t/7609-mergetool--lib.sh\" created. Right now it only\n    contains one test which calls \"mergetools/vimdiff\" with a special\n    environment set, causing layout unit tests to run.\n\n\nNew in v4:\n\n  * Rebase on top of latest master\n\n  * Stop using \"$\" inside arithmetic expressions.\n\n  * Remove \"!/bin/bash\" from the top of the \"vimdiff\" script.\n\n  * Update comment explaining how the \"vimdiff\" script can be run.\n\n  * Fix spaces/tabs.\n\n  * Change the way unit tests are run (now the script is directly sourced\n    instead of calling bash)\n\n  * Remove unnecessary \"case/esac\" structure.\n\n  * Fix typo in documentation\n\n\nNew in v5:\n\n  * Rebase on top of latest master\n\n\nNew in v6:\n\n  * Syntax corrections (spaces around parenthesis)\n\n  * Fix layout definition of \"vimdiff1\"\n\n  * Make clear how the old behaviour of the different variants (vimdiffN) is\n    tested in the built in unit tests\n\n  * Move doc into a subsection inside \"git help mergetool\"\n\n\nNew in v7:\n\n  * Rebase on top of latest master\n\n  * Fix some comments that had not being updated to reflect the latest changes\n\n  * `git mergetool --tool-help` now shows the information associated to each\n    entry in the same line. It also briefly explains what each variant does.\n\n  * Apply patch from Philippe Blain that fixes HTML formatting (thanks!)\n\n  * Add asccidoc directive to hide references to `git-mergetool` when we are\n    already reading documentation from the `git-mergetool` entry\n\n  * Fix \"Vim\", \"Neovim\", \"gVim\" and \"Git\" capitalization in docs\n\n  * Change double and single quotes into backticks in docs where applicable\n\n  * Fix typos in docs\n\n  * Remove \"mergetool.gvimdiff.layout\" and \"mergetool.nvimdiff.layout\". The\n    only one remaining now is \"mergetool.vimdiff.layout\" which defines the\n    layout in all cases, no matter the vim variant we are using.\n\n  * Remove trailing spaces\n\n  * Only list appropiate variants (\"vimdiff\", \"nvim\" and \"gvim\") when running\n    `git difftool --tool-help`\n\n  * Add a short description to all other (already existing) merge/diff tools\n    (Beyond Compare, xxdiff, etc...)\n\n\nNew in v8:\n\n  * Rebase on top of latest master\n\n  * Remove spaces from indented blocks of documentation\n\n  * Fix missing commit message in one of the commits\n\n  * Added \"Helped-by\" signature to the doc commit\n\n  * Change sentence in docs to make it syntactically correct\n\n  * Add commit from Philippe Blain to also print the tool description when\n    running ` git help config` (thanks!)\n\n\nNew in v9:\n\n  * Rebase on top of latest master\n\n  * Fix authorship of commits\n\nFernando Ramos (4):\n  vimdiff: new implementation with layout support\n  vimdiff: integrate layout tests in the unit tests framework ('t'\n    folder)\n  vimdiff: add tool documentation\n  mergetools: add description to all diff/merge tools\n\n Documentation/Makefile               |   8 +-\n Documentation/config/mergetool.txt   |   9 +\n Documentation/git-mergetool.txt      |   8 +\n Documentation/mergetools/vimdiff.txt | 194 +++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/araxis                    |   8 +\n mergetools/bc                        |   8 +\n mergetools/codecompare               |   8 +\n mergetools/deltawalker               |   8 +\n mergetools/diffmerge                 |   8 +\n mergetools/diffuse                   |   8 +\n mergetools/ecmerge                   |   8 +\n mergetools/emerge                    |   8 +\n mergetools/examdiff                  |   8 +\n mergetools/guiffy                    |   8 +\n mergetools/kdiff3                    |   8 +\n mergetools/kompare                   |   8 +\n mergetools/meld                      |   8 +\n mergetools/opendiff                  |   8 +\n mergetools/p4merge                   |   8 +\n mergetools/smerge                    |   8 +\n mergetools/tkdiff                    |   8 +\n mergetools/tortoisemerge             |   8 +\n mergetools/vimdiff                   | 607 +++++++++++++++++++++++++--\n mergetools/winmerge                  |   8 +\n mergetools/xxdiff                    |   8 +\n t/t7609-mergetool--lib.sh            |  14 +\n 27 files changed, 978 insertions(+), 32 deletions(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n create mode 100755 t/t7609-mergetool--lib.sh\n\n-- \n2.35.1\n\n"},{"id":"452694","messageId":"20220330191909.294610-2-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220330191909.294610-1-greenfoo@u92.eu","subject":"[PATCH v9 1/4] vimdiff: new implementation with layout support","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T19:19:06Z","receivedAt":"2022-03-30T19:19:45Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"When running 'git mergetool -t vimdiff', a new configuration option\n('mergetool.vimdiff.layout') can now be used to select how the user\nwants the different windows, tabs and buffers to be displayed.\n\nIf the option is not provided, the layout will be the same one that was\nbeing used before this commit (ie. two rows with LOCAL, BASE and COMMIT\nin the top one and MERGED in the bottom one).\n\nThe 'vimdiff' variants ('vimdiff{1,2,3}') still work but, because they\nrepresented nothing else than different layouts, are now internally\nimplemented as a subcase of 'vimdiff' with the corresponding\npre-configured 'layout'.\n\nAgain, if you don't set \"mergetool.vimdiff.layout\" everything will work\nthe same as before *but* the arguments used to call {n,g,}vim will be\nothers (even if you don't/shouldn't notice it):\n\n  - git mergetool -t vimdiff\n\n    > Before this commit:\n      {n,g,}vim -f -d -c '4wincmd w | wincmd J' $LOCAL $BASE $REMOTE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff1\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'echon \"...\"' $LOCAL $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff2\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'wincmd l' $LOCAL $MERGED $REMOTE\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\n  - git mergetool -t vimdiff3\n\n    > Before this commit:\n      {n,g,}vim -f -d -c 'hid | hid | hid' $LOCAL $REMOTE $BASE $MERGED\n\n    > After this commit:\n      {n,g,}vim -f -c \"echo | 4b | bufdo diffthis\" -c \"tabfirst\" $LOCAL $BASE $REMOTE $MERGED\n\nDespite being different, I have manually verified that they generate the same\nlayout as before.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/vimdiff | 558 ++++++++++++++++++++++++++++++++++++++++++---\n 1 file changed, 529 insertions(+), 29 deletions(-)\n\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 96f6209a04..9d1bf4f455 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -1,49 +1,442 @@\n+# This script can be run in two different contexts:\n+#\n+#   - From git, when the user invokes the \"vimdiff\" merge tool. In this context\n+#     this script expects the following environment variables (among others) to\n+#     be defined (which is something \"git\" takes care of):\n+#\n+#       - $BASE\n+#       - $LOCAL\n+#       - $REMOTE\n+#       - $MERGED\n+#\n+#     In this mode, all this script does is to run the next command:\n+#\n+#         vim -f -c ... $LOCAL $BASE $REMOTE $MERGED\n+#\n+#     ...where the \"...\" string depends on the value of the\n+#     \"mergetool.vimdiff.layout\" configuration variable and is used to open vim\n+#     with a certain layout of buffers, windows and tabs.\n+#\n+#   - From a script inside the unit tests framework folder (\"t\" folder) by\n+#     sourcing this script and then manually calling \"run_unit_tests\", which\n+#     will run a battery of unit tests to make sure nothing breaks.\n+#     In this context this script does not expect any particular environment\n+#     variable to be set.\n+\n+\n+################################################################################\n+## Internal functions (not meant to be used outside this script)\n+################################################################################\n+\n+debug_print () {\n+\t# Send message to stderr if global variable GIT_MERGETOOL_VIMDIFF is set\n+\t# to \"true\"\n+\n+\tif test -n \"$GIT_MERGETOOL_VIMDIFF_DEBUG\"\n+\tthen\n+\t\t>&2 echo \"$@\"\n+\tfi\n+}\n+\n+substring () {\n+\t# Return a substring of $1 containing $3 characters starting at\n+\t# zero-based offset $2.\n+\t#\n+\t# Examples:\n+\t#\n+\t#   substring \"Hello world\" 0 4  --> \"Hell\"\n+\t#   substring \"Hello world\" 3 4  --> \"lo w\"\n+\t#   substring \"Hello world\" 3 10 --> \"lo world\"\n+\n+\tSTRING=$1\n+\tSTART=$2\n+\tLEN=$3\n+\n+\techo \"$STRING\" | cut -c$(( START + 1 ))-$(( START + $LEN ))\n+}\n+\n+gen_cmd_aux () {\n+\t# Auxiliary function used from \"gen_cmd()\".\n+\t# Read that other function documentation for more details.\n+\n+\tLAYOUT=$1\n+\tCMD=$2  # This is a second (hidden) argument used for recursion\n+\n+\tdebug_print\n+\tdebug_print \"LAYOUT    : $LAYOUT\"\n+\tdebug_print \"CMD       : $CMD\"\n+\n+\tif test -z \"$CMD\"\n+\tthen\n+\t\tCMD=\"echo\" # vim \"nop\" operator\n+\tfi\n+\n+\tstart=0\n+\tend=${#LAYOUT}\n+\n+\tnested=0\n+\tnested_min=100\n+\n+\n+\t# Step 1:\n+\t#\n+\t# Increase/decrease \"start\"/\"end\" indices respectively to get rid of\n+\t# outer parenthesis.\n+\t#\n+\t# Example:\n+\t#\n+\t#   - BEFORE: (( LOCAL , BASE ) / MERGED )\n+\t#   - AFTER :  ( LOCAL , BASE ) / MERGED\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(echo \"$LAYOUT\" | sed 's:.:&#:g')\n+\tdo\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" -lt \"$nested_min\"\n+\t\tthen\n+\t\t\tnested_min=$nested\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\tdebug_print \"NESTED MIN: $nested_min\"\n+\n+\twhile test \"$nested_min\" -gt \"0\"\n+\tdo\n+\t\tstart=$(( start + 1 ))\n+\t\tend=$(( end - 1 ))\n+\n+\t\tstart_minus_one=$(( start - 1 ))\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$start_minus_one\" 1)\" = \"(\"\n+\t\tdo\n+\t\t\tstart=$(( start + 1 ))\n+\t\t\tstart_minus_one=$(( start_minus_one + 1 ))\n+\t\tdone\n+\n+\t\twhile ! test \"$(substring \"$LAYOUT\" \"$end\" 1)\" = \")\"\n+\t\tdo\n+\t\t\tend=$(( end - 1 ))\n+\t\tdone\n+\n+\t\tnested_min=$(( nested_min - 1 ))\n+\tdone\n+\n+\tdebug_print \"CLEAN     : $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\")\"\n+\n+\n+\t# Step 2:\n+\t#\n+\t# Search for all valid separators (\"+\", \"/\" or \",\") which are *not*\n+\t# inside parenthesis. Save the index at which each of them makes the\n+\t# first appearance.\n+\n+\tindex_new_tab=\"\"\n+\tindex_horizontal_split=\"\"\n+\tindex_vertical_split=\"\"\n+\n+\tnested=0\n+\ti=$(( start - 1 ))\n+\n+\toldIFS=$IFS\n+\tIFS=#\n+\tfor c in $(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:.:&#:g');\n+\tdo\n+\t\ti=$(( i + 1 ))\n+\n+\t\tif test \"$c\" = \" \"\n+\t\tthen\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \"(\"\n+\t\tthen\n+\t\t\tnested=$(( nested + 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$c\" = \")\"\n+\t\tthen\n+\t\t\tnested=$(( nested - 1 ))\n+\t\t\tcontinue\n+\t\tfi\n+\n+\t\tif test \"$nested\" = 0\n+\t\tthen\n+\t\t\tcurrent=$c\n+\n+\t\t\tif test \"$current\" = \"+\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_new_tab\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_new_tab=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \"/\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_horizontal_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_horizontal_split=$i\n+\t\t\t\tfi\n+\n+\t\t\telif test \"$current\" = \",\"\n+\t\t\tthen\n+\t\t\t\tif test -z \"$index_vertical_split\"\n+\t\t\t\tthen\n+\t\t\t\t\tindex_vertical_split=$i\n+\t\t\t\tfi\n+\t\t\tfi\n+\t\tfi\n+\tdone\n+\tIFS=$oldIFS\n+\n+\n+\t# Step 3:\n+\t#\n+\t# Process the separator with the highest order of precedence\n+\t# (\";\" has the highest precedence and \"|\" the lowest one).\n+\t#\n+\t# By \"process\" I mean recursively call this function twice: the first\n+\t# one with the substring at the left of the separator and the second one\n+\t# with the one at its right.\n+\n+\tterminate=\"false\"\n+\n+\tif ! test -z \"$index_new_tab\"\n+\tthen\n+\t\tbefore=\"-tabnew\"\n+\t\tafter=\"tabnext\"\n+\t\tindex=$index_new_tab\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_horizontal_split\"\n+\tthen\n+\t\tbefore=\"split\"\n+\t\tafter=\"wincmd j\"\n+\t\tindex=$index_horizontal_split\n+\t\tterminate=\"true\"\n+\n+\telif ! test -z \"$index_vertical_split\"\n+\tthen\n+\t\tbefore=\"vertical split\"\n+\t\tafter=\"wincmd l\"\n+\t\tindex=$index_vertical_split\n+\t\tterminate=\"true\"\n+\tfi\n+\n+\tif  test \"$terminate\" = \"true\"\n+\tthen\n+\t\tCMD=\"$CMD | $before\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$start\" \"$(( index - start ))\")\" \"$CMD\")\n+\t\tCMD=\"$CMD | $after\"\n+\t\tCMD=$(gen_cmd_aux \"$(substring \"$LAYOUT\" \"$(( index + 1 ))\" \"$(( ${#LAYOUT} - index ))\")\" \"$CMD\")\n+\t\techo \"$CMD\"\n+\t\treturn\n+\tfi\n+\n+\n+\t# Step 4:\n+\t#\n+\t# If we reach this point, it means there are no separators and we just\n+\t# need to print the command to display the specified buffer\n+\n+\ttarget=$(substring \"$LAYOUT\" \"$start\" \"$(( end - start ))\" | sed 's:[ @();|-]::g')\n+\n+\tif test \"$target\" = \"LOCAL\"\n+\tthen\n+\t\tCMD=\"$CMD | 1b\"\n+\n+\telif test \"$target\" = \"BASE\"\n+\tthen\n+\t\tCMD=\"$CMD | 2b\"\n+\n+\telif test \"$target\" = \"REMOTE\"\n+\tthen\n+\t\tCMD=\"$CMD | 3b\"\n+\n+\telif test \"$target\" = \"MERGED\"\n+\tthen\n+\t\tCMD=\"$CMD | 4b\"\n+\n+\telse\n+\t\tCMD=\"$CMD | ERROR: >$target<\"\n+\tfi\n+\n+\techo \"$CMD\"\n+\treturn\n+}\n+\n+\n+gen_cmd () {\n+\t# This function returns (in global variable FINAL_CMD) the string that\n+\t# you can use when invoking \"vim\" (as shown next) to obtain a given\n+\t# layout:\n+\t#\n+\t#   $ vim -f $FINAL_CMD \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\t#\n+\t# It takes one single argument: a string containing the desired layout\n+\t# definition.\n+\t#\n+\t# The syntax of the \"layout definitions\" is explained in \"Documentation/\n+\t# mergetools/vimdiff.txt\" but you can already intuitively understand how\n+\t# it works by knowing that...\n+\t#\n+\t#   * \"+\" means \"a new vim tab\"\n+\t#   * \"/\" means \"a new vim horizontal split\"\n+\t#   * \",\" means \"a new vim vertical split\"\n+\t#\n+\t# It also returns (in global variable FINAL_TARGET) the name (\"LOCAL\",\n+\t# \"BASE\", \"REMOTE\" or \"MERGED\") of the file that is marked with an \"@\",\n+\t# or \"MERGED\" if none of them is.\n+\t#\n+\t# Example:\n+\t#\n+\t#     gen_cmd \"@LOCAL , REMOTE\"\n+\t#     |\n+\t#     `-> FINAL_CMD    == \"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\t#         FINAL_TARGET == \"LOCAL\"\n+\n+\tLAYOUT=$1\n+\n+\n+\t# Search for a \"@\" in one of the files identifiers (\"LOCAL\", \"BASE\",\n+\t# \"REMOTE\", \"MERGED\"). If not found, use \"MERGE\" as the default file\n+\t# where changes will be saved.\n+\n+\tif echo \"$LAYOUT\" | grep @LOCAL >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"LOCAL\"\n+\telif echo \"$LAYOUT\" | grep @BASE >/dev/null\n+\tthen\n+\t\tFINAL_TARGET=\"BASE\"\n+\telse\n+\t\tFINAL_TARGET=\"MERGED\"\n+\tfi\n+\n+\n+\t# Obtain the first part of vim \"-c\" option to obtain the desired layout\n+\n+\tCMD=$(gen_cmd_aux \"$LAYOUT\")\n+\n+\n+\t# Adjust the just obtained script depending on whether more than one\n+\t# windows are visible or not\n+\n+\tif echo \"$LAYOUT\" | grep \",\\|/\" >/dev/null\n+\tthen\n+\t\tCMD=\"$CMD | tabdo windo diffthis\"\n+\telse\n+\t\tCMD=\"$CMD | bufdo diffthis\"\n+\tfi\n+\n+\n+\t# Add an extra \"-c\" option to move to the first tab (notice that we\n+\t# can't simply append the command to the previous \"-c\" string as\n+\t# explained here: https://github.com/vim/vim/issues/9076\n+\n+\tFINAL_CMD=\"-c \\\"$CMD\\\" -c \\\"tabfirst\\\"\"\n+}\n+\n+\n+################################################################################\n+## API functions (called from \"git-mergetool--lib.sh\")\n+################################################################################\n+\n diff_cmd () {\n \t\"$merge_tool_path\" -R -f -d \\\n \t\t-c 'wincmd l' -c 'cd $GIT_PREFIX' \"$LOCAL\" \"$REMOTE\"\n }\n \n+\n merge_cmd () {\n+\tlayout=$(git config mergetool.vimdiff.layout)\n+\n \tcase \"$1\" in\n \t*vimdiff)\n-\t\tif $base_present\n+\t\tif test -z \"$layout\"\n \t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c '4wincmd w | wincmd J' \\\n-\t\t\t\t\"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\t\t# Default layout when none is specified\n+\t\t\tlayout=\"(LOCAL,BASE,REMOTE)/MERGED\"\n \t\tfi\n \t\t;;\n \t*vimdiff1)\n-\t\t\"$merge_tool_path\" -f -d \\\n-\t\t\t-c 'echon \"Resolve conflicts leftward then save. Use :cq to abort.\"' \\\n-\t\t\t\"$LOCAL\" \"$REMOTE\"\n-\t\tret=\"$?\"\n-\t\tif test \"$ret\" -eq 0\n-\t\tthen\n-\t\t\tcp -- \"$LOCAL\" \"$MERGED\"\n-\t\tfi\n-\t\treturn \"$ret\"\n+\t\tlayout=\"@LOCAL,REMOTE\"\n \t\t;;\n \t*vimdiff2)\n-\t\t\"$merge_tool_path\" -f -d -c 'wincmd l' \\\n-\t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\"\n+\t\tlayout=\"LOCAL,MERGED,REMOTE\"\n \t\t;;\n \t*vimdiff3)\n-\t\tif $base_present\n-\t\tthen\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"\n-\t\telse\n-\t\t\t\"$merge_tool_path\" -f -d -c 'hid | hid' \\\n-\t\t\t\t\"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n-\t\tfi\n+\t\tlayout=\"MERGED\"\n \t\t;;\n \tesac\n+\n+\tgen_cmd \"$layout\"\n+\n+\tdebug_print \"\"\n+\tdebug_print \"FINAL CMD : $FINAL_CMD\"\n+\tdebug_print \"FINAL TAR : $FINAL_TARGET\"\n+\n+\tif $base_present\n+\tthen\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$BASE\" \"$REMOTE\" \"$MERGED\"\n+\telse\n+\t\t# If there is no BASE (example: a merge conflict in a new file\n+\t\t# with the same name created in both braches which didn't exist\n+\t\t# before), close all BASE windows using vim's \"quit\" command\n+\n+\t\tFINAL_CMD=$(echo \"$FINAL_CMD\" | \\\n+\t\t\tsed -e 's:2b:quit:g' -e 's:3b:2b:g' -e 's:4b:3b:g')\n+\n+\t\teval \"$merge_tool_path\" \\\n+\t\t\t-f \"$FINAL_CMD\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"\n+\tfi\n+\n+\tret=\"$?\"\n+\n+\tif test \"$ret\" -eq 0\n+\tthen\n+\t\tcase \"$FINAL_TARGET\" in\n+\t\tLOCAL)\n+\t\t\tsource_path=\"$LOCAL\"\n+\t\t\t;;\n+\t\tREMOTE)\n+\t\t\tsource_path=\"$REMOTE\"\n+\t\t\t;;\n+\t\tMERGED|*)\n+\t\t\t# Do nothing\n+\t\t\tsource_path=\n+\t\t\t;;\n+\t\tesac\n+\n+\t\tif test -n \"$source_path\"\n+\t\tthen\n+\t\t\tcp \"$source_path\" \"$MERGED\"\n+\t\tfi\n+\tfi\n+\n+\treturn \"$ret\"\n }\n \n-translate_merge_tool_path() {\n+\n+translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n \t\techo nvim\n@@ -57,14 +450,121 @@ translate_merge_tool_path() {\n \tesac\n }\n \n+\n exit_code_trustable () {\n \ttrue\n }\n \n+\n list_tool_variants () {\n-\tfor prefix in '' g n; do\n-\t\tfor suffix in '' 1 2 3; do\n-\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\tif test \"$TOOL_MODE\" = \"diff\"\n+\tthen\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\techo \"${prefix}vimdiff\"\n \t\tdone\n+\telse\n+\t\tfor prefix in '' g n\n+\t\tdo\n+\t\t\tfor suffix in '' 1 2 3\n+\t\t\tdo\n+\t\t\t\techo \"${prefix}vimdiff${suffix}\"\n+\t\t\tdone\n+\t\tdone\n+\tfi\n+}\n+\n+\n+################################################################################\n+## Unit tests (called from scripts inside the \"t\" folder)\n+################################################################################\n+\n+run_unit_tests () {\n+\t# Function to make sure that we don't break anything when modifying this\n+\t# script.\n+\n+\tNUMBER_OF_TEST_CASES=16\n+\n+\tTEST_CASE_01=\"(LOCAL,BASE,REMOTE)/MERGED\"   # default behaviour\n+\tTEST_CASE_02=\"@LOCAL,REMOTE\"                # when using vimdiff1\n+\tTEST_CASE_03=\"LOCAL,MERGED,REMOTE\"          # when using vimdiff2\n+\tTEST_CASE_04=\"MERGED\"                       # when using vimdiff3\n+\tTEST_CASE_05=\"LOCAL/MERGED/REMOTE\"\n+\tTEST_CASE_06=\"(LOCAL/REMOTE),MERGED\"\n+\tTEST_CASE_07=\"MERGED,(LOCAL/REMOTE)\"\n+\tTEST_CASE_08=\"(LOCAL,REMOTE)/MERGED\"\n+\tTEST_CASE_09=\"MERGED/(LOCAL,REMOTE)\"\n+\tTEST_CASE_10=\"(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_11=\"(LOCAL,BASE,REMOTE)/MERGED+BASE,LOCAL+BASE,REMOTE+(LOCAL/BASE/REMOTE),MERGED\"\n+\tTEST_CASE_12=\"((LOCAL,REMOTE)/BASE),MERGED\"\n+\tTEST_CASE_13=\"((LOCAL,REMOTE)/BASE),((LOCAL/REMOTE),MERGED)\"\n+\tTEST_CASE_14=\"BASE,REMOTE+BASE,LOCAL\"\n+\tTEST_CASE_15=\"  ((  (LOCAL , BASE , REMOTE) / MERGED))   +(BASE)   , LOCAL+ BASE , REMOTE+ (((LOCAL / BASE / REMOTE)) ,    MERGED   )  \"\n+\tTEST_CASE_16=\"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL / BASE / REMOTE),MERGED\"\n+\n+\tEXPECTED_CMD_01=\"-c \\\"echo | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_02=\"-c \\\"echo | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_03=\"-c \\\"echo | vertical split | 1b | wincmd l | vertical split | 4b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_04=\"-c \\\"echo | 4b | bufdo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_05=\"-c \\\"echo | split | 1b | wincmd j | split | 4b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_06=\"-c \\\"echo | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_07=\"-c \\\"echo | vertical split | 4b | wincmd l | split | 1b | wincmd j | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_08=\"-c \\\"echo | split | vertical split | 1b | wincmd l | 3b | wincmd j | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_09=\"-c \\\"echo | split | 4b | wincmd j | vertical split | 1b | wincmd l | 3b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_10=\"-c \\\"echo | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_11=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_12=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_13=\"-c \\\"echo | vertical split | split | vertical split | 1b | wincmd l | 3b | wincmd j | 2b | wincmd l | vertical split | split | 1b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_14=\"-c \\\"echo | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | 2b | wincmd l | 1b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_15=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\tEXPECTED_CMD_16=\"-c \\\"echo | -tabnew | split | vertical split | 1b | wincmd l | vertical split | 2b | wincmd l | 3b | wincmd j | 4b | tabnext | -tabnew | vertical split | 2b | wincmd l | 1b | tabnext | -tabnew | vertical split | 2b | wincmd l | 3b | tabnext | vertical split | split | 1b | wincmd j | split | 2b | wincmd j | 3b | wincmd l | 4b | tabdo windo diffthis\\\" -c \\\"tabfirst\\\"\"\n+\n+\tEXPECTED_TARGET_01=\"MERGED\"\n+\tEXPECTED_TARGET_02=\"LOCAL\"\n+\tEXPECTED_TARGET_03=\"MERGED\"\n+\tEXPECTED_TARGET_04=\"MERGED\"\n+\tEXPECTED_TARGET_05=\"MERGED\"\n+\tEXPECTED_TARGET_06=\"MERGED\"\n+\tEXPECTED_TARGET_07=\"MERGED\"\n+\tEXPECTED_TARGET_08=\"MERGED\"\n+\tEXPECTED_TARGET_09=\"MERGED\"\n+\tEXPECTED_TARGET_10=\"MERGED\"\n+\tEXPECTED_TARGET_11=\"MERGED\"\n+\tEXPECTED_TARGET_12=\"MERGED\"\n+\tEXPECTED_TARGET_13=\"MERGED\"\n+\tEXPECTED_TARGET_14=\"MERGED\"\n+\tEXPECTED_TARGET_15=\"MERGED\"\n+\tEXPECTED_TARGET_16=\"MERGED\"\n+\n+\tat_least_one_ko=\"false\"\n+\n+\tfor i in $(seq -w 1 99)\n+\tdo\n+\t\tif test \"$i\" -gt $NUMBER_OF_TEST_CASES\n+\t\tthen\n+\t\t\tbreak\n+\t\tfi\n+\n+\t\tgen_cmd \"$(eval echo \\${TEST_CASE_\"$i\"})\"\n+\n+\t\tif test \"$FINAL_CMD\" = \"$(eval echo \\${EXPECTED_CMD_\"$i\"})\" \\\n+\t\t\t&& test \"$FINAL_TARGET\" = \"$(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\tthen\n+\t\t\tprintf \"Test Case #%02d: OK\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\telse\n+\t\t\tprintf \"Test Case #%02d: KO !!!!\\n\" \"$(echo \"$i\" | sed 's/^0*//')\"\n+\t\t\techo \"  FINAL_CMD              : $FINAL_CMD\"\n+\t\t\techo \"  FINAL_CMD (expected)   : $(eval echo \\${EXPECTED_CMD_\"$i\"})\"\n+\t\t\techo \"  FINAL_TARGET           : $FINAL_TARGET\"\n+\t\t\techo \"  FINAL_TARGET (expected): $(eval echo \\${EXPECTED_TARGET_\"$i\"})\"\n+\t\t\tat_least_one_ko=\"true\"\n+\t\tfi\n \tdone\n+\n+\tif test \"$at_least_one_ko\" = \"true\"\n+\tthen\n+\t\treturn 255\n+\telse\n+\t\treturn 0\n+\tfi\n }\n-- \n2.35.1\n\n"},{"id":"452695","messageId":"20220330191909.294610-3-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220330191909.294610-1-greenfoo@u92.eu","subject":"[PATCH v9 2/4] vimdiff: integrate layout tests in the unit tests framework ('t' folder)","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T19:19:07Z","receivedAt":"2022-03-30T19:19:49Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Create a new test case file for the different available merge tools.\nRight now it only tests the 'mergetool.vimdiff.layout' option. Other\nmerge tools might be interested in adding their own tests here too.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n t/t7609-mergetool--lib.sh | 14 ++++++++++++++\n 1 file changed, 14 insertions(+)\n create mode 100755 t/t7609-mergetool--lib.sh\n\ndiff --git a/t/t7609-mergetool--lib.sh b/t/t7609-mergetool--lib.sh\nnew file mode 100755\nindex 0000000000..d848fe6442\n--- /dev/null\n+++ b/t/t7609-mergetool--lib.sh\n@@ -0,0 +1,14 @@\n+#!/bin/sh\n+\n+test_description='git mergetool\n+\n+Testing basic merge tools options'\n+\n+. ./test-lib.sh\n+\n+test_expect_success 'mergetool --tool=vimdiff creates the expected layout' '\n+\t. $GIT_BUILD_DIR/mergetools/vimdiff &&\n+\trun_unit_tests\n+'\n+\n+test_done\n-- \n2.35.1\n\n"},{"id":"452696","messageId":"20220330191909.294610-4-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220330191909.294610-1-greenfoo@u92.eu","subject":"[PATCH v9 3/4] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T19:19:08Z","receivedAt":"2022-03-30T19:20:05Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"Running 'git {merge,diff}tool --tool-help' now also prints usage\ninformation about the vimdiff tool (and its variants) instead of just\nits name.\n\nTwo new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\nadded to the set of functions that each merge tool (ie. scripts found\ninside \"mergetools/\") can overwrite to provided tool specific\ninformation.\n\nRight now, only 'mergetools/vimdiff' implements these functions, but\nother tools are encouraged to do so in the future, specially if they\ntake configuration options not explained anywhere else (as it is the\ncase with the 'vimdiff' tool and the new 'layout' option)\n\nNote that the function 'show_tool_names', used in the implmentation of\n'git mergetool --tool-help', is also used in Documentation/Makefile to\ngenerate the list of allowed values for the configuration variables\n'{diff,merge}.{gui,}tool'. Adjust the rule so its output is an Asciidoc\n\"description list\" instead of a plain list, with the tool name as the\nitem and the newly added tool description as the description.\n\nIn addition, a section has been added to\n\"Documentation/git-mergetool.txt\" to explain the new \"layout\"\nconfiguration option with examples.\n\nHelped-by: Philippe Blain <levraiphilippeblain@gmail.com>\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n Documentation/Makefile               |   8 +-\n Documentation/config/mergetool.txt   |   9 ++\n Documentation/git-mergetool.txt      |   8 ++\n Documentation/mergetools/vimdiff.txt | 194 +++++++++++++++++++++++++++\n git-mergetool--lib.sh                |  10 +-\n mergetools/vimdiff                   |  53 ++++++++\n 6 files changed, 277 insertions(+), 5 deletions(-)\n create mode 100644 Documentation/mergetools/vimdiff.txt\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex 1eb9192dae..faed285462 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -302,12 +302,12 @@ $(mergetools_txt): mergetools-list.made\n \n mergetools-list.made: ../git-mergetool--lib.sh $(wildcard ../mergetools/*)\n \t$(QUIET_GEN) \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=diff && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_diff \"* \" || :' >mergetools-diff.txt && \\\n-\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && \\\n+\t\tshow_tool_names can_diff' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-diff.txt && \\\n+\t$(SHELL_PATH) -c 'MERGE_TOOLS_DIR=../mergetools && TOOL_MODE=merge && \\\n \t\t. ../git-mergetool--lib.sh && \\\n-\t\tshow_tool_names can_merge \"* \" || :' >mergetools-merge.txt && \\\n+\t\tshow_tool_names can_merge' | sed -e \"s/\\([a-z0-9]*\\)/\\`\\1\\`;;/\" >mergetools-merge.txt && \\\n \tdate >$@\n \n TRACK_ASCIIDOCFLAGS = $(subst ','\\'',$(ASCIIDOC_COMMON):$(ASCIIDOC_HTML):$(ASCIIDOC_DOCBOOK))\ndiff --git a/Documentation/config/mergetool.txt b/Documentation/config/mergetool.txt\nindex cafbbef46a..90b3809700 100644\n--- a/Documentation/config/mergetool.txt\n+++ b/Documentation/config/mergetool.txt\n@@ -45,6 +45,15 @@ mergetool.meld.useAutoMerge::\n \tvalue of `false` avoids using `--auto-merge` altogether, and is the\n \tdefault value.\n \n+mergetool.vimdiff.layout::\n+\tThe vimdiff backend uses this variable to control how its split\n+\twindows look like. Applies even if you are using Neovim (`nvim`) or\n+\tgVim (`gvim`) as the merge tool. See BACKEND SPECIFIC HINTS section\n+ifndef::git-mergetool[]\n+\tin linkgit:git-mergetool[1].\n+endif::[]\n+\tfor details.\n+\n mergetool.hideResolved::\n \tDuring a merge Git will automatically resolve as many conflicts as\n \tpossible and write the 'MERGED' file containing conflict markers around\ndiff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt\nindex e587c7763a..f784027bc1 100644\n--- a/Documentation/git-mergetool.txt\n+++ b/Documentation/git-mergetool.txt\n@@ -101,6 +101,7 @@ success of the resolution after the custom tool has exited.\n \n CONFIGURATION\n -------------\n+:git-mergetool: 1\n include::config/mergetool.txt[]\n \n TEMPORARY FILES\n@@ -113,6 +114,13 @@ Setting the `mergetool.keepBackup` configuration variable to `false`\n causes `git mergetool` to automatically remove the backup as files\n are successfully merged.\n \n+BACKEND SPECIFIC HINTS\n+----------------------\n+\n+vimdiff\n+~~~~~~~\n+include::mergetools/vimdiff.txt[]\n+\n GIT\n ---\n Part of the linkgit:git[1] suite\ndiff --git a/Documentation/mergetools/vimdiff.txt b/Documentation/mergetools/vimdiff.txt\nnew file mode 100644\nindex 0000000000..2d631e9b1f\n--- /dev/null\n+++ b/Documentation/mergetools/vimdiff.txt\n@@ -0,0 +1,194 @@\n+Description\n+^^^^^^^^^^^\n+\n+When specifying `--tool=vimdiff` in `git mergetool` Git will open Vim with a 4\n+windows layout distributed in the following way:\n+....\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n+`LOCAL`, `BASE` and `REMOTE` are read-only buffers showing the contents of the\n+conflicting file in specific commits (\"commit you are merging into\", \"common\n+ancestor commit\" and \"commit you are merging from\" respectively)\n+\n+`MERGED` is a writable buffer where you have to resolve the conflicts (using the\n+other read-only buffers as a reference). Once you are done, save and exit Vim as\n+usual (`:wq`) or, if you want to abort, exit using `:cq`.\n+\n+Layout configuration\n+^^^^^^^^^^^^^^^^^^^^\n+\n+You can change the windows layout used by Vim by setting configuration variable\n+`mergetool.vimdiff.layout` which accepts a string where the following separators\n+have special meaning:\n+\n+  - `+` is used to \"open a new tab\"\n+  - `,` is used to \"open a new vertical split\"\n+  - `/` is used to \"open a new horizontal split\"\n+  - `@` is used to indicate which is the file containing the final version after\n+    solving the conflicts. If not present, `MERGED` will be used by default.\n+\n+The precedence of the operators is this one (you can use parentheses to change\n+it):\n+\n+    `@` > `+` > `/` > `,`\n+\n+Let's see some examples to understand how it works:\n+\n+* `layout = \"(LOCAL,BASE,REMOTE)/MERGED\"`\n++\n+--\n+This is exactly the same as the default layout we have already seen.\n+\n+Note that `/` has precedence over `,` and thus the parenthesis are not\n+needed in this case. The next layout definition is equivalent:\n+\n+    layout = \"LOCAL,BASE,REMOTE / MERGED\"\n+--\n+* `layout = \"LOCAL,MERGED,REMOTE\"`\n++\n+--\n+If, for some reason, we are not interested in the `BASE` buffer.\n+....\n+------------------------------------------\n+|             |           |              |\n+|             |           |              |\n+|   LOCAL     |   MERGED  |   REMOTE     |\n+|             |           |              |\n+|             |           |              |\n+------------------------------------------\n+....\n+--\n+* `layout = \"MERGED\"`\n++\n+--\n+Only the `MERGED` buffer will be shown. Note, however, that all the other\n+ones are still loaded in vim, and you can access them with the \"buffers\"\n+command.\n+....\n+------------------------------------------\n+|                                        |\n+|                                        |\n+|                 MERGED                 |\n+|                                        |\n+|                                        |\n+------------------------------------------\n+....\n+--\n+* `layout = \"@LOCAL,REMOTE\"`\n++\n+--\n+When `MERGED` is not present in the layout, you must \"mark\" one of the\n+buffers with an asterisk. That will become the buffer you need to edit and\n+save after resolving the conflicts.\n+....\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     LOCAL         |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE\"`\n++\n+--\n+Three tabs will open: the first one is a copy of the default layout, while\n+the other two only show the differences between (`BASE` and `LOCAL`) and\n+(`BASE` and `REMOTE`) respectively.\n+....\n+------------------------------------------\n+| <TAB #1> |  TAB #2  |  TAB #3  |       |\n+------------------------------------------\n+|             |           |              |\n+|   LOCAL     |   BASE    |   REMOTE     |\n+|             |           |              |\n+------------------------------------------\n+|                                        |\n+|                MERGED                  |\n+|                                        |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  | <TAB #2> |  TAB #3  |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    LOCAL           |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+....\n+------------------------------------------\n+|  TAB #1  |  TAB #2  | <TAB #3> |       |\n+------------------------------------------\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+|     BASE          |    REMOTE          |\n+|                   |                    |\n+|                   |                    |\n+|                   |                    |\n+------------------------------------------\n+....\n+--\n+* `layout = \"LOCAL,BASE,REMOTE / MERGED + BASE,LOCAL + BASE,REMOTE + (LOCAL/BASE/REMOTE),MERGED\"`\n++\n+--\n+Same as the previous example, but adds a fourth tab with the same\n+information as the first tab, with a different layout.\n+....\n+---------------------------------------------\n+|  TAB #1  |  TAB #2  |  TAB #3  | <TAB #4> |\n+---------------------------------------------\n+|       LOCAL         |                     |\n+|---------------------|                     |\n+|       BASE          |        MERGED       |\n+|---------------------|                     |\n+|       REMOTE        |                     |\n+---------------------------------------------\n+....\n+Note how in the third tab definition we need to use parenthesis to make `,`\n+have precedence over `/`.\n+--\n+\n+Variants\n+^^^^^^^^\n+\n+Instead of `--tool=vimdiff`, you can also use one of these other variants:\n+\n+  * `--tool=gvimdiff`, to open gVim instead of Vim.\n+\n+  * `--tool=nvimdiff`, to open Neovim instead of Vim.\n+\n+When using these variants, in order to specify a custom layout you will have to\n+set configuration variables `mergetool.gvimdiff.layout` and\n+`mergetool.nvimdiff.layout` instead of `mergetool.vimdiff.layout`\n+\n+In addition, for backwards compatibility with previous Git versions, you can\n+also append `1`, `2` or `3` to either `vimdiff` or any of the variants (ex:\n+`vimdiff3`, `nvimdiff1`, etc...) to use a predefined layout.\n+In other words, using `--tool=[g,n,]vimdiffx` is the same as using\n+`--tool=[g,n,]vimdiff` and setting configuration variable\n+`mergetool.[g,n,]vimdiff.layout` to...\n+\n+  * `x=1`: `\"@LOCAL, REMOTE\"`\n+  * `x=2`: `\"LOCAL, MERGED, REMOTE\"`\n+  * `x=3`: `\"MERGED\"`\n+\n+Example: using `--tool=gvimdiff2` will open `gvim` with three columns (LOCAL,\n+MERGED and REMOTE).\ndiff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh\nindex 542a6a75eb..9f99201bcc 100644\n--- a/git-mergetool--lib.sh\n+++ b/git-mergetool--lib.sh\n@@ -63,7 +63,7 @@ $(list_tool_variants)\"\n \t\t\t\t\tpreamble=\n \t\t\t\tfi\n \t\t\t\tshown_any=yes\n-\t\t\t\tprintf \"%s%s\\n\" \"$per_line_prefix\" \"$toolname\"\n+\t\t\t\tprintf \"%s%-15s  %s\\n\" \"$per_line_prefix\" \"$toolname\" $(diff_mode && diff_cmd_help \"$toolname\" || merge_cmd_help \"$toolname\")\n \t\t\tfi\n \t\tdone\n \n@@ -162,10 +162,18 @@ setup_tool () {\n \t\treturn 1\n \t}\n \n+\tdiff_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \tmerge_cmd () {\n \t\treturn 1\n \t}\n \n+\tmerge_cmd_help () {\n+\t\treturn 0\n+\t}\n+\n \thide_resolved_enabled () {\n \t\treturn 0\n \t}\ndiff --git a/mergetools/vimdiff b/mergetools/vimdiff\nindex 9d1bf4f455..461a89b6f9 100644\n--- a/mergetools/vimdiff\n+++ b/mergetools/vimdiff\n@@ -365,6 +365,25 @@ diff_cmd () {\n }\n \n \n+diff_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim\"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session)\"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n merge_cmd () {\n \tlayout=$(git config mergetool.vimdiff.layout)\n \n@@ -436,6 +455,40 @@ merge_cmd () {\n }\n \n \n+merge_cmd_help () {\n+\tTOOL=$1\n+\n+\tcase \"$TOOL\" in\n+\tnvimdiff*)\n+\t\tprintf \"Use Neovim \"\n+\t\t;;\n+\tgvimdiff*)\n+\t\tprintf \"Use gVim (requires a graphical session) \"\n+\t\t;;\n+\tvimdiff*)\n+\t\tprintf \"Use Vim \"\n+\t\t;;\n+\tesac\n+\n+\tcase \"$TOOL\" in\n+\t*1)\n+\t\techo \"with a 2 panes layout (LOCAL and REMOTE)\"\n+\t\t;;\n+\t*2)\n+\t\techo \"with a 3 panes layout (LOCAL, MERGED and REMOTE)\"\n+\t\t;;\n+\t*3)\n+\t\techo \"where only the MERGED file is shown\"\n+\t\t;;\n+\t*)\n+\t\techo \"with a custom layout (see \\`git help mergetool\\`'s \\`BACKEND SPECIFIC HINTS\\` section)\"\n+\t\t;;\n+\tesac\n+\n+\treturn 0\n+}\n+\n+\n translate_merge_tool_path () {\n \tcase \"$1\" in\n \tnvimdiff*)\n-- \n2.35.1\n\n"},{"id":"452697","messageId":"20220330191909.294610-5-greenfoo@u92.eu","threadId":"57629","inReplyTo":"20220330191909.294610-1-greenfoo@u92.eu","subject":"[PATCH v9 4/4] mergetools: add description to all diff/merge tools","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-03-30T19:19:09Z","receivedAt":"2022-03-30T19:20:07Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"The output of `git mergetool --tool-help` and `git difftool --tool-help`\nonly showed the `alias` of each available merge/diff tool.\n\nIt is not always obvious what tool these `aliases` end up using (ex:\n`opendiff` runs `FileMerge` and `bc` runs `Beyond Compare`).\n\nThis commit adds a short description to each of them to help the user\nidentify the `alias` they want.\n\nSigned-off-by: Fernando Ramos <greenfoo@u92.eu>\n---\n mergetools/araxis        | 8 ++++++++\n mergetools/bc            | 8 ++++++++\n mergetools/codecompare   | 8 ++++++++\n mergetools/deltawalker   | 8 ++++++++\n mergetools/diffmerge     | 8 ++++++++\n mergetools/diffuse       | 8 ++++++++\n mergetools/ecmerge       | 8 ++++++++\n mergetools/emerge        | 8 ++++++++\n mergetools/examdiff      | 8 ++++++++\n mergetools/guiffy        | 8 ++++++++\n mergetools/kdiff3        | 8 ++++++++\n mergetools/kompare       | 8 ++++++++\n mergetools/meld          | 8 ++++++++\n mergetools/opendiff      | 8 ++++++++\n mergetools/p4merge       | 8 ++++++++\n mergetools/smerge        | 8 ++++++++\n mergetools/tkdiff        | 8 ++++++++\n mergetools/tortoisemerge | 8 ++++++++\n mergetools/winmerge      | 8 ++++++++\n mergetools/xxdiff        | 8 ++++++++\n 20 files changed, 160 insertions(+)\n\ndiff --git a/mergetools/araxis b/mergetools/araxis\nindex e2407b65b7..eb32a7da95 100644\n--- a/mergetools/araxis\n+++ b/mergetools/araxis\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -wait -2 \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Araxis Merge (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \techo compare\n }\ndiff --git a/mergetools/bc b/mergetools/bc\nindex 26c19d46a5..2922667ddd 100644\n--- a/mergetools/bc\n+++ b/mergetools/bc\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Beyond Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif type bcomp >/dev/null 2>/dev/null\n \tthen\ndiff --git a/mergetools/codecompare b/mergetools/codecompare\nindex 9f60e8da65..610963d377 100644\n--- a/mergetools/codecompare\n+++ b/mergetools/codecompare\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Code Compare (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tif merge_mode\n \tthen\ndiff --git a/mergetools/deltawalker b/mergetools/deltawalker\nindex ee6f374bce..efae4c285c 100644\n--- a/mergetools/deltawalker\n+++ b/mergetools/deltawalker\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# Adding $(pwd)/ in front of $MERGED should not be necessary.\n \t# However without it, DeltaWalker (at least v1.9.8 on Windows)\n@@ -16,6 +20,10 @@ merge_cmd () {\n \tfi >/dev/null 2>&1\n }\n \n+merge_cmd_help () {\n+\techo \"Use DeltaWalker (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path () {\n \techo DeltaWalker\n }\ndiff --git a/mergetools/diffmerge b/mergetools/diffmerge\nindex 9b6355b98a..9b5b62d1ca 100644\n--- a/mergetools/diffmerge\n+++ b/mergetools/diffmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use DiffMerge (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/diffuse b/mergetools/diffuse\nindex 5a3ae8b569..ebfaba5172 100644\n--- a/mergetools/diffuse\n+++ b/mergetools/diffuse\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,3 +17,7 @@ merge_cmd () {\n \t\t\t\"$LOCAL\" \"$MERGED\" \"$REMOTE\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Diffuse (requires a graphical session)\"\n+}\ndiff --git a/mergetools/ecmerge b/mergetools/ecmerge\nindex 6c5101c4f7..0d4d609874 100644\n--- a/mergetools/ecmerge\n+++ b/mergetools/ecmerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" --default --mode=diff2 \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t--default --mode=merge2 --to=\"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use ECMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/emerge b/mergetools/emerge\nindex d1ce513ff5..fc6892cc95 100644\n--- a/mergetools/emerge\n+++ b/mergetools/emerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" -f emerge-files-command \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -17,6 +21,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Emacs' Emerge\"\n+}\n+\n translate_merge_tool_path() {\n \techo emacs\n }\ndiff --git a/mergetools/examdiff b/mergetools/examdiff\nindex e72b06fc4d..6f53ca9161 100644\n--- a/mergetools/examdiff\n+++ b/mergetools/examdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" -nh\n }\n \n+diff_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -11,6 +15,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use ExamDiff Pro (requires a graphical session)\"\n+}\n+\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"ExamDiff.com\" \"ExamDiff Pro\"\n }\ndiff --git a/mergetools/guiffy b/mergetools/guiffy\nindex 8b23a13c41..3ed07efd16 100644\n--- a/mergetools/guiffy\n+++ b/mergetools/guiffy\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -13,6 +17,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Guiffy's Diff Tool (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kdiff3 b/mergetools/kdiff3\nindex 520cb914a1..ee8b3a0570 100644\n--- a/mergetools/kdiff3\n+++ b/mergetools/kdiff3\n@@ -4,6 +4,10 @@ diff_cmd () {\n \t\t\"$LOCAL\" \"$REMOTE\" >/dev/null 2>&1\n }\n \n+diff_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -22,6 +26,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use KDiff3 (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/kompare b/mergetools/kompare\nindex e8c0bfa678..4ce23dbe8b 100644\n--- a/mergetools/kompare\n+++ b/mergetools/kompare\n@@ -2,10 +2,18 @@ can_merge () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+merge_cmd_help () {\n+\techo \"Use Kompare (requires a graphical session)\"\n+}\n+\n exit_code_trustable () {\n \ttrue\n }\ndiff --git a/mergetools/meld b/mergetools/meld\nindex aab4ebb935..8ec0867e03 100644\n--- a/mergetools/meld\n+++ b/mergetools/meld\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Meld (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tcheck_meld_for_features\n \n@@ -20,6 +24,10 @@ merge_cmd () {\n \tfi\n }\n \n+merge_cmd_help () {\n+\techo \"Use Meld (requires a graphical session) with optional \\`auto merge\\` (see \\`git help mergetool\\`'s \\`CONFIGURATION\\` section)\"\n+}\n+\n # Get meld help message\n init_meld_help_msg () {\n \tif test -z \"$meld_help_msg\"\ndiff --git a/mergetools/opendiff b/mergetools/opendiff\nindex b608dd6de3..44adf8f951 100644\n--- a/mergetools/opendiff\n+++ b/mergetools/opendiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\" | cat\n }\n \n+diff_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -12,3 +16,7 @@ merge_cmd () {\n \t\t\t-merge \"$MERGED\" | cat\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use FileMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/p4merge b/mergetools/p4merge\nindex 7a5b291dd2..f3cb197e58 100644\n--- a/mergetools/p4merge\n+++ b/mergetools/p4merge\n@@ -19,6 +19,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif ! $base_present\n \tthen\n@@ -34,3 +38,7 @@ create_empty_file () {\n \n \tprintf \"%s\" \"$empty_file\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use HelixCore P4Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/smerge b/mergetools/smerge\nindex 9c2e6f6fd7..5410835a6b 100644\n--- a/mergetools/smerge\n+++ b/mergetools/smerge\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -10,3 +14,7 @@ merge_cmd () {\n \t\t\"$merge_tool_path\" mergetool \"$LOCAL\" \"$REMOTE\" -o \"$MERGED\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use Sublime Merge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tkdiff b/mergetools/tkdiff\nindex eee5cb57e3..66906a720d 100644\n--- a/mergetools/tkdiff\n+++ b/mergetools/tkdiff\n@@ -2,6 +2,10 @@ diff_cmd () {\n \t\"$merge_tool_path\" \"$LOCAL\" \"$REMOTE\"\n }\n \n+diff_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -14,3 +18,7 @@ merge_cmd () {\n exit_code_trustable () {\n \ttrue\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TkDiff (requires a graphical session)\"\n+}\ndiff --git a/mergetools/tortoisemerge b/mergetools/tortoisemerge\nindex d7ab666a59..507edcd444 100644\n--- a/mergetools/tortoisemerge\n+++ b/mergetools/tortoisemerge\n@@ -2,6 +2,10 @@ can_diff () {\n \treturn 1\n }\n \n+diff_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -30,3 +34,7 @@ translate_merge_tool_path() {\n \t\techo tortoisemerge\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use TortoiseMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/winmerge b/mergetools/winmerge\nindex 74d03259fd..36c72dde6e 100644\n--- a/mergetools/winmerge\n+++ b/mergetools/winmerge\n@@ -3,6 +3,10 @@ diff_cmd () {\n \treturn 0\n }\n \n+diff_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \t# mergetool.winmerge.trustExitCode is implicitly false.\n \t# touch $BACKUP so that we can check_unchanged.\n@@ -13,3 +17,7 @@ merge_cmd () {\n translate_merge_tool_path() {\n \tmergetool_find_win32_cmd \"WinMergeU.exe\" \"WinMerge\"\n }\n+\n+merge_cmd_help () {\n+\techo \"Use WinMerge (requires a graphical session)\"\n+}\ndiff --git a/mergetools/xxdiff b/mergetools/xxdiff\nindex d5ce467995..cd205f9842 100644\n--- a/mergetools/xxdiff\n+++ b/mergetools/xxdiff\n@@ -12,6 +12,10 @@ diff_cmd () {\n \tfi\n }\n \n+diff_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n+\n merge_cmd () {\n \tif $base_present\n \tthen\n@@ -28,3 +32,7 @@ merge_cmd () {\n \t\t\t--merged-file \"$MERGED\" \"$LOCAL\" \"$REMOTE\"\n \tfi\n }\n+\n+merge_cmd_help () {\n+\techo \"Use xxdiff (requires a graphical session)\"\n+}\n-- \n2.35.1\n\n"},{"id":"453004","messageId":"d01710e1-8a42-e4d1-5034-f6796372587e@gmail.com","threadId":"57629","inReplyTo":"20220330191909.294610-4-greenfoo@u92.eu","subject":"Re: [PATCH v9 3/4] vimdiff: add tool documentation","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2022-04-03T20:02:08Z","receivedAt":"2022-04-03T20:02:14Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Fernando,\n\nLe 2022-03-30 à 15:19, Fernando Ramos a écrit :\n> Running 'git {merge,diff}tool --tool-help' now also prints usage\n> information about the vimdiff tool (and its variants) instead of just\n> its name.\n> \n> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n> added to the set of functions that each merge tool (ie. scripts found\n> inside \"mergetools/\") can overwrite to provided tool specific\n> information.\n> \n> Right now, only 'mergetools/vimdiff' implements these functions, but\n> other tools are encouraged to do so in the future, specially if they\n> take configuration options not explained anywhere else (as it is the\n> case with the 'vimdiff' tool and the new 'layout' option)\n> \n> Note that the function 'show_tool_names', used in the implmentation of\n\ntypo here: implementation (by bad!)\n\nMaybe Junio will correct it before merging to next ?\n\nPhilippe.\n"},{"id":"453013","messageId":"xmqq1qydu6r1.fsf@gitster.g","threadId":"57629","inReplyTo":"d01710e1-8a42-e4d1-5034-f6796372587e@gmail.com","subject":"Re: [PATCH v9 3/4] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-04-03T22:44:34Z","receivedAt":"2022-04-03T22:44:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Philippe Blain <levraiphilippeblain@gmail.com> writes:\n\n> Hi Fernando,\n>\n> Le 2022-03-30 à 15:19, Fernando Ramos a écrit :\n>> Running 'git {merge,diff}tool --tool-help' now also prints usage\n>> information about the vimdiff tool (and its variants) instead of just\n>> its name.\n>> \n>> Two new functions ('diff_cmd_help()' and 'merge_cmd_help()') have been\n>> added to the set of functions that each merge tool (ie. scripts found\n>> inside \"mergetools/\") can overwrite to provided tool specific\n>> information.\n>> \n>> Right now, only 'mergetools/vimdiff' implements these functions, but\n>> other tools are encouraged to do so in the future, specially if they\n>> take configuration options not explained anywhere else (as it is the\n>> case with the 'vimdiff' tool and the new 'layout' option)\n>> \n>> Note that the function 'show_tool_names', used in the implmentation of\n>\n> typo here: implementation (by bad!)\n>\n> Maybe Junio will correct it before merging to next ?\n\nThanks.\n\n$ git range-diff @{1}...\n1:  7efd9fdf62 ! 1:  7b5cf8be18 vimdiff: add tool documentation\n    @@ Commit message\n         take configuration options not explained anywhere else (as it is the\n         case with the 'vimdiff' tool and the new 'layout' option)\n     \n    -    Note that the function 'show_tool_names', used in the implmentation of\n    +    Note that the function 'show_tool_names', used in the implementation of\n         'git mergetool --tool-help', is also used in Documentation/Makefile to\n         generate the list of allowed values for the configuration variables\n         '{diff,merge}.{gui,}tool'. Adjust the rule so its output is an Asciidoc\n2:  3e7aa9c425 = 2:  980145f747 mergetools: add description to all diff/merge tools\n"},{"id":"453046","messageId":"YktOTyBq/O9Myev6@zacax395.localdomain","threadId":"57629","inReplyTo":"xmqq1qydu6r1.fsf@gitster.g","subject":"Re: [PATCH v9 3/4] vimdiff: add tool documentation","fromName":"Fernando Ramos","fromEmail":"greenfoo@u92.eu","sentAt":"2022-04-04T20:00:15Z","receivedAt":"2022-04-04T21:23:12Z","isPatch":true,"sender":{"key":"greenfoo@u92.eu","avatar":"https://avatars.githubusercontent.com/u/42691086?v=4"},"body":"> > typo here: implementation (by bad!)\n> >\n> > Maybe Junio will correct it before merging to next ?\n> \n> Thanks.\n> \n> $ git range-diff @{1}...\n> 1:  7efd9fdf62 ! 1:  7b5cf8be18 vimdiff: add tool documentation\n>     @@ Commit message\n>          take configuration options not explained anywhere else (as it is the\n>          case with the 'vimdiff' tool and the new 'layout' option)\n>      \n>     -    Note that the function 'show_tool_names', used in the implmentation of\n>     +    Note that the function 'show_tool_names', used in the implementation of\n>          'git mergetool --tool-help', is also used in Documentation/Makefile to\n>          generate the list of allowed values for the configuration variables\n>          '{diff,merge}.{gui,}tool'. Adjust the rule so its output is an Asciidoc\n> 2:  3e7aa9c425 = 2:  980145f747 mergetools: add description to all diff/merge tools\n\nThanks! No need to roll out a v10, then?\n"},{"id":"453062","messageId":"xmqqilro34xs.fsf@gitster.g","threadId":"57629","inReplyTo":"YktOTyBq/O9Myev6@zacax395.localdomain","subject":"Re: [PATCH v9 3/4] vimdiff: add tool documentation","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-04-04T21:38:07Z","receivedAt":"2022-04-04T21:53:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fernando Ramos <greenfoo@u92.eu> writes:\n\n>> > typo here: implementation (by bad!)\n>> >\n>> > Maybe Junio will correct it before merging to next ?\n>> \n>> Thanks.\n>> \n>> $ git range-diff @{1}...\n>> 1:  7efd9fdf62 ! 1:  7b5cf8be18 vimdiff: add tool documentation\n>>     @@ Commit message\n>>          take configuration options not explained anywhere else (as it is the\n>>          case with the 'vimdiff' tool and the new 'layout' option)\n>>      \n>>     -    Note that the function 'show_tool_names', used in the implmentation of\n>>     +    Note that the function 'show_tool_names', used in the implementation of\n>>          'git mergetool --tool-help', is also used in Documentation/Makefile to\n>>          generate the list of allowed values for the configuration variables\n>>          '{diff,merge}.{gui,}tool'. Adjust the rule so its output is an Asciidoc\n>> 2:  3e7aa9c425 = 2:  980145f747 mergetools: add description to all diff/merge tools\n>\n> Thanks! No need to roll out a v10, then?\n\nCorrect.  Thanks.\n"}]}