| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | . "$(dirname "$0")/testlib.sh" |
| 4 | |
| 5 | begin_test "macros" |
| 6 | ( |
| 7 | set -e |
| 8 | |
| 9 | reponame="$(basename "$0" ".sh")" |
| 10 | clone_repo "$reponame" repo |
| 11 | |
| 12 | mkdir dir |
| 13 | printf '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.dat lfs\n' \ |
| 14 | > .gitattributes |
| 15 | printf '[attr]lfs2 filter=lfs diff=lfs merge=lfs -text\n*.bin lfs2\n' \ |
| 16 | > dir/.gitattributes |
| 17 | git add .gitattributes dir |
| 18 | git commit -m 'initial import' |
| 19 | |
| 20 | contents="some data" |
| 21 | printf "$contents" > foo.dat |
| 22 | git add *.dat |
| 23 | git commit -m 'foo.dat' |
| 24 | assert_local_object "$(calc_oid "$contents")" 9 |
| 25 | |
| 26 | contents2="other data" |
| 27 | printf "$contents2" > dir/foo.bin |
| 28 | git add dir |
| 29 | git commit -m 'foo.bin' |
| 30 | refute_local_object "$(calc_oid "$contents2")" |
| 31 | |
| 32 | git lfs track '*.dat' 2>&1 | tee track.log |
| 33 | grep '"*.dat" already supported' track.log |
| 34 | |
| 35 | cd dir |
| 36 | git lfs track '*.bin' 2>&1 | tee track.log |
| 37 | grep '"*.bin" already supported' track.log && exit 1 |
| 38 | true |
| 39 | |
| 40 | # NOTE: At present we do not test that "git lfs track" reports |
| 41 | # "already supported" when it finds a pattern in a subdirectory's |
| 42 | # .gitattributes file which references a macro attribute in |
| 43 | # the top-level .gitattributes file that sets "filter=lfs". |
| 44 | # This is because, while "git check-attr" resolves macro references |
| 45 | # from a file such as dir/.gitattributes to .gitattributess, |
| 46 | # "git lfs track" only resolves macro references as it reads these |
| 47 | # files in depth-first order, so unlike Git it does not expand an |
| 48 | # "lfs" reference to "filter=lfs" if it appears in dir/.gitattributes. |
| 49 | ) |
| 50 | end_test |
| 51 | |
| 52 | begin_test "macros with HOME" |
| 53 | ( |
| 54 | set -e |
| 55 | |
| 56 | reponame="$(basename "$0" ".sh")-home" |
| 57 | clone_repo "$reponame" repo-home |
| 58 | |
| 59 | mkdir -p "$HOME/.config/git" |
| 60 | printf '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.dat lfs\n' \ |
| 61 | > "$HOME/.config/git/attributes" |
| 62 | |
| 63 | contents="some data" |
| 64 | printf "$contents" > foo.dat |
| 65 | git add *.dat |
| 66 | git commit -m 'foo.dat' |
| 67 | assert_local_object "$(calc_oid "$contents")" 9 |
| 68 | |
| 69 | git lfs track 2>&1 | tee track.log |
| 70 | grep '*.dat' track.log |
| 71 | ) |
| 72 | end_test |
| 73 | |
| 74 | begin_test "macros with HOME split" |
| 75 | ( |
| 76 | set -e |
| 77 | |
| 78 | reponame="$(basename "$0" ".sh")-home-split" |
| 79 | clone_repo "$reponame" repo-home-split |
| 80 | |
| 81 | mkdir -p "$HOME/.config/git" |
| 82 | printf '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n' \ |
| 83 | > "$HOME/.config/git/attributes" |
| 84 | |
| 85 | printf '*.dat lfs\n' > .gitattributes |
| 86 | git add .gitattributes |
| 87 | git commit -m 'initial import' |
| 88 | |
| 89 | contents="some data" |
| 90 | printf "$contents" > foo.dat |
| 91 | git add *.dat |
| 92 | git commit -m 'foo.dat' |
| 93 | assert_local_object "$(calc_oid "$contents")" 9 |
| 94 | |
| 95 | git lfs track '*.dat' 2>&1 | tee track.log |
| 96 | grep '"*.dat" already supported' track.log |
| 97 | ) |
| 98 | end_test |
| 99 | |
| 100 | begin_test "macros with unspecified flag" |
| 101 | ( |
| 102 | set -e |
| 103 | |
| 104 | reponame="$(basename "$0" ".sh")" |
| 105 | clone_repo "$reponame" repo-unspecified |
| 106 | |
| 107 | mkdir dir |
| 108 | printf '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n**/*.dat lfs\n' \ |
| 109 | > .gitattributes |
| 110 | printf '*.dat !lfs\n' \ |
| 111 | > dir/.gitattributes |
| 112 | git add .gitattributes dir |
| 113 | git commit -m 'initial import' |
| 114 | |
| 115 | contents="some data" |
| 116 | printf "$contents" > foo.dat |
| 117 | git add *.dat |
| 118 | git commit -m 'foo.dat' |
| 119 | assert_local_object "$(calc_oid "$contents")" 9 |
| 120 | |
| 121 | contents2="other data" |
| 122 | printf "$contents2" > dir/foo.dat |
| 123 | git add dir |
| 124 | git commit -m 'dir/foo.dat' |
| 125 | refute_local_object "$(calc_oid "$contents2")" |
| 126 | |
| 127 | git lfs track '**/*.dat' 2>&1 | tee track.log |
| 128 | grep '"*\*/\*.dat" already supported' track.log |
| 129 | |
| 130 | # NOTE: The intent of this test is to confirm that running the |
| 131 | # "git lfs track '*.dat'" command in the dir/ directory returns |
| 132 | # "already supported", because it finds the "*.dat" pattern and |
| 133 | # resolves its reference to the "lfs" macro attribute in |
| 134 | # top-level .gitattributes file such that a "filter" attribute |
| 135 | # is recognized, albeit with the unspecified state set. |
| 136 | # |
| 137 | # However, as noted in the "macros" test above, because the |
| 138 | # "git lfs track" command parses the dir/.gitattributes file |
| 139 | # before the top-level .gitattributes file, it does not resolve |
| 140 | # the macro attribute reference, and our test would fail despite |
| 141 | # our ability to parse macro attribute references with a "!" |
| 142 | # unspecified flag character prefix. |
| 143 | |
| 144 | #cd dir |
| 145 | #git lfs track '*.dat' 2>&1 | tee track.log |
| 146 | #grep '"*.dat" already supported' track.log |
| 147 | ) |
| 148 | end_test |