| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Test --follow follows renames across merges' |
| 4 | |
| 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master |
| 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
| 8 | . ./test-lib.sh |
| 9 | |
| 10 | test_expect_success 'setup subtree-merged repository' ' |
| 11 | git init inner && |
| 12 | echo inner >inner/inner.txt && |
| 13 | git -C inner add inner.txt && |
| 14 | git -C inner commit -m "inner init" && |
| 15 | |
| 16 | git init outer && |
| 17 | echo outer >outer/outer.txt && |
| 18 | git -C outer add outer.txt && |
| 19 | git -C outer commit -m "outer init" && |
| 20 | |
| 21 | git -C outer fetch ../inner master && |
| 22 | git -C outer merge -s ours --no-commit --allow-unrelated-histories \ |
| 23 | FETCH_HEAD && |
| 24 | git -C outer read-tree --prefix=inner/ -u FETCH_HEAD && |
| 25 | git -C outer commit -m "Merge inner repo into inner/ subdirectory" |
| 26 | ' |
| 27 | |
| 28 | test_expect_success '--follow finds the pre-merge commit through a subtree merge' ' |
| 29 | git -C outer log --follow --pretty=tformat:%s inner/inner.txt >actual && |
| 30 | echo "inner init" >expect && |
| 31 | test_cmp expect actual |
| 32 | ' |
| 33 | |
| 34 | test_expect_success 'setup merge of two branches that both renamed a file to README' ' |
| 35 | git init foo && |
| 36 | mkdir foo/foo && |
| 37 | echo "foo readme" >foo/foo/README && |
| 38 | git -C foo add foo/README && |
| 39 | git -C foo commit -m "add foo README" && |
| 40 | |
| 41 | git -C foo mv foo/README README && |
| 42 | git -C foo commit -m "promote foo README to toplevel" && |
| 43 | |
| 44 | echo "foo c" >foo/foo.c && |
| 45 | git -C foo add foo.c && |
| 46 | git -C foo commit -m "add foo C impl" && |
| 47 | |
| 48 | git init bar && |
| 49 | mkdir bar/bar && |
| 50 | echo "bar readme" >bar/bar/README && |
| 51 | git -C bar add bar/README && |
| 52 | git -C bar commit -m "add bar README" && |
| 53 | |
| 54 | git -C bar mv bar/README README && |
| 55 | git -C bar commit -m "promote bar README to toplevel" && |
| 56 | |
| 57 | echo "bar c" >bar/bar.c && |
| 58 | git -C bar add bar.c && |
| 59 | git -C bar commit -m "add bar C impl" && |
| 60 | |
| 61 | git -C foo fetch ../bar master && |
| 62 | git -C foo merge -s ours --no-commit --allow-unrelated-histories \ |
| 63 | FETCH_HEAD && |
| 64 | git -C foo checkout FETCH_HEAD -- bar.c && |
| 65 | git -C foo commit -m "merge bar into foo" |
| 66 | ' |
| 67 | |
| 68 | test_expect_success '--follow follows renames across both sides of a merge' ' |
| 69 | git -C foo log --follow --pretty=tformat:%s README >actual && |
| 70 | sort actual >actual.sorted && |
| 71 | cat >expect <<-\EOF && |
| 72 | add bar README |
| 73 | add foo README |
| 74 | promote bar README to toplevel |
| 75 | promote foo README to toplevel |
| 76 | EOF |
| 77 | test_cmp expect actual.sorted |
| 78 | ' |
| 79 | |
| 80 | test_expect_success 'setup diamond with renames on both sides of a fork' ' |
| 81 | git init diamond && |
| 82 | test_lines="line 1\nline 2\nline 3\nline 4\nline 5\n" && |
| 83 | |
| 84 | printf "$test_lines" >diamond/path0 && |
| 85 | git -C diamond add path0 && |
| 86 | git -C diamond commit -m "A: add path0" && |
| 87 | |
| 88 | git -C diamond checkout -b upper && |
| 89 | printf "line 1\nline 2\nline 3 modified by B\nline 4\nline 5\n" \ |
| 90 | >diamond/path0 && |
| 91 | git -C diamond commit -am "B: modify path0 on upper" && |
| 92 | git -C diamond mv path0 path1 && |
| 93 | git -C diamond commit -m "X: rename path0 to path1" && |
| 94 | |
| 95 | git -C diamond checkout -b lower master && |
| 96 | printf "line 1\nline 2\nline 3 modified by C\nline 4\nline 5\n" \ |
| 97 | >diamond/path0 && |
| 98 | git -C diamond commit -am "C: modify path0 on lower" && |
| 99 | git -C diamond mv path0 path2 && |
| 100 | git -C diamond commit -m "Y: rename path0 to path2" && |
| 101 | |
| 102 | git -C diamond checkout upper && |
| 103 | git -C diamond merge -s ours --no-commit lower && |
| 104 | git -C diamond rm path1 && |
| 105 | printf "line 1\nline 2\nline 3 merged\nline 4\nline 5\n" \ |
| 106 | >diamond/path && |
| 107 | git -C diamond add path && |
| 108 | git -C diamond commit -m "M: merge with rename to path" && |
| 109 | |
| 110 | printf "line 1\nline 2\nline 3 merged again\nline 4\nline 5\n" \ |
| 111 | >diamond/path && |
| 112 | git -C diamond commit -am "Z: modify path" |
| 113 | ' |
| 114 | |
| 115 | test_expect_success '--follow follows renames through a fork in a single history' ' |
| 116 | git -C diamond log --follow --pretty=tformat:%s path >actual && |
| 117 | sort actual >actual.sorted && |
| 118 | cat >expect <<-\EOF && |
| 119 | A: add path0 |
| 120 | B: modify path0 on upper |
| 121 | C: modify path0 on lower |
| 122 | X: rename path0 to path1 |
| 123 | Y: rename path0 to path2 |
| 124 | Z: modify path |
| 125 | EOF |
| 126 | test_cmp expect actual.sorted |
| 127 | ' |
| 128 | |
| 129 | test_done |