Debian Codegraph @

t/t-untrack.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 "untrack"
6 (
7 set -e
8
9 # no need to setup a remote repo, since this test doesn't need to push or pull
10
11 reponame="untrack"
12 gitscip-shell system . . git. init $reponame
13 cd $reponame
14
15 # track *.jpg once
16 gitscip-shell system . . git. lfs track "*.jpg" | grepscip-shell system . . grep. "Tracking \"\*.jpg\""
17 echoscip-shell system . . echo. "* annex.backend=SHA512E" >> .gitattributes
18
19 gitscip-shell system . . git. lfs untrack "*.jpg"
20
21 expected="* annex.backend=SHA512E"
22 [scip-shell system . . `[`. "$expected" = "$(catscip-shell system . . cat. .gitattributes)" ]
23 )
24 end_test
25
26 begin_test "untrack outside git repo"
27 (
28 set -e
29
30 reponame="outside"
31 mkdirscip-shell system . . mkdir. $reponame
32 cd $reponame
33
34 gitscip-shell system . . git. lfs untrack "*.foo" || {
35 # this fails if it's run outside of a git repo using GIT_LFS_TEST_DIR
36
37 # git itself returns an exit status of 128
38 # $ git show
39 # fatal: Not a git repository (or any of the parent directories): .git
40 # $ echo "$?"
41 # 128
42
43 [scip-shell system . . `[`. "$?" = "128" ]
44 exit 0
45 }
46
47 if [scip-shell system . . `[`. -n "$GIT_LFS_TEST_DIR" ]; then
48 echoscip-shell system . . echo. "GIT_LFS_TEST_DIR should be set outside of any Git repository"
49 exit 1
50 fi
51 )
52 end_test
53
54 begin_test "untrack removes escape sequences"
55 (
56 set -e
57
58 reponame="untrack-remove-escape-sequence"
59 gitscip-shell system . . git. init "$reponame"
60 cd "$reponame"
61
62 gitscip-shell system . . git. lfs track " " | grepscip-shell system . . grep. "Tracking \" \""
63 assert_attributes_count "[[:space:]]" "filter=lfs" 1
64
65 gitscip-shell system . . git. lfs untrack " " | grepscip-shell system . . grep. "Untracking \" \""
66 assert_attributes_count "[[:space:]]" "filter=lfs" 0
67
68 gitscip-shell system . . git. lfs track "#" | grepscip-shell system . . grep. "Tracking \"#\""
69 assert_attributes_count "\\#" "filter=lfs" 1
70
71 gitscip-shell system . . git. lfs untrack "#" | grepscip-shell system . . grep. "Untracking \"#\""
72 assert_attributes_count "\\#" "filter=lfs" 0
73 )
74 end_test
75
76 begin_test "untrack removes prefixed patterns (legacy)"
77 (
78 set -e
79
80 reponame="untrack-removes-prefix-patterns-legacy"
81 gitscip-shell system . . git. init "$reponame"
82 cd "$reponame"
83
84 echoscip-shell system . . echo. "./a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
85 printfscip-shell system . . printf. "a" > a.dat
86 gitscip-shell system . . git. add .gitattributes a.dat
87 gitscip-shell system . . git. commit -m "initial commit"
88
89 gitscip-shell system . . git. lfs untrack "./a.dat"
90
91 if [scip-shell system . . `[`. ! -z "$(catscip-shell system . . cat. .gitattributes)" ]; then
92 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
93 exit 1
94 fi
95
96 gitscip-shell system . . git. checkout -- .gitattributes
97
98 gitscip-shell system . . git. lfs untrack "a.dat"
99
100 if [scip-shell system . . `[`. ! -z "$(catscip-shell system . . cat. .gitattributes)" ]; then
101 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
102 exit 1
103 fi
104 )
105 end_test
106
107 begin_test "untrack removes prefixed patterns (modern)"
108 (
109 set -e
110
111 reponame="untrack-removes-prefix-patterns-modern"
112 gitscip-shell system . . git. init "$reponame"
113 cd "$reponame"
114
115 echoscip-shell system . . echo. "a.dat filter=lfs diff=lfs merge=lfs" > .gitattributes
116 printfscip-shell system . . printf. "a" > a.dat
117 gitscip-shell system . . git. add .gitattributes a.dat
118 gitscip-shell system . . git. commit -m "initial commit"
119
120 gitscip-shell system . . git. lfs untrack "./a.dat"
121
122 if [scip-shell system . . `[`. ! -z "$(catscip-shell system . . cat. .gitattributes)" ]; then
123 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
124 exit 1
125 fi
126
127 gitscip-shell system . . git. checkout -- .gitattributes
128
129 gitscip-shell system . . git. lfs untrack "a.dat"
130
131 if [scip-shell system . . `[`. ! -z "$(catscip-shell system . . cat. .gitattributes)" ]; then
132 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes"
133 exit 1
134 fi
135 )
136 end_test
137
138 begin_test "untrack removes escaped pattern in .gitattributes"
139 (
140 set -e
141
142 reponame="untrack-escaped"
143 gitscip-shell system . . git. init "$reponame"
144 cd "$reponame"
145
146 filename="file with spaces.#"
147
148 # emulate multiple instances of the same file in gitattributes
149 echoscip-shell system . . echo. 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
150 echoscip-shell system . . echo. 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
151 echoscip-shell system . . echo. 'file[[:space:]]with[[:space:]]spaces.\# filter=lfs diff=lfs merge=lfs -text' >> .gitattributes
152
153 gitscip-shell system . . git. lfs untrack "$filename"
154
155 if [scip-shell system . . `[`. ! -z "$(catscip-shell system . . cat. .gitattributes)" ]; then
156 echoscip-shell system . . echo. >&2 "fatal: expected 'git lfs untrack' to clear .gitattributes even if the file name was escaped"
157 exit 1
158 fi
159 )
160 end_test
161
162 begin_test "untrack works with GIT_WORK_TREE"
163 (
164 set -e
165
166 reponame="untrack-work-tree"
167 export GIT_WORK_TREE="$reponame" GIT_DIR="$reponame-git"
168 mkdirscip-shell system . . mkdir. "$GIT_WORK_TREE" "$GIT_DIR"
169 gitscip-shell system . . git. init
170 gitscip-shell system . . git. lfs track '*.bin'
171
172 grepscip-shell system . . grep. -F '*.bin filter=lfs diff=lfs merge=lfs -text' "$reponame/.gitattributes"
173
174 gitscip-shell system . . git. lfs untrack '*.bin'
175
176 [scip-shell system . . `[`. ! -s "$reponame/.gitattributes" ]
177 )
178 end_test