{"thread":{"id":"16703","subject":"Updates to the previous mergetool patches","startedAt":"2008-12-12T21:48:39Z","lastAt":"2008-12-12T22:11:41Z","messageCount":4,"participants":["Charles Bailey","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"97739","messageId":"1229118521-22923-1-git-send-email-charles@hashpling.org","threadId":"16703","inReplyTo":null,"subject":"Updates to the previous mergetool patches","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2008-12-12T21:48:39Z","receivedAt":"2008-12-12T21:48:39Z","isPatch":false,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"These two patches go on top of 682b451f and replace the 'DONTMERGE'\ncommit: 09b511016. If it would be easier if I cooked these in a\ndifferent way then let me know.\n\nI've implemented a replacement for the \"keep going\" option which is now\nto prompt after a failed merge to see if the user wants to continue\nmerging the remaining paths. This gets rid of a need for an option of\nconfiguration option.\n\nI haven't implemented any change to the logic as to whether to pause\nbefore invoking the merge tool based on which merge tool is being used.\n\nThe added tests for the return status of the merge are slightly less\nneat than I would have liked, but I think are necessary. I test after\ninvoking the merge tool to make sure that the \"roll-up\" status is\ncorrect, and before invoking the next tool to see if the user wants to\ncontinue despite the failure of the previous merge.\n\nOnly testing after the merge tool invocation can end up with a \"do you\nwant to continue\" before mergetool has determined that there are, in\nfact, no more files to merge. Only testing before the merge means that\nthe status of the last merge doesn't contribute to the script's return\nvalue. I don't know how many people rely on the return value of git\nmergetool, but why not keep it consistent?\n\nThe second patch makes optional the retention of temporary files on a\nfailed merge optional. It seperates out the behaviour change that I'd\nforgotten I'd left in the previous version of the \"-k\" patch.\n"},{"id":"97741","messageId":"1229118521-22923-2-git-send-email-charles@hashpling.org","threadId":"16703","inReplyTo":"1229118521-22923-1-git-send-email-charles@hashpling.org","subject":"[PATCH 1/2] mergetool: Add prompt to continue after failing to merge a file","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2008-12-12T21:48:40Z","receivedAt":"2008-12-12T21:48:40Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"This option stops git mergetool from aborting at the first failed merge.\nAfter a failed merge the user will be prompted to indicated whether he\nwishes to continue with attempting to merge subsequent paths or to\nabort.\n\nThis allows some additional use patterns. Merge conflicts can now be\npreviewed one at time and merges can also be skipped so that they can be\nperformed in a later pass.\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n git-mergetool.sh |   52 +++++++++++++++++++++++++++++++++++++++++++---------\n 1 files changed, 43 insertions(+), 9 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 507028f..5144971 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -70,16 +70,16 @@ resolve_symlink_merge () {\n \t\tgit checkout-index -f --stage=2 -- \"$MERGED\"\n \t\tgit add -- \"$MERGED\"\n \t\tcleanup_temp_files --save-backup\n-\t\treturn\n+\t\treturn 0\n \t\t;;\n \t    [rR]*)\n \t\tgit checkout-index -f --stage=3 -- \"$MERGED\"\n \t\tgit add -- \"$MERGED\"\n \t\tcleanup_temp_files --save-backup\n-\t\treturn\n+\t\treturn 0\n \t\t;;\n \t    [aA]*)\n-\t\texit 1\n+\t\treturn 1\n \t\t;;\n \t    esac\n \tdone\n@@ -97,15 +97,15 @@ resolve_deleted_merge () {\n \t    [mMcC]*)\n \t\tgit add -- \"$MERGED\"\n \t\tcleanup_temp_files --save-backup\n-\t\treturn\n+\t\treturn 0\n \t\t;;\n \t    [dD]*)\n \t\tgit rm -- \"$MERGED\" > /dev/null\n \t\tcleanup_temp_files\n-\t\treturn\n+\t\treturn 0\n \t\t;;\n \t    [aA]*)\n-\t\texit 1\n+\t\treturn 1\n \t\t;;\n \t    esac\n \tdone\n@@ -137,7 +137,7 @@ merge_file () {\n \telse\n \t    echo \"$MERGED: file does not need merging\"\n \tfi\n-\texit 1\n+\treturn 1\n     fi\n \n     ext=\"$$$(expr \"$MERGED\" : '.*\\(\\.[^/]*\\)$')\"\n@@ -269,7 +269,7 @@ merge_file () {\n     if test \"$status\" -ne 0; then\n \techo \"merge of $MERGED failed\" 1>&2\n \tmv -- \"$BACKUP\" \"$MERGED\"\n-\texit 1\n+\treturn 1\n     fi\n \n     if test \"$merge_keep_backup\" = \"true\"; then\n@@ -280,6 +280,7 @@ merge_file () {\n \n     git add -- \"$MERGED\"\n     cleanup_temp_files\n+    return 0\n }\n \n prompt=$(git config --bool mergetool.prompt || echo true)\n@@ -350,6 +351,22 @@ init_merge_tool_path() {\n \tfi\n }\n \n+prompt_after_failed_merge() {\n+    while true; do\n+\tprintf \"Continue merging other unresolved paths (y/n) ? \"\n+\tread ans\n+\tcase \"$ans\" in\n+\n+\t    [yY]*)\n+\t\treturn 0\n+\t\t;;\n+\n+\t    [nN]*)\n+\t\treturn 1\n+\t\t;;\n+\tesac\n+    done\n+}\n \n if test -z \"$merge_tool\"; then\n     merge_tool=`git config merge.tool`\n@@ -409,6 +426,8 @@ else\n     fi\n fi\n \n+last_status=0\n+rollup_status=0\n \n if test $# -eq 0 ; then\n     files=`git ls-files -u | sed -e 's/^[^\t]*\t//' | sort -u`\n@@ -422,14 +441,29 @@ if test $# -eq 0 ; then\n     sort -u |\n     while IFS= read i\n     do\n+\tif test $last_status -ne 0; then\n+\t    prompt_after_failed_merge < /dev/tty || exit 1\n+\tfi\n \tprintf \"\\n\"\n \tmerge_file \"$i\" < /dev/tty > /dev/tty\n+\tlast_status=$?\n+\tif test $last_status -ne 0; then\n+\t    rollup_status=1\n+\tfi\n     done\n else\n     while test $# -gt 0; do\n+\tif test $last_status -ne 0; then\n+\t    prompt_after_failed_merge || exit 1\n+\tfi\n \tprintf \"\\n\"\n \tmerge_file \"$1\"\n+\tlast_status=$?\n+\tif test $last_status -ne 0; then\n+\t    rollup_status=1\n+\tfi\n \tshift\n     done\n fi\n-exit 0\n+\n+exit $rollup_status\n-- \n1.6.1.rc1.342.g83b24d\n"},{"id":"97740","messageId":"1229118521-22923-3-git-send-email-charles@hashpling.org","threadId":"16703","inReplyTo":"1229118521-22923-2-git-send-email-charles@hashpling.org","subject":"[PATCH 2/2] mergetool: Don't keep temporary merge files unless told to","fromName":"Charles Bailey","fromEmail":"charles@hashpling.org","sentAt":"2008-12-12T21:48:41Z","receivedAt":"2008-12-12T21:48:41Z","isPatch":true,"sender":{"key":"charles@hashpling.org","avatar":"https://avatars.githubusercontent.com/u/1668475?v=4"},"body":"This changes git mergetool to remove the temporary files used to invoke\nthe merge tool even if it returns non-zero.\n\nThis also adds a configuration option (mergetool.keepTemporaries) to\nretain the previous behaviour if desired.\n\nSigned-off-by: Charles Bailey <charles@hashpling.org>\n---\n Documentation/config.txt |    7 +++++++\n git-mergetool.sh         |    6 ++++++\n 2 files changed, 13 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex bc5642d..3d5a8df 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -976,6 +976,13 @@ mergetool.keepBackup::\n \tis set to `false` then this file is not preserved.  Defaults to\n \t`true` (i.e. keep the backup files).\n \n+mergetool.keepTemporaries::\n+\tWhen invoking a custom merge tool, git uses a set of temporary\n+\tfiles to pass to the tool. If the tool returns an error and this\n+\tvariable is set to `true`, then these temporary files will be\n+\tpreserved, otherwise they will be removed after the tool has\n+\texited. Defaults to `false`.\n+\n mergetool.prompt::\n \tPrompt before each invocation of the merge resolution program.\n \ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 5144971..f04240d 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -269,6 +269,11 @@ merge_file () {\n     if test \"$status\" -ne 0; then\n \techo \"merge of $MERGED failed\" 1>&2\n \tmv -- \"$BACKUP\" \"$MERGED\"\n+\n+\tif test \"$merge_keep_temporaries\" = \"false\"; then\n+\t    cleanup_temp_files\n+\tfi\n+\n \treturn 1\n     fi\n \n@@ -415,6 +420,7 @@ else\n     init_merge_tool_path \"$merge_tool\"\n \n     merge_keep_backup=\"$(git config --bool merge.keepBackup || echo true)\"\n+    merge_keep_temporaries=\"$(git config --bool mergetool.keepTemporaries || echo false)\"\n \n     if test -z \"$merge_tool_cmd\" && ! type \"$merge_tool_path\" > /dev/null 2>&1; then\n         echo \"The merge tool $merge_tool is not available as '$merge_tool_path'\"\n-- \n1.6.1.rc1.342.g83b24d\n"},{"id":"97757","messageId":"ghuniq$s99$1@ger.gmane.org","threadId":"16703","inReplyTo":"1229118521-22923-3-git-send-email-charles@hashpling.org","subject":"Re: [PATCH 2/2] mergetool: Don't keep temporary merge files unless told to","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-12-12T22:11:41Z","receivedAt":"2008-12-12T22:11:41Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Charles Bailey wrote:\n\n> +mergetool.keepTemporaries::\n\nmergetool.keepTemporaryFiles ?\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}