Debian Codegraph @

t/t-attributes.sh

raw symbols SCIP
1 #!/usr/bin/envscip-shell filesystem . . `/usr/bin/env`. bash
2
3 . "$(dirnamescip-shell system . . dirname. "$0")/testlib.sh"
4
5 begin_test "macros"
6 (
7 set -e
8
9 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")"
10 clone_repo "$reponame" repo
11
12 mkdirscip-shell system . . mkdir. dir
13 printfscip-shell system . . printf. '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n*.dat lfs\n' \
14 > .gitattributes
15 printfscip-shell system . . printf. '[attr]lfs2 filter=lfs diff=lfs merge=lfs -text\n*.bin lfs2\n' \
16 > dir/.gitattributes
17 gitscip-shell system . . git. add .gitattributes dir
18 gitscip-shell system . . git. commit -m 'initial import'
19
20 contents="some data"
21 printfscip-shell system . . printf. "$contents" > foo.dat
22 gitscip-shell system . . git. add *.dat
23 gitscip-shell system . . git. commit -m 'foo.dat'
24 assert_local_object "$(calc_oid "$contents")" 9
25
26 contents2="other data"
27 printfscip-shell system . . printf. "$contents2" > dir/foo.bin
28 gitscip-shell system . . git. add dir
29 gitscip-shell system . . git. commit -m 'foo.bin'
30 refute_local_object "$(calc_oid "$contents2")"
31
32 gitscip-shell system . . git. lfs track '*.dat' 2>&1 | teescip-shell system . . tee. track.log
33 grepscip-shell system . . grep. '"*.dat" already supported' track.log
34
35 cd dir
36 gitscip-shell system . . git. lfs track '*.bin' 2>&1 | teescip-shell system . . tee. track.log
37 grepscip-shell system . . grep. '"*.bin" already supported' track.log && exit 1
38 truescip-shell system . . 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="$(basenamescip-shell system . . basename. "$0" ".sh")-home"
57 clone_repo "$reponame" repo-home
58
59 mkdirscip-shell system . . mkdir. -p "$HOME/.config/git"
60 printfscip-shell system . . 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 printfscip-shell system . . printf. "$contents" > foo.dat
65 gitscip-shell system . . git. add *.dat
66 gitscip-shell system . . git. commit -m 'foo.dat'
67 assert_local_object "$(calc_oid "$contents")" 9
68
69 gitscip-shell system . . git. lfs track 2>&1 | teescip-shell system . . tee. track.log
70 grepscip-shell system . . grep. '*.dat' track.log
71 )
72 end_test
73
74 begin_test "macros with HOME split"
75 (
76 set -e
77
78 reponame="$(basenamescip-shell system . . basename. "$0" ".sh")-home-split"
79 clone_repo "$reponame" repo-home-split
80
81 mkdirscip-shell system . . mkdir. -p "$HOME/.config/git"
82 printfscip-shell system . . printf. '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n' \
83 > "$HOME/.config/git/attributes"
84
85 printfscip-shell system . . printf. '*.dat lfs\n' > .gitattributes
86 gitscip-shell system . . git. add .gitattributes
87 gitscip-shell system . . git. commit -m 'initial import'
88
89 contents="some data"
90 printfscip-shell system . . printf. "$contents" > foo.dat
91 gitscip-shell system . . git. add *.dat
92 gitscip-shell system . . git. commit -m 'foo.dat'
93 assert_local_object "$(calc_oid "$contents")" 9
94
95 gitscip-shell system . . git. lfs track '*.dat' 2>&1 | teescip-shell system . . tee. track.log
96 grepscip-shell system . . 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="$(basenamescip-shell system . . basename. "$0" ".sh")"
105 clone_repo "$reponame" repo-unspecified
106
107 mkdirscip-shell system . . mkdir. dir
108 printfscip-shell system . . printf. '[attr]lfs filter=lfs diff=lfs merge=lfs -text\n**/*.dat lfs\n' \
109 > .gitattributes
110 printfscip-shell system . . printf. '*.dat !lfs\n' \
111 > dir/.gitattributes
112 gitscip-shell system . . git. add .gitattributes dir
113 gitscip-shell system . . git. commit -m 'initial import'
114
115 contents="some data"
116 printfscip-shell system . . printf. "$contents" > foo.dat
117 gitscip-shell system . . git. add *.dat
118 gitscip-shell system . . git. commit -m 'foo.dat'
119 assert_local_object "$(calc_oid "$contents")" 9
120
121 contents2="other data"
122 printfscip-shell system . . printf. "$contents2" > dir/foo.dat
123 gitscip-shell system . . git. add dir
124 gitscip-shell system . . git. commit -m 'dir/foo.dat'
125 refute_local_object "$(calc_oid "$contents2")"
126
127 gitscip-shell system . . git. lfs track '**/*.dat' 2>&1 | teescip-shell system . . tee. track.log
128 grepscip-shell system . . 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