git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mergetool: demonstrate directory / file conflict breakage
@ 2009-02-24 23:01 Charles Bailey
  2009-02-24 23:01 ` [PATCH] Test refactor Charles Bailey
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Bailey @ 2009-02-24 23:01 UTC (permalink / raw)
  To: git; +Cc: Caleb Cushing, Junio C Hamano, Charles Bailey

---

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(-)

diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh
index e768c3e..df57b83 100755
--- a/t/t7610-mergetool.sh
+++ b/t/t7610-mergetool.sh
@@ -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?
 #
-- 
1.6.2.rc1.258.g314b8b

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH] Test refactor
  2009-02-24 23:01 [PATCH] mergetool: demonstrate directory / file conflict breakage Charles Bailey
@ 2009-02-24 23:01 ` Charles Bailey
  2009-02-24 23:05   ` Charles Bailey
  0 siblings, 1 reply; 3+ messages in thread
From: Charles Bailey @ 2009-02-24 23:01 UTC (permalink / raw)
  To: git; +Cc: Caleb Cushing, Junio C Hamano, Charles Bailey

---
 git-mergetool.sh |  110 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 59 insertions(+), 51 deletions(-)

diff --git a/git-mergetool.sh b/git-mergetool.sh
index 87fa88a..9446b8e 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -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
 }
 
-- 
1.6.2.rc1.258.g314b8b

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Test refactor
  2009-02-24 23:01 ` [PATCH] Test refactor Charles Bailey
@ 2009-02-24 23:05   ` Charles Bailey
  0 siblings, 0 replies; 3+ messages in thread
From: Charles Bailey @ 2009-02-24 23:05 UTC (permalink / raw)
  To: git; +Cc: Caleb Cushing, Junio C Hamano

On Tue, Feb 24, 2009 at 11:01:55PM +0000, Charles Bailey wrote:
> ---
>  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.

-- 
Charles Bailey
http://ccgi.hashpling.plus.com/blog/

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-02-24 23:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-24 23:01 [PATCH] mergetool: demonstrate directory / file conflict breakage Charles Bailey
2009-02-24 23:01 ` [PATCH] Test refactor Charles Bailey
2009-02-24 23:05   ` Charles Bailey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).