add cherrypick test for symlink conflict cases This test accepts the current behaviour, even though the current behaviour isn't ideal in some cases.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
diff --git a/regress/cmdline/cherrypick.sh b/regress/cmdline/cherrypick.sh
index f5bdf9b..d6bd1a3 100755
--- a/regress/cmdline/cherrypick.sh
+++ b/regress/cmdline/cherrypick.sh
@@ -458,6 +458,205 @@ function test_cherrypick_modified_symlinks {
test_done "$testroot" "0"
}
+function test_cherrypick_symlink_conflicts {
+ local testroot=`test_init cherrypick_symlink_conflicts`
+
+ (cd $testroot/repo && ln -s alpha alpha.link)
+ (cd $testroot/repo && ln -s epsilon epsilon.link)
+ (cd $testroot/repo && ln -s /etc/passwd passwd.link)
+ (cd $testroot/repo && ln -s ../beta epsilon/beta.link)
+ (cd $testroot/repo && ln -s nonexistent nonexistent.link)
+ (cd $testroot/repo && ln -sf epsilon/zeta zeta.link)
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "add symlinks"
+ local commit_id1=`git_show_head $testroot/repo`
+
+ (cd $testroot/repo && ln -sf beta alpha.link)
+ (cd $testroot/repo && ln -sfh gamma epsilon.link)
+ (cd $testroot/repo && ln -sf ../gamma/delta epsilon/beta.link)
+ echo 'this is regular file foo' > $testroot/repo/dotgotfoo.link
+ (cd $testroot/repo && ln -sf .got/bar dotgotbar.link)
+ (cd $testroot/repo && git rm -q nonexistent.link)
+ (cd $testroot/repo && ln -sf gamma/delta zeta.link)
+ (cd $testroot/repo && ln -sf alpha new.link)
+ (cd $testroot/repo && git add .)
+ git_commit $testroot/repo -m "change symlinks"
+ local commit_id2=`git_show_head $testroot/repo`
+
+ got branch -r $testroot/repo -c $commit_id1 foo
+ got checkout -b foo $testroot/repo $testroot/wt > /dev/null
+
+ # modified symlink to file A vs modified symlink to file B
+ (cd $testroot/wt && ln -sf gamma/delta alpha.link)
+ # modified symlink to dir A vs modified symlink to file B
+ (cd $testroot/wt && ln -sfh beta epsilon.link)
+ # modeified symlink to file A vs modified symlink to dir B
+ (cd $testroot/wt && ln -sfh ../gamma epsilon/beta.link)
+ # added regular file A vs added bad symlink to file A
+ (cd $testroot/wt && ln -sf .got/bar dotgotfoo.link)
+ # added bad symlink to file A vs added regular file A
+ echo 'this is regular file bar' > $testroot/wt/dotgotbar.link
+ # removed symlink to non-existent file A vs modified symlink
+ # to nonexistent file B
+ (cd $testroot/wt && ln -sf nonexistent2 nonexistent.link)
+ # modified symlink to file A vs removed symlink to file A
+ (cd $testroot/wt && got rm zeta.link > /dev/null)
+ # added symlink to file A vs added symlink to file B
+ (cd $testroot/wt && ln -sf beta new.link)
+ (cd $testroot/wt && got add new.link > /dev/null)
+ (cd $testroot/wt && got commit -m "change on symlinks on branch foo" \
+ > /dev/null)
+
+ (cd $testroot/wt && got update >/dev/null)
+ (cd $testroot/wt && got cherrypick $commit_id2 > $testroot/stdout)
+
+ echo -n > $testroot/stdout.expected
+ echo "~ alpha.link" >> $testroot/stdout.expected
+ echo "~ epsilon/beta.link" >> $testroot/stdout.expected
+ echo "U dotgotbar.link" >> $testroot/stdout.expected
+ echo "~ epsilon.link" >> $testroot/stdout.expected
+ echo "U dotgotfoo.link" >> $testroot/stdout.expected
+ echo "D nonexistent.link" >> $testroot/stdout.expected
+ echo "! zeta.link" >> $testroot/stdout.expected
+ echo "G new.link" >> $testroot/stdout.expected
+ echo "Merged commit $commit_id2" >> $testroot/stdout.expected
+ echo "File paths obstructed by a non-regular file: 3" \
+ >> $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if ! [ -h $testroot/wt/alpha.link ]; then
+ echo "alpha.link is not a symlink"
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ readlink $testroot/wt/alpha.link > $testroot/stdout
+ echo "gamma/delta" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if ! [ -h $testroot/wt/epsilon.link ]; then
+ echo "epsilon.link is not a symlink"
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ readlink $testroot/wt/epsilon.link > $testroot/stdout
+ echo "beta" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if [ -h $testroot/wt/passwd.link ]; then
+ echo -n "passwd.link symlink points outside of work tree: " >&2
+ readlink $testroot/wt/passwd.link >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo -n "/etc/passwd" > $testroot/content.expected
+ cp $testroot/wt/passwd.link $testroot/content
+
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ readlink $testroot/wt/epsilon/beta.link > $testroot/stdout
+ echo "../gamma" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if [ -h $testroot/wt/nonexistent.link ]; then
+ echo -n "nonexistent.link still exists on disk: " >&2
+ readlink $testroot/wt/nonexistent.link >&2
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ if [ -h $testroot/wt/dotgotfoo.link ]; then
+ echo "dotgotfoo.link is a symlink"
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ echo "this is regular file foo" > $testroot/content.expected
+ cp $testroot/wt/dotgotfoo.link $testroot/content
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if [ -h $testroot/wt/dotgotbar.link ]; then
+ echo "dotgotbar.link is a symlink"
+ test_done "$testroot" "1"
+ return 1
+ fi
+ echo -n ".got/bar" > $testroot/content.expected
+ cp $testroot/wt/dotgotbar.link $testroot/content
+ cmp -s $testroot/content.expected $testroot/content
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/content.expected $testroot/content
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ if ! [ -h $testroot/wt/new.link ]; then
+ echo "new.link is not a symlink"
+ test_done "$testroot" "1"
+ return 1
+ fi
+
+ readlink $testroot/wt/new.link > $testroot/stdout
+ echo "alpha" > $testroot/stdout.expected
+ cmp -s $testroot/stdout.expected $testroot/stdout
+ ret="$?"
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ echo "A dotgotfoo.link" > $testroot/stdout.expected
+ echo "M new.link" >> $testroot/stdout.expected
+ echo "D nonexistent.link" >> $testroot/stdout.expected
+ (cd $testroot/wt && got status > $testroot/stdout)
+ if [ "$ret" != "0" ]; then
+ diff -u $testroot/stdout.expected $testroot/stdout
+ test_done "$testroot" "$ret"
+ return 1
+ fi
+
+ test_done "$testroot" "0"
+}
+
run_test test_cherrypick_basic
run_test test_cherrypick_root_commit
run_test test_cherrypick_into_work_tree_with_conflicts
@@ -465,3 +664,4 @@ run_test test_cherrypick_modified_submodule
run_test test_cherrypick_added_submodule
run_test test_cherrypick_conflict_wt_file_vs_repo_submodule
run_test test_cherrypick_modified_symlinks
+run_test test_cherrypick_symlink_conflicts