mergetool: demonstrate directory / file conflict breakage
PATCH 1/1 mergetool: demonstrate directory / file conflict breakage
---
This appears to demonstrate one of the corner cases that trips mergetool up. I also appear to have fixed it in my work-in-progress refactoring of mergetool, but I haven't yet completed it or tested it thoroughly enough so it's not ready for human consumption.
t/t7610-mergetool.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 47 insertions(+), 2 deletions(-)
t/t7610-mergetool.sh +47 -2
@@ -34,6 +34,8 @@ test_expect_success 'setup' ' git add file1 file2 subdir/file3 && git commit -m "master updates" && + git branch empty $(echo empty | git commit-tree $(printf "" | git mktree)) && + git config merge.tool mytool && git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && git config mergetool.mytool.trustExitCode true
@@ -67,13 +69,56 @@ test_expect_success 'mergetool crlf' ' ' test_expect_success 'mergetool in subdir' ' - git checkout -b test3 branch1 - cd subdir && ( + git checkout -b test3 branch1 && + ( cd subdir && test_must_fail git merge master >/dev/null 2>&1 && ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && test "$(cat file3)" = "master new sub" ) ' +# Choosing the 'remote' symlink should work +test_expect_success 'mergetool symlink change' ' + git clean -f && + git checkout -f -b symlink-test empty && + echo file >file1 && + echo file >linktofile1 && + git add file1 linktofile1 && + git commit -m base && + rm linktofile1 && + ln -s file1 linktofile1 && + git commit -a -m "change file to link" && + git checkout -b symlink-test-2 HEAD^ && + rm linktofile1 && + printf file1 >linktofile1 && + git commit -a -m "file change" && + test_must_fail git merge symlink-test >/dev/null 2>&1 && + ( yes "r" | git mergetool linktofile1 >/dev/null 2>&1 ) && + test -L linktofile1 && + git commit -m "symlink resolve" +' + +# Aborting a conflicted dir -> file merge shouldn't remove the offending +# parth altogether +test_expect_failure 'abort mergetool directory change' ' + git clean -f && + git checkout -f -b dir-test empty && + echo file >dir1 && + git add dir1 && + git commit -m base && + rm dir1 && + mkdir dir1 && + echo file >dir1/file && + git add dir1 + git commit -a -m "change file to dir" && + git checkout -b dir-test-2 HEAD^ && + echo not a dir >dir1 && + git commit -a -m "file change" && + test_must_fail git merge -s resolve dir-test && + test -e dir1 && + ( yes "a" | test_must_fail git mergetool dir1 >/dev/null 2>&1 ) && + test -e dir1 +' + # We can't merge files from parent directories when running mergetool # from a subdir. Is this a bug? #
Signature · 1 line
1.6.2.rc1.258.g314b8b
PATCH 1/1 Test refactor
--- git-mergetool.sh | 110 +++++++++++++++++++++++++++++------------------------- 1 files changed, 59 insertions(+), 51 deletions(-)
git-mergetool.sh +59 -51
@@ -99,7 +99,7 @@ resolve_deleted_merge () { return 0 ;; [dD]*) - git rm -- "$MERGED" > /dev/null + git rm -q -- "$MERGED" cleanup_temp_files return 0 ;;
@@ -134,55 +134,8 @@ checkout_staged_file () { fi } -merge_file () { - MERGED="$1" - - f=`git ls-files -u -- "$MERGED"` - if test -z "$f" ; then - if test ! -f "$MERGED" ; then - echo "$MERGED: file not found" - else - echo "$MERGED: file does not need merging" - fi - return 1 - fi - - ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')" - BACKUP="./$MERGED.BACKUP.$ext" - LOCAL="./$MERGED.LOCAL.$ext" - REMOTE="./$MERGED.REMOTE.$ext" - BASE="./$MERGED.BASE.$ext" - - mv -- "$MERGED" "$BACKUP" - cp -- "$BACKUP" "$MERGED" - - base_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}'` - local_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}'` - remote_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}'` - - base_present && checkout_staged_file 1 "$MERGED" "$BASE" - local_present && checkout_staged_file 2 "$MERGED" "$LOCAL" - remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE" +resolve_normal_merge () { - if test -z "$local_mode" -o -z "$remote_mode"; then - echo "Deleted merge conflict for '$MERGED':" - describe_file "$local_mode" "local" "$LOCAL" - describe_file "$remote_mode" "remote" "$REMOTE" - resolve_deleted_merge - return - fi - - if is_symlink "$local_mode" || is_symlink "$remote_mode"; then - echo "Symbolic link merge conflict for '$MERGED':" - describe_file "$local_mode" "local" "$LOCAL" - describe_file "$remote_mode" "remote" "$REMOTE" - resolve_symlink_merge - return - fi - - echo "Normal merge conflict for '$MERGED':" - describe_file "$local_mode" "local" "$LOCAL" - describe_file "$remote_mode" "remote" "$REMOTE" if "$prompt" = true; then printf "Hit return to start merge resolution tool (%s): " "$merge_tool" read ans
@@ -278,7 +231,62 @@ merge_file () { fi ;; esac - if test "$status" -ne 0; then + + if test $status -eq 0; then + git add -- "$MERGED" + fi + + return $status +} + +merge_file () { + MERGED="$1" + + f=`git ls-files -u -- "$MERGED"` + if test -z "$f" ; then + if test ! -f "$MERGED" ; then + echo "$MERGED: file not found" + else + echo "$MERGED: file does not need merging" + fi + return 1 + fi + + ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')" + BACKUP="./$MERGED.BACKUP.$ext" + LOCAL="./$MERGED.LOCAL.$ext" + REMOTE="./$MERGED.REMOTE.$ext" + BASE="./$MERGED.BASE.$ext" + + mv -- "$MERGED" "$BACKUP" + cp -- "$BACKUP" "$MERGED" + + base_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}'` + local_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}'` + remote_mode=`git ls-files -u -- "$MERGED" | awk '{if ($3==3) print $1;}'` + + base_present && checkout_staged_file 1 "$MERGED" "$BASE" + local_present && checkout_staged_file 2 "$MERGED" "$LOCAL" + remote_present && checkout_staged_file 3 "$MERGED" "$REMOTE" + + if test -z "$local_mode" -o -z "$remote_mode"; then + echo "Deleted merge conflict for '$MERGED':" + describe_file "$local_mode" "local" "$LOCAL" + describe_file "$remote_mode" "remote" "$REMOTE" + resolve_deleted_merge + elif is_symlink "$local_mode" || is_symlink "$remote_mode"; then + echo "Symbolic link merge conflict for '$MERGED':" + describe_file "$local_mode" "local" "$LOCAL" + describe_file "$remote_mode" "remote" "$REMOTE" + resolve_symlink_merge + else + echo "Normal merge conflict for '$MERGED':" + describe_file "$local_mode" "local" "$LOCAL" + describe_file "$remote_mode" "remote" "$REMOTE" + resolve_normal_merge + fi + + if test $? -ne 0; then echo "merge of $MERGED failed" 1>&2 mv -- "$BACKUP" "$MERGED"
@@ -295,8 +303,8 @@ merge_file () { rm -- "$BACKUP" fi - git add -- "$MERGED" cleanup_temp_files + return 0 }
Signature · 1 line
1.6.2.rc1.258.g314b8b
Re: [PATCH] Test refactor
Quoted 3 lines · Charles Bailey
--- git-mergetool.sh | 110 +++++++++++++++++++++++++++++------------------------- 1 files changed, 59 insertions(+), 51 deletions(-)
Lack of sign-off: deliberate.
Failure to say 'RFC' and a have a meaningful commit subject: human error.
Sorry about that.
Signature · 2 lines
Charles Bailey http://ccgi.hashpling.plus.com/blog/