view hgmerge @ 616:d45d1c90032e

Fix zombie files in merge # HG changeset patch # User maf46@burn.cl.cam.ac.uk # Node ID 57667c9b93a5a743e4629d15a0e6bd76699130c3 # Parent d2994b5298fb20f87dc1d4747635b280db3c0526 Fix zombie files in merge Keir Fraser observed the following: > I made a small test case that illustrates the bug in merging changesets > with 'hg remove's in them: > > 1. Create a repository A containing files foo & bar. > 2. Create clone called B. > 3. A removes file bar, and commits this removal. > 4. B edits file foo, and commits this edit. > > Now, if B: > # hg pull ../A; hg update -m; hg commit > Then bar remains deleted. > > If A: > # hg pull ../B; hg update -m; hg commit > Then bar is resurrected! > > It looks as though, when you merge across a branch, any deletions in > your own branch are forgotten. > ... > Fixing this is a must, as zombie files are a real pain. :-) Keir later patched our local copy of hg as shown below, which fixes the problem. I've also enclosed a test which captures the test Keir outlined... Files deleted on a branch should not automatically reappear in a merge Patch notes: 1. The first chunk does not change behaviour, but cleans up the code to more closely match check of 'force' in the second chunk. I think it makes the code clearer. 2. The second chunk fixes two bugs -- i. If we choose to keep a remotely-changed locally-deleted file, then we need to 'get' that file. If we choose to delete it then no action need be taken (it is already deleted in the working manifest). Without this fix, choosing to delete would get a Python traceback. ii. The test for whether the file was remotely-created is insufficient. It is only true if f is not in the common ancestor. Otherwise the file was deleted locally, and should remain deleted. (this is the most important fix!) Index: hg/tests/test-merge6 ===================================================================
author maf46@burn.cl.cam.ac.uk
date Mon, 04 Jul 2005 12:38:34 -0800
parents 4fc63e22b1fe
children cd0ad12d9e42 8f5637f0a0c0 0902ffece4b4
line wrap: on
line source

#!/bin/sh
#
# hgmerge - default merge helper for Mercurial
#
# This tries to find a way to do three-way merge on the current system.
# The result ought to end up in $1.

set -e # bail out quickly on failure

LOCAL=$1
BASE=$2
OTHER=$3

EDITOR="${EDITOR:-vi}"

# Back up our file
cp $LOCAL $LOCAL.orig

# Attempt to do a non-interactive merge
if which merge > /dev/null ; then
    if merge $LOCAL $BASE $OTHER 2> /dev/null; then
	# success!
	exit 0
    fi
    cp $LOCAL.orig $LOCAL
elif which diff3 > /dev/null ; then
    if diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL ; then
	# success
	exit 0
    fi
    cp $LOCAL.orig $LOCAL
fi

if [ -n "$DISPLAY" ]; then
    # try using kdiff3, which is fairly nice
    if which kdiff3 > /dev/null ; then
	if kdiff3 --auto $BASE $LOCAL $OTHER -o $LOCAL ; then
	    exit 0
	else
	    exit 1
	fi
    fi

    # try using tkdiff, which is a bit less sophisticated
    if which tkdiff > /dev/null ; then
	if tkdiff $LOCAL $OTHER -a $BASE -o $LOCAL ; then
	    exit 0
	else
	    exit 1
	fi
    fi
fi

# Attempt to do a merge with $EDITOR
if which merge > /dev/null ; then
    echo "conflicts detected in $LOCAL"
    merge $LOCAL $BASE $OTHER 2>/dev/null || $EDITOR $LOCAL
    exit 0
fi

if which diff3 > /dev/null ; then
    echo "conflicts detected in $LOCAL"
    diff3 -m $LOCAL.orig $BASE $OTHER > $LOCAL || $EDITOR $LOCAL
    exit 0
fi

# attempt to manually merge with diff and patch
if which diff > /dev/null ; then
    if which patch > /dev/null ; then
	T=`mktemp`
	diff -u $BASE $OTHER > $T
	if patch $LOCAL < $T ; then
	    exit 0
	else
	    $EDITOR $LOCAL $LOCAL.rej
	fi
	rm $T
	exit 1
    fi
fi

echo "hgmerge: unable to find merge, tkdiff, kdiff3, or diff+patch!"
exit 1