{"thread":{"id":"41656","subject":"[PATCH v3 1/2] mergetool: support delete/delete conflicts","startedAt":"2016-03-10T07:13:58Z","lastAt":"2016-03-10T22:08:48Z","messageCount":3,"participants":["David Aguilar","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":2},"messages":[{"id":"280529","messageId":"1457594039-22629-1-git-send-email-davvid@gmail.com","threadId":"41656","inReplyTo":null,"subject":"[PATCH v3 1/2] mergetool: support delete/delete conflicts","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2016-03-10T07:13:58Z","receivedAt":"2016-03-10T07:13:58Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"If two branches each move a file into different directories then\nmergetool will fail because it assumes that the file being merged, and\nits parent directory, are present in the worktree.\n\nCreate the merge file's parent directory to allow using the\ndeleted base version of the file for merge resolution when\nencountering a delete/delete conflict.\n\nThe end result is that a delete/delete conflict is presented for the\nuser to resolve.\n\nReported-by: Joe Einertson <joe@kidblog.org>\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\nRebased to include tests and test fixes.\n\nThe series was also reordered so that this patch comes first\nsince it made the tests easier to incrementally update.\n\n git-mergetool.sh     | 14 +++++++++++---\n t/t7610-mergetool.sh | 39 +++++++++++++++++++++++++++++++++++++++\n 2 files changed, 50 insertions(+), 3 deletions(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex 9f77e3a..b06ae78 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -282,8 +282,14 @@ merge_file () {\n \t\treturn\n \tfi\n \n-\tmv -- \"$MERGED\" \"$BACKUP\"\n-\tcp -- \"$BACKUP\" \"$MERGED\"\n+\tif test -f \"$MERGED\"\n+\tthen\n+\t\tmv -- \"$MERGED\" \"$BACKUP\"\n+\t\tcp -- \"$BACKUP\" \"$MERGED\"\n+\tfi\n+\t# Create a parent directory to handle delete/delete conflicts\n+\t# where the base's directory no longer exists.\n+\tmkdir -p \"$(dirname \"$MERGED\")\"\n \n \tcheckout_staged_file 1 \"$MERGED\" \"$BASE\"\n \tcheckout_staged_file 2 \"$MERGED\" \"$LOCAL\"\n@@ -295,7 +301,9 @@ merge_file () {\n \t\tdescribe_file \"$local_mode\" \"local\" \"$LOCAL\"\n \t\tdescribe_file \"$remote_mode\" \"remote\" \"$REMOTE\"\n \t\tresolve_deleted_merge\n-\t\treturn\n+\t\tstatus=$?\n+\t\trmdir -p \"$(dirname \"$MERGED\")\" 2>/dev/null\n+\t\treturn $status\n \tfi\n \n \tif is_symlink \"$local_mode\" || is_symlink \"$remote_mode\"\ndiff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh\nindex 6f12b23..39469d9 100755\n--- a/t/t7610-mergetool.sh\n+++ b/t/t7610-mergetool.sh\n@@ -243,6 +243,45 @@ test_expect_success 'mergetool takes partial path' '\n \tgit reset --hard\n '\n \n+test_expect_success 'mergetool delete/delete conflict' '\n+\tgit checkout -b delete-base branch1 &&\n+\tmkdir -p a/a &&\n+\t(echo one; echo two; echo 3; echo 4) >a/a/file.txt &&\n+\tgit add a/a/file.txt &&\n+\tgit commit -m\"base file\" &&\n+\tgit checkout -b move-to-b delete-base &&\n+\tmkdir -p b/b &&\n+\tgit mv a/a/file.txt b/b/file.txt &&\n+\t(echo one; echo two; echo 4) >b/b/file.txt &&\n+\tgit commit -a -m\"move to b\" &&\n+\tgit checkout -b move-to-c delete-base &&\n+\tmkdir -p c/c &&\n+\tgit mv a/a/file.txt c/c/file.txt &&\n+\t(echo one; echo two; echo 3) >c/c/file.txt &&\n+\tgit commit -a -m\"move to c\" &&\n+\ttest_must_fail git merge move-to-b &&\n+\techo d | git mergetool a/a/file.txt &&\n+\t! test -f a/a/file.txt &&\n+\tgit reset --hard HEAD &&\n+\ttest_must_fail git merge move-to-b &&\n+\techo m | git mergetool a/a/file.txt &&\n+\ttest -f b/b/file.txt &&\n+\tgit reset --hard HEAD &&\n+\ttest_must_fail git merge move-to-b &&\n+\t! echo a | git mergetool a/a/file.txt &&\n+\t! test -f a/a/file.txt &&\n+\tgit reset --hard HEAD\n+'\n+\n+test_expect_success 'mergetool produces no errors when keepBackup is used' '\n+\ttest_config mergetool.keepBackup true &&\n+\ttest_must_fail git merge move-to-b &&\n+\t: >expect &&\n+\techo d | git mergetool a/a/file.txt 2>actual &&\n+\ttest_cmp expect actual &&\n+\tgit reset --hard HEAD\n+'\n+\n test_expect_success 'deleted vs modified submodule' '\n \tgit checkout -b test6 branch1 &&\n \tgit submodule update -N &&\n-- \n2.8.0.rc1.2.gb8cabf0\n"},{"id":"280530","messageId":"1457594039-22629-2-git-send-email-davvid@gmail.com","threadId":"41656","inReplyTo":"1457594039-22629-1-git-send-email-davvid@gmail.com","subject":"[PATCH v3 2/2] mergetool: honor tempfile configuration when resolving delete conflicts","fromName":"David Aguilar","fromEmail":"davvid@gmail.com","sentAt":"2016-03-10T07:13:59Z","receivedAt":"2016-03-10T07:13:59Z","isPatch":true,"sender":{"key":"davvid@gmail.com","avatar":"https://avatars.githubusercontent.com/u/13196?v=4"},"body":"Teach resolve_deleted_merge() to honor the mergetool.keepBackup and\nmergetool.keepTemporaries configuration knobs.\n\nThis ensures that the worktree is kept pristine when resolving deletion\nconflicts with the variables both set to false.\n\nSigned-off-by: David Aguilar <davvid@gmail.com>\n---\nRebased to include tests and test fixes.\n\n git-mergetool.sh     | 11 ++++++++++-\n t/t7610-mergetool.sh | 25 +++++++++++++++++++++++++\n 2 files changed, 35 insertions(+), 1 deletion(-)\n\ndiff --git a/git-mergetool.sh b/git-mergetool.sh\nindex b06ae78..f67bab5 100755\n--- a/git-mergetool.sh\n+++ b/git-mergetool.sh\n@@ -126,7 +126,12 @@ resolve_deleted_merge () {\n \t\tcase \"$ans\" in\n \t\t[mMcC]*)\n \t\t\tgit add -- \"$MERGED\"\n-\t\t\tcleanup_temp_files --save-backup\n+\t\t\tif test \"$merge_keep_backup\" = \"true\"\n+\t\t\tthen\n+\t\t\t\tcleanup_temp_files --save-backup\n+\t\t\telse\n+\t\t\t\tcleanup_temp_files\n+\t\t\tfi\n \t\t\treturn 0\n \t\t\t;;\n \t\t[dD]*)\n@@ -135,6 +140,10 @@ resolve_deleted_merge () {\n \t\t\treturn 0\n \t\t\t;;\n \t\t[aA]*)\n+\t\t\tif test \"$merge_keep_temporaries\" = \"false\"\n+\t\t\tthen\n+\t\t\t\tcleanup_temp_files\n+\t\t\tfi\n \t\t\treturn 1\n \t\t\t;;\n \t\tesac\ndiff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh\nindex 39469d9..db723e8 100755\n--- a/t/t7610-mergetool.sh\n+++ b/t/t7610-mergetool.sh\n@@ -279,6 +279,31 @@ test_expect_success 'mergetool produces no errors when keepBackup is used' '\n \t: >expect &&\n \techo d | git mergetool a/a/file.txt 2>actual &&\n \ttest_cmp expect actual &&\n+\t! test -d a &&\n+\tgit reset --hard HEAD\n+'\n+\n+test_expect_success 'mergetool honors tempfile config for deleted files' '\n+\ttest_config mergetool.keepTemporaries false &&\n+\ttest_must_fail git merge move-to-b &&\n+\techo d | git mergetool a/a/file.txt &&\n+\t! test -d a &&\n+\tgit reset --hard HEAD\n+'\n+\n+test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '\n+\ttest_config mergetool.keepTemporaries true &&\n+\ttest_must_fail git merge move-to-b &&\n+\t! (echo a; echo n) | git mergetool a/a/file.txt &&\n+\ttest -d a/a &&\n+\tcat  >expect <<-\\EOF &&\n+\tfile_BASE_.txt\n+\tfile_LOCAL_.txt\n+\tfile_REMOTE_.txt\n+\tEOF\n+\tls -1 a/a | sed -e \"s/[0-9]*//g\" >actual &&\n+\ttest_cmp expect actual &&\n+\tgit clean -fdx &&\n \tgit reset --hard HEAD\n '\n \n-- \n2.8.0.rc1.2.gb8cabf0\n"},{"id":"280584","messageId":"xmqqpov2c7f3.fsf@gitster.mtv.corp.google.com","threadId":"41656","inReplyTo":"1457594039-22629-2-git-send-email-davvid@gmail.com","subject":"Re: [PATCH v3 2/2] mergetool: honor tempfile configuration when resolving delete conflicts","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-03-10T22:08:48Z","receivedAt":"2016-03-10T22:08:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"David Aguilar <davvid@gmail.com> writes:\n\n> Teach resolve_deleted_merge() to honor the mergetool.keepBackup and\n> mergetool.keepTemporaries configuration knobs.\n>\n> This ensures that the worktree is kept pristine when resolving deletion\n> conflicts with the variables both set to false.\n>\n> Signed-off-by: David Aguilar <davvid@gmail.com>\n> ---\n> Rebased to include tests and test fixes.\n\nThanks.  Will queue after applying a single fix-up again.\n\n>\n>  git-mergetool.sh     | 11 ++++++++++-\n>  t/t7610-mergetool.sh | 25 +++++++++++++++++++++++++\n>  2 files changed, 35 insertions(+), 1 deletion(-)\n>\n> diff --git a/git-mergetool.sh b/git-mergetool.sh\n> index b06ae78..f67bab5 100755\n> --- a/git-mergetool.sh\n> +++ b/git-mergetool.sh\n> @@ -126,7 +126,12 @@ resolve_deleted_merge () {\n>  \t\tcase \"$ans\" in\n>  \t\t[mMcC]*)\n>  \t\t\tgit add -- \"$MERGED\"\n> -\t\t\tcleanup_temp_files --save-backup\n> +\t\t\tif test \"$merge_keep_backup\" = \"true\"\n> +\t\t\tthen\n> +\t\t\t\tcleanup_temp_files --save-backup\n> +\t\t\telse\n> +\t\t\t\tcleanup_temp_files\n> +\t\t\tfi\n>  \t\t\treturn 0\n>  \t\t\t;;\n>  \t\t[dD]*)\n> @@ -135,6 +140,10 @@ resolve_deleted_merge () {\n>  \t\t\treturn 0\n>  \t\t\t;;\n>  \t\t[aA]*)\n> +\t\t\tif test \"$merge_keep_temporaries\" = \"false\"\n> +\t\t\tthen\n> +\t\t\t\tcleanup_temp_files\n> +\t\t\tfi\n>  \t\t\treturn 1\n>  \t\t\t;;\n>  \t\tesac\n> diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh\n> index 39469d9..db723e8 100755\n> --- a/t/t7610-mergetool.sh\n> +++ b/t/t7610-mergetool.sh\n> @@ -279,6 +279,31 @@ test_expect_success 'mergetool produces no errors when keepBackup is used' '\n>  \t: >expect &&\n>  \techo d | git mergetool a/a/file.txt 2>actual &&\n>  \ttest_cmp expect actual &&\n> +\t! test -d a &&\n> +\tgit reset --hard HEAD\n> +'\n> +\n> +test_expect_success 'mergetool honors tempfile config for deleted files' '\n> +\ttest_config mergetool.keepTemporaries false &&\n> +\ttest_must_fail git merge move-to-b &&\n> +\techo d | git mergetool a/a/file.txt &&\n> +\t! test -d a &&\n> +\tgit reset --hard HEAD\n> +'\n> +\n> +test_expect_success 'mergetool keeps tempfiles when aborting delete/delete' '\n> +\ttest_config mergetool.keepTemporaries true &&\n> +\ttest_must_fail git merge move-to-b &&\n> +\t! (echo a; echo n) | git mergetool a/a/file.txt &&\n> +\ttest -d a/a &&\n> +\tcat  >expect <<-\\EOF &&\n> +\tfile_BASE_.txt\n> +\tfile_LOCAL_.txt\n> +\tfile_REMOTE_.txt\n> +\tEOF\n> +\tls -1 a/a | sed -e \"s/[0-9]*//g\" >actual &&\n> +\ttest_cmp expect actual &&\n> +\tgit clean -fdx &&\n>  \tgit reset --hard HEAD\n>  '\n"}]}