| 1 | #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash |
| 2 | |
| 3 | . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh" |
| 4 | |
| 5 | setup_successful_reposcip-shell shell shell-project 0.0.0 setup_successful_repo(). () { |
| 6 | if [scip-shell system . . `[`. "$1" != "--track-later" ] |
| 7 | then |
| 8 | gitscip-shell system . . git. lfs track '*.dat' |
| 9 | else |
| 10 | touchscip-shell system . . touch. .gitattributes |
| 11 | fi |
| 12 | |
| 13 | seqscip-shell system . . seq. 1 10 > a.dat |
| 14 | gitscip-shell system . . git. add .gitattributes *.dat |
| 15 | gitscip-shell system . . git. commit -m 'Initial import' |
| 16 | |
| 17 | gitscip-shell system . . git. checkout -b other |
| 18 | |
| 19 | # sed -i isn't portable. |
| 20 | sedscip-shell system . . sed. -e 's/9/B/' a.dat > b.dat |
| 21 | mvscip-shell system . . mv. b.dat a.dat |
| 22 | gitscip-shell system . . git. add -u |
| 23 | gitscip-shell system . . git. commit -m 'B' |
| 24 | |
| 25 | if [scip-shell system . . `[`. "$1" = "--track-later" ] |
| 26 | then |
| 27 | gitscip-shell system . . git. lfs track '*.dat' |
| 28 | gitscip-shell system . . git. add .gitattributes |
| 29 | gitscip-shell system . . git. commit -m 'B2' |
| 30 | fi |
| 31 | |
| 32 | gitscip-shell system . . git. checkout --force main |
| 33 | sedscip-shell system . . sed. -e 's/2/A/' a.dat > b.dat |
| 34 | mvscip-shell system . . mv. b.dat a.dat |
| 35 | gitscip-shell system . . git. add -u |
| 36 | gitscip-shell system . . git. commit -m 'A' |
| 37 | |
| 38 | if [scip-shell system . . `[`. "$1" = "--track-later" ] |
| 39 | then |
| 40 | gitscip-shell system . . git. lfs track '*.dat' |
| 41 | gitscip-shell system . . git. add -u |
| 42 | gitscip-shell system . . git. commit -m 'A2' |
| 43 | fi |
| 44 | } |
| 45 | |
| 46 | setup_custom_reposcip-shell shell shell-project 0.0.0 setup_custom_repo(). () { |
| 47 | gitscip-shell system . . git. lfs track '*.dat' |
| 48 | |
| 49 | seqscip-shell system . . seq. 1 10 > a.dat |
| 50 | gitscip-shell system . . git. add .gitattributes *.dat |
| 51 | gitscip-shell system . . git. commit -m 'Initial import' |
| 52 | |
| 53 | gitscip-shell system . . git. checkout -b other |
| 54 | |
| 55 | # sed -i isn't portable. |
| 56 | sedscip-shell system . . sed. -e 's/2/B/' -e 's/9/B/' a.dat > b.dat |
| 57 | mvscip-shell system . . mv. b.dat a.dat |
| 58 | gitscip-shell system . . git. add -u |
| 59 | gitscip-shell system . . git. commit -m 'B' |
| 60 | |
| 61 | gitscip-shell system . . git. checkout main |
| 62 | sedscip-shell system . . sed. -e 's/2/A/' -e 's/9/A/' a.dat > b.dat |
| 63 | mvscip-shell system . . mv. b.dat a.dat |
| 64 | gitscip-shell system . . git. add -u |
| 65 | gitscip-shell system . . git. commit -m 'A' |
| 66 | } |
| 67 | |
| 68 | setup_conflicting_reposcip-shell shell shell-project 0.0.0 setup_conflicting_repo(). () { |
| 69 | if [scip-shell system . . `[`. "$1" != "--track-later" ] |
| 70 | then |
| 71 | gitscip-shell system . . git. lfs track '*.dat' |
| 72 | else |
| 73 | touchscip-shell system . . touch. .gitattributes |
| 74 | fi |
| 75 | |
| 76 | seqscip-shell system . . seq. 1 10 > a.dat |
| 77 | gitscip-shell system . . git. add .gitattributes *.dat |
| 78 | gitscip-shell system . . git. commit -m 'Initial import' |
| 79 | |
| 80 | gitscip-shell system . . git. checkout -b other |
| 81 | |
| 82 | # sed -i isn't portable. |
| 83 | sedscip-shell system . . sed. -e 's/3/B/' a.dat > b.dat |
| 84 | mvscip-shell system . . mv. b.dat a.dat |
| 85 | gitscip-shell system . . git. add -u |
| 86 | gitscip-shell system . . git. commit -m 'B' |
| 87 | |
| 88 | if [scip-shell system . . `[`. "$1" = "--track-later" ] |
| 89 | then |
| 90 | gitscip-shell system . . git. lfs track '*.dat' |
| 91 | gitscip-shell system . . git. add .gitattributes |
| 92 | gitscip-shell system . . git. commit -m 'B2' |
| 93 | fi |
| 94 | |
| 95 | gitscip-shell system . . git. checkout --force main |
| 96 | sedscip-shell system . . sed. -e 's/2/A/' a.dat > b.dat |
| 97 | mvscip-shell system . . mv. b.dat a.dat |
| 98 | gitscip-shell system . . git. add -u |
| 99 | gitscip-shell system . . git. commit -m 'A' |
| 100 | |
| 101 | if [scip-shell system . . `[`. "$1" = "--track-later" ] |
| 102 | then |
| 103 | gitscip-shell system . . git. lfs track '*.dat' |
| 104 | gitscip-shell system . . git. add -u |
| 105 | gitscip-shell system . . git. commit -m 'A2' |
| 106 | fi |
| 107 | } |
| 108 | |
| 109 | begin_test "merge-driver uses Git merge by default" |
| 110 | ( |
| 111 | set -e |
| 112 | |
| 113 | reponame="merge-driver-basic" |
| 114 | gitscip-shell system . . git. init "$reponame" |
| 115 | cd "$reponame" |
| 116 | |
| 117 | result="07b26d7b3123467282635a68fdf9b59e81269cf9faf12282cedf30f393a55e5b" |
| 118 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A' |
| 119 | |
| 120 | setup_successful_reposcip-shell shell shell-project 0.0.0 setup_successful_repo(). |
| 121 | |
| 122 | gitscip-shell system . . git. merge other |
| 123 | |
| 124 | ( |
| 125 | set - |
| 126 | echoscip-shell system . . echo. 1 |
| 127 | echoscip-shell system . . echo. A |
| 128 | seqscip-shell system . . seq. 3 8 |
| 129 | echoscip-shell system . . echo. B |
| 130 | echoscip-shell system . . echo. 10 |
| 131 | ) > expected.dat |
| 132 | diffscip-shell system . . diff. -u a.dat expected.dat |
| 133 | assert_pointer "main" "a.dat" "$result" 21 |
| 134 | assert_local_object "$result" 21 |
| 135 | ) |
| 136 | end_test |
| 137 | |
| 138 | begin_test "merge-driver uses Git merge when explicit" |
| 139 | ( |
| 140 | set -e |
| 141 | |
| 142 | reponame="merge-driver-explicit" |
| 143 | gitscip-shell system . . git. init "$reponame" |
| 144 | cd "$reponame" |
| 145 | |
| 146 | result="07b26d7b3123467282635a68fdf9b59e81269cf9faf12282cedf30f393a55e5b" |
| 147 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A --program '\''git merge-file --stdout --marker-size=%%L %%A %%O %%B >%%D'\''' |
| 148 | gitscip-shell system . . git. lfs track '*.dat' |
| 149 | |
| 150 | setup_successful_reposcip-shell shell shell-project 0.0.0 setup_successful_repo(). |
| 151 | |
| 152 | gitscip-shell system . . git. merge other |
| 153 | |
| 154 | ( |
| 155 | set -e |
| 156 | echoscip-shell system . . echo. 1 |
| 157 | echoscip-shell system . . echo. A |
| 158 | seqscip-shell system . . seq. 3 8 |
| 159 | echoscip-shell system . . echo. B |
| 160 | echoscip-shell system . . echo. 10 |
| 161 | ) > expected.dat |
| 162 | diffscip-shell system . . diff. -u a.dat expected.dat |
| 163 | assert_pointer "main" "a.dat" "$result" 21 |
| 164 | assert_local_object "$result" 21 |
| 165 | ) |
| 166 | end_test |
| 167 | |
| 168 | begin_test "merge-driver uses custom driver when explicit" |
| 169 | ( |
| 170 | set -e |
| 171 | |
| 172 | reponame="merge-driver-custom" |
| 173 | gitscip-shell system . . git. init "$reponame" |
| 174 | cd "$reponame" |
| 175 | |
| 176 | result="07b26d7b3123467282635a68fdf9b59e81269cf9faf12282cedf30f393a55e5b" |
| 177 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A --program '\''(sed -n 1,5p %%A; sed -n 6,10p %%B) >%%D'\''' |
| 178 | gitscip-shell system . . git. lfs track '*.dat' |
| 179 | |
| 180 | setup_custom_reposcip-shell shell shell-project 0.0.0 setup_custom_repo(). |
| 181 | |
| 182 | gitscip-shell system . . git. merge other |
| 183 | |
| 184 | ( |
| 185 | set -e |
| 186 | echoscip-shell system . . echo. 1 |
| 187 | echoscip-shell system . . echo. A |
| 188 | seqscip-shell system . . seq. 3 8 |
| 189 | echoscip-shell system . . echo. B |
| 190 | echoscip-shell system . . echo. 10 |
| 191 | ) > expected.dat |
| 192 | diffscip-shell system . . diff. -u a.dat expected.dat |
| 193 | assert_pointer "main" "a.dat" "$result" 21 |
| 194 | assert_local_object "$result" 21 |
| 195 | ) |
| 196 | end_test |
| 197 | |
| 198 | begin_test "merge-driver reports conflicts" |
| 199 | ( |
| 200 | set -e |
| 201 | |
| 202 | reponame="merge-driver-conflicts" |
| 203 | gitscip-shell system . . git. init "$reponame" |
| 204 | cd "$reponame" |
| 205 | |
| 206 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A --program '\''git merge-file --stdout --marker-size=%%L %%A %%O %%B >%%D'\''' |
| 207 | gitscip-shell system . . git. lfs track '*.dat' |
| 208 | |
| 209 | setup_conflicting_reposcip-shell shell shell-project 0.0.0 setup_conflicting_repo(). |
| 210 | |
| 211 | gitscip-shell system . . git. merge other && exit 1 |
| 212 | sedscip-shell system . . sed. -e 's/<<<<<<<.*/<<<<<<</' -e 's/>>>>>>>.*/>>>>>>>/' a.dat > actual.dat |
| 213 | ( |
| 214 | set -e |
| 215 | echoscip-shell system . . echo. 1 |
| 216 | echoscip-shell system . . echo. "<<<<<<<" |
| 217 | echoscip-shell system . . echo. A |
| 218 | echoscip-shell system . . echo. 3 |
| 219 | echoscip-shell system . . echo. "=======" |
| 220 | echoscip-shell system . . echo. 2 |
| 221 | echoscip-shell system . . echo. B |
| 222 | echoscip-shell system . . echo. ">>>>>>>" |
| 223 | seqscip-shell system . . seq. 4 10 |
| 224 | ) > expected.dat |
| 225 | diffscip-shell system . . diff. -u actual.dat expected.dat |
| 226 | ) |
| 227 | end_test |
| 228 | |
| 229 | begin_test "merge-driver gracefully handles non-pointer" |
| 230 | ( |
| 231 | set -e |
| 232 | |
| 233 | reponame="merge-driver-non-pointer" |
| 234 | gitscip-shell system . . git. init "$reponame" |
| 235 | cd "$reponame" |
| 236 | |
| 237 | result="07b26d7b3123467282635a68fdf9b59e81269cf9faf12282cedf30f393a55e5b" |
| 238 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A' |
| 239 | |
| 240 | setup_successful_reposcip-shell shell shell-project 0.0.0 setup_successful_repo(). --track-later |
| 241 | |
| 242 | gitscip-shell system . . git. merge other |
| 243 | |
| 244 | ( |
| 245 | set - |
| 246 | echoscip-shell system . . echo. 1 |
| 247 | echoscip-shell system . . echo. A |
| 248 | seqscip-shell system . . seq. 3 8 |
| 249 | echoscip-shell system . . echo. B |
| 250 | echoscip-shell system . . echo. 10 |
| 251 | ) > expected.dat |
| 252 | diffscip-shell system . . diff. -u a.dat expected.dat |
| 253 | assert_pointer "main" "a.dat" "$result" 21 |
| 254 | assert_local_object "$result" 21 |
| 255 | ) |
| 256 | end_test |
| 257 | |
| 258 | begin_test "merge-driver reports conflicts with non-pointer" |
| 259 | ( |
| 260 | set -e |
| 261 | |
| 262 | reponame="conflicts-non-pointer" |
| 263 | gitscip-shell system . . git. init "$reponame" |
| 264 | cd "$reponame" |
| 265 | |
| 266 | gitscip-shell system . . git. config merge.lfs.driver 'git lfs merge-driver --ancestor %O --current %A --other %B --marker-size %L --output %A --program '\''git merge-file --stdout --marker-size=%%L %%A %%O %%B >%%D'\''' |
| 267 | |
| 268 | setup_conflicting_reposcip-shell shell shell-project 0.0.0 setup_conflicting_repo(). --track-later |
| 269 | |
| 270 | gitscip-shell system . . git. merge other && exit 1 |
| 271 | sedscip-shell system . . sed. -e 's/<<<<<<<.*/<<<<<<</' -e 's/>>>>>>>.*/>>>>>>>/' a.dat > actual.dat |
| 272 | ( |
| 273 | set -e |
| 274 | echoscip-shell system . . echo. 1 |
| 275 | echoscip-shell system . . echo. "<<<<<<<" |
| 276 | echoscip-shell system . . echo. A |
| 277 | echoscip-shell system . . echo. 3 |
| 278 | echoscip-shell system . . echo. "=======" |
| 279 | echoscip-shell system . . echo. 2 |
| 280 | echoscip-shell system . . echo. B |
| 281 | echoscip-shell system . . echo. ">>>>>>>" |
| 282 | seqscip-shell system . . seq. 4 10 |
| 283 | ) > expected.dat |
| 284 | diffscip-shell system . . diff. -u actual.dat expected.dat |
| 285 | ) |
| 286 | end_test |