@matheusbsbs / matheus-bagliano / commits / 1affea4f62
Fork 0

merge-recursive: handle file mode changes

File mode changes should be handled similarly to changes of content. That is, if the file mode changed in only one branch, keep the changed version, and if both branch changed to different mode, mark it as a conflict. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Mar 13, 2008 at 23:47 UTC 1affea4f629537fd48e3bd66de89a6f45d0fcd82
2 files changed +62 -2
merge-recursive.c
+13 -2
@@ -1028,9 +1028,20 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
1028 if (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1))
1029 result.merge = 1;
1030
1031 - result.mode = a->mode == o->mode ? b->mode: a->mode;
1031 + /*
1032 + * Merge modes
1033 + */
1034 + if (a->mode == b->mode || a->mode == o->mode)
1035 + result.mode = b->mode;
1036 + else {
1037 + result.mode = a->mode;
1038 + if (b->mode != o->mode) {
1039 + result.clean = 0;
1040 + result.merge = 1;
1041 + }
1042 + }
1043
1033 - if (sha_eq(a->sha1, o->sha1))
1044 + if (sha_eq(a->sha1, b->sha1) || sha_eq(a->sha1, o->sha1))
1045 hashcpy(result.sha, b->sha1);
1046 else if (sha_eq(b->sha1, o->sha1))
1047 hashcpy(result.sha, a->sha1);
t/t6031-merge-recursive.sh new
+49
@@ -0,0 +1,49 @@
1 +#!/bin/sh
2 +
3 +test_description='merge-recursive: handle file mode'
4 +. ./test-lib.sh
5 +
6 +test_expect_success 'mode change in one branch: keep changed version' '
7 + : >file1 &&
8 + git add file1 &&
9 + git commit -m initial &&
10 + git checkout -b a1 master &&
11 + : >dummy &&
12 + git add dummy &&
13 + git commit -m a &&
14 + git checkout -b b1 master &&
15 + chmod +x file1 &&
16 + git add file1 &&
17 + git commit -m b1 &&
18 + git checkout a1 &&
19 + git merge-recursive master -- a1 b1 &&
20 + test -x file1
21 +'
22 +
23 +test_expect_success 'mode change in both branches: expect conflict' '
24 + git reset --hard HEAD &&
25 + git checkout -b a2 master &&
26 + : >file2 &&
27 + H=$(git hash-object file2) &&
28 + chmod +x file2 &&
29 + git add file2 &&
30 + git commit -m a2 &&
31 + git checkout -b b2 master &&
32 + : >file2 &&
33 + git add file2 &&
34 + git commit -m b2 &&
35 + git checkout a2 &&
36 + (
37 + git merge-recursive master -- a2 b2
38 + test $? = 1
39 + ) &&
40 + git ls-files -u >actual &&
41 + (
42 + echo "100755 $H 2 file2"
43 + echo "100644 $H 3 file2"
44 + ) >expect &&
45 + diff -u actual expect &&
46 + test -x file2
47 +'
48 +
49 +test_done