merge: loosen overcautious "working file will be lost" check.
The three-way merge complained unconditionally when a path that does not exist in the index is involved in a merge when it existed in the working tree. If we are merging an old version that had that path tracked, but the path is not tracked anymore, and if we are merging that old version in, the result will be that the path is not tracked. In that case we should not complain. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Oct 8, 2006 at 22:48 UTC
ed93b449c5e13a70beb7f0ae02fb6da95e42a805
3 files changed
+69
-4
git-merge-one-file.sh
+15
-1
@@ -23,6 +23,12 @@ case "${1:-.}${2:-.}${3:-.}" in
23
"$1.." | "$1.$1" | "$1$1.")
24
if [ "$2" ]; then
25
echo "Removing $4"
26
+ else
27
+ # read-tree checked that index matches HEAD already,
28
+ # so we know we do not have this path tracked.
29
+ # there may be an unrelated working tree file here,
30
+ # which we should just leave unmolested.
31
+ exit 0
32
fi
33
if test -f "$4"; then
34
rm -f -- "$4" &&
@@ -34,8 +40,16 @@ case "${1:-.}${2:-.}${3:-.}" in
40
#
41
# Added in one.
42
#
37
-".$2." | "..$3" )
43
+".$2.")
44
+ # the other side did not add and we added so there is nothing
45
+ # to be done.
46
+ ;;
47
+"..$3")
48
echo "Adding $4"
49
+ test -f "$4" || {
50
+ echo "ERROR: untracked $4 is overwritten by the merge."
51
+ exit 1
52
+ }
53
git-update-index --add --cacheinfo "$6$7" "$2$3" "$4" &&
54
exec git-checkout-index -u -f -- "$4"
55
;;
t/t1004-read-tree-m-u-wf.sh
new
+53
@@ -0,0 +1,53 @@
1
+#!/bin/sh
2
+
3
+test_description='read-tree -m -u checks working tree files'
4
+
5
+. ./test-lib.sh
6
+
7
+# two-tree test
8
+
9
+test_expect_success 'two-way setup' '
10
+
11
+ echo >file1 file one &&
12
+ echo >file2 file two &&
13
+ git update-index --add file1 file2 &&
14
+ git commit -m initial &&
15
+
16
+ git branch side &&
17
+ git tag -f branch-point &&
18
+
19
+ echo file2 is not tracked on the master anymore &&
20
+ rm -f file2 &&
21
+ git update-index --remove file2 &&
22
+ git commit -a -m "master removes file2"
23
+'
24
+
25
+test_expect_success 'two-way not clobbering' '
26
+
27
+ echo >file2 master creates untracked file2 &&
28
+ if err=`git read-tree -m -u master side 2>&1`
29
+ then
30
+ echo should have complained
31
+ false
32
+ else
33
+ echo "happy to see $err"
34
+ fi
35
+'
36
+
37
+# three-tree test
38
+
39
+test_expect_success 'three-way not complaining' '
40
+
41
+ rm -f file2 &&
42
+ git checkout side &&
43
+ echo >file3 file three &&
44
+ git update-index --add file3 &&
45
+ git commit -a -m "side adds file3" &&
46
+
47
+ git checkout master &&
48
+ echo >file2 file two is untracked on the master side &&
49
+
50
+ git-read-tree -m -u branch-point master side
51
+'
52
+
53
+test_done
unpack-trees.c
+1
-3
@@ -642,7 +642,7 @@ int threeway_merge(struct cache_entry **stages,
642
(remote_deleted && head && head_match)) {
643
if (index)
644
return deleted_entry(index, index, o);
645
- else if (path)
645
+ else if (path && !head_deleted)
646
verify_absent(path, "removed", o);
647
return 0;
648
}
@@ -661,8 +661,6 @@ int threeway_merge(struct cache_entry **stages,
661
if (index) {
662
verify_uptodate(index, o);
663
}
664
- else if (path)
665
- verify_absent(path, "overwritten", o);
664
665
o->nontrivial_merge = 1;
666