| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/fixtures/migrate.sh" |
| 4 | . "$(dirname "$0")/testlib.sh" |
| 5 | |
| 6 | begin_test "migrate import (--fixup)" |
| 7 | ( |
| 8 | set -e |
| 9 | |
| 10 | setup_single_local_branch_tracked_corrupt |
| 11 | |
| 12 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 13 | |
| 14 | git lfs migrate import --everything --fixup --yes |
| 15 | |
| 16 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 17 | assert_local_object "$txt_oid" "120" |
| 18 | |
| 19 | main="$(git rev-parse refs/heads/main)" |
| 20 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 21 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 22 | ) |
| 23 | end_test |
| 24 | |
| 25 | begin_test "migrate import (--fixup, special attributes)" |
| 26 | ( |
| 27 | set -e |
| 28 | setup_single_local_branch_tracked_corrupt special |
| 29 | |
| 30 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 31 | dat_oid="$(calc_oid "$(git cat-file -p :a.dat)")" |
| 32 | bat_oid="$(calc_oid "$(git cat-file -p :a.bat)")" |
| 33 | out_oid="$(calc_oid "$(git cat-file -p :a.out)")" |
| 34 | bin_oid="$(calc_oid "$(git cat-file -p :a.bin)")" |
| 35 | |
| 36 | git lfs migrate import --everything --fixup --yes |
| 37 | |
| 38 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 39 | assert_local_object "$txt_oid" "120" |
| 40 | |
| 41 | assert_pointer "refs/heads/main" "a.bat" "$bat_oid" "120" |
| 42 | assert_local_object "$bat_oid" "120" |
| 43 | |
| 44 | assert_pointer "refs/heads/main" "a.bin" "$bin_oid" "120" |
| 45 | assert_local_object "$bin_oid" "120" |
| 46 | |
| 47 | assert_pointer "refs/heads/main" "a.dat" "$dat_oid" "120" |
| 48 | assert_local_object "$dat_oid" "120" |
| 49 | |
| 50 | assert_pointer "refs/heads/main" "a.out" "$out_oid" "120" |
| 51 | assert_local_object "$out_oid" "120" |
| 52 | ) |
| 53 | end_test |
| 54 | |
| 55 | begin_test "migrate import (--fixup, complex nested)" |
| 56 | ( |
| 57 | set -e |
| 58 | |
| 59 | setup_single_local_branch_complex_tracked |
| 60 | |
| 61 | a_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 62 | b_oid="$(calc_oid "$(git cat-file -p :dir/b.txt)")" |
| 63 | |
| 64 | git lfs migrate import --everything --fixup --yes |
| 65 | |
| 66 | assert_pointer "refs/heads/main" "a.txt" "$a_oid" "1" |
| 67 | refute_pointer "refs/heads/main" "dir/b.txt" |
| 68 | |
| 69 | assert_local_object "$a_oid" "1" |
| 70 | refute_local_object "$b_oid" "1" |
| 71 | |
| 72 | main="$(git rev-parse refs/heads/main)" |
| 73 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 74 | main_dir_attrs="$(git cat-file -p "$main:dir/.gitattributes")" |
| 75 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 76 | echo "$main_dir_attrs" | grep -q "*.txt !filter !diff !merge" |
| 77 | ) |
| 78 | end_test |
| 79 | |
| 80 | begin_test "migrate import (--fixup, --include)" |
| 81 | ( |
| 82 | set -e |
| 83 | |
| 84 | setup_single_local_branch_tracked_corrupt |
| 85 | |
| 86 | git lfs migrate import --everything --fixup --yes --include="*.txt" 2>&1 \ |
| 87 | | tee migrate.log |
| 88 | |
| 89 | if [ "${PIPESTATUS[0]}" -eq 0 ]; then |
| 90 | echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..." |
| 91 | exit 1 |
| 92 | fi |
| 93 | |
| 94 | grep -q "Cannot use --fixup with --include, --exclude" migrate.log |
| 95 | ) |
| 96 | end_test |
| 97 | |
| 98 | begin_test "migrate import (--fixup, --exclude)" |
| 99 | ( |
| 100 | set -e |
| 101 | |
| 102 | setup_single_local_branch_tracked_corrupt |
| 103 | |
| 104 | git lfs migrate import --everything --fixup --yes --exclude="*.txt" 2>&1 \ |
| 105 | | tee migrate.log |
| 106 | |
| 107 | if [ "${PIPESTATUS[0]}" -eq 0 ]; then |
| 108 | echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..." |
| 109 | exit 1 |
| 110 | fi |
| 111 | |
| 112 | grep -q "Cannot use --fixup with --include, --exclude" migrate.log |
| 113 | ) |
| 114 | end_test |
| 115 | |
| 116 | begin_test "migrate import (--fixup, --no-rewrite)" |
| 117 | ( |
| 118 | set -e |
| 119 | |
| 120 | setup_single_local_branch_tracked_corrupt |
| 121 | |
| 122 | git lfs migrate import --everything --fixup --yes --no-rewrite 2>&1 \ |
| 123 | | tee migrate.log |
| 124 | |
| 125 | if [ "${PIPESTATUS[0]}" -eq 0 ]; then |
| 126 | echo >&2 "Expected 'git lfs migrate ...' to fail, didn't ..." |
| 127 | exit 1 |
| 128 | fi |
| 129 | |
| 130 | grep -qe "--no-rewrite and --fixup cannot be combined" migrate.log |
| 131 | ) |
| 132 | end_test |
| 133 | |
| 134 | begin_test "migrate import (--fixup with remote tags)" |
| 135 | ( |
| 136 | set -e |
| 137 | |
| 138 | setup_single_local_branch_tracked_corrupt |
| 139 | |
| 140 | git lfs uninstall |
| 141 | |
| 142 | lfstest-genrandom --base64 120 >b.txt |
| 143 | git add b.txt |
| 144 | git commit -m "b.txt" |
| 145 | |
| 146 | git tag -m tag1 -a tag1 |
| 147 | git reset --hard HEAD^ |
| 148 | |
| 149 | git lfs install |
| 150 | |
| 151 | cwd=$(pwd) |
| 152 | cd "$TRASHDIR" |
| 153 | |
| 154 | git clone "$cwd" "$reponame-2" |
| 155 | cd "$reponame-2" |
| 156 | |
| 157 | # We're checking here that this succeeds even though it does nothing in this |
| 158 | # case. |
| 159 | git lfs migrate import --fixup --yes main |
| 160 | ) |
| 161 | end_test |
| 162 | |
| 163 | begin_test "migrate import (--fixup, .gitattributes symlink)" |
| 164 | ( |
| 165 | set -e |
| 166 | |
| 167 | setup_single_local_branch_tracked_corrupt link |
| 168 | |
| 169 | git lfs migrate import --everything --fixup --yes 2>&1 | tee migrate.log |
| 170 | if [ ${PIPESTATUS[0]} -eq 0 ]; then |
| 171 | echo >&2 "fatal: expected git lfs migrate import to fail, didn't" |
| 172 | exit 1 |
| 173 | fi |
| 174 | |
| 175 | grep "expected '.gitattributes' to be a file, got a symbolic link" migrate.log |
| 176 | |
| 177 | main="$(git rev-parse refs/heads/main)" |
| 178 | |
| 179 | attrs_main_sha="$(git show $main:.gitattributes | git hash-object --stdin)" |
| 180 | |
| 181 | diff -u <(git ls-tree $main -- .gitattributes) <(cat <<-EOF |
| 182 | 120000 blob $attrs_main_sha .gitattributes |
| 183 | EOF |
| 184 | ) |
| 185 | ) |
| 186 | end_test |
| 187 | |
| 188 | begin_test "migrate import (--fixup, .gitattributes with macro)" |
| 189 | ( |
| 190 | set -e |
| 191 | |
| 192 | setup_single_local_branch_tracked_corrupt macro |
| 193 | |
| 194 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 195 | |
| 196 | git lfs migrate import --everything --fixup --yes |
| 197 | |
| 198 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 199 | assert_local_object "$txt_oid" "120" |
| 200 | |
| 201 | main="$(git rev-parse refs/heads/main)" |
| 202 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 203 | echo "$main_attrs" | grep -q "*.txt filter=lfs diff=lfs merge=lfs" |
| 204 | ) |
| 205 | end_test |
| 206 | |
| 207 | begin_test "migrate import (--fixup, .gitattributes with LFS macro)" |
| 208 | ( |
| 209 | set -e |
| 210 | |
| 211 | setup_single_local_branch_tracked_corrupt lfsmacro |
| 212 | |
| 213 | txt_oid="$(calc_oid "$(git cat-file -p :a.txt)")" |
| 214 | |
| 215 | git lfs migrate import --everything --fixup --yes |
| 216 | |
| 217 | assert_pointer "refs/heads/main" "a.txt" "$txt_oid" "120" |
| 218 | assert_local_object "$txt_oid" "120" |
| 219 | |
| 220 | main="$(git rev-parse refs/heads/main)" |
| 221 | main_attrs="$(git cat-file -p "$main:.gitattributes")" |
| 222 | echo "$main_attrs" | grep -q "\[attr\]lfs filter=lfs diff=lfs merge=lfs" |
| 223 | echo "$main_attrs" | grep -q "*\.txt lfs" |
| 224 | ) |
| 225 | end_test |
| 226 | |
| 227 | begin_test "migrate import (no potential fixup, --fixup, no .gitattributes)" |
| 228 | ( |
| 229 | set -e |
| 230 | |
| 231 | setup_multiple_local_branches |
| 232 | |
| 233 | original_head="$(git rev-parse HEAD)" |
| 234 | |
| 235 | # Ensure "fixup" command reports nothing if no files are tracked by LFS. |
| 236 | git lfs migrate import --everything --fixup --yes >migrate.log |
| 237 | [ "0" -eq "$(cat migrate.log | wc -l)" ] |
| 238 | |
| 239 | migrated_head="$(git rev-parse HEAD)" |
| 240 | |
| 241 | assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" |
| 242 | ) |
| 243 | end_test |
| 244 | |
| 245 | begin_test "migrate import (no potential fixup, --fixup, .gitattributes with macro)" |
| 246 | ( |
| 247 | set -e |
| 248 | |
| 249 | setup_multiple_local_branches |
| 250 | |
| 251 | echo "[attr]foo foo" >.gitattributes |
| 252 | lfstest-genrandom --base64 30 >a.md |
| 253 | git add .gitattributes a.md |
| 254 | git commit -m macro |
| 255 | |
| 256 | original_head="$(git rev-parse HEAD)" |
| 257 | |
| 258 | # Ensure "fixup" command reports nothing if no files are tracked by LFS. |
| 259 | git lfs migrate import --everything --fixup --yes >migrate.log |
| 260 | [ "0" -eq "$(cat migrate.log | wc -l)" ] |
| 261 | |
| 262 | migrated_head="$(git rev-parse HEAD)" |
| 263 | |
| 264 | assert_ref_unmoved "HEAD" "$original_head" "$migrated_head" |
| 265 | ) |
| 266 | end_test |