Debian Codegraph @

tests/test-symlinks.t

raw
1 #require symlink
2
3 #testcases dirstate-v1 dirstate-v2
4
5 #if dirstate-v2
6 $ cat >> $HGRCPATH << EOF
7 > [format]
8 > use-dirstate-v2=1
9 > [storage]
10 > dirstate-v2.slow-path=allow
11 > EOF
12 #endif
13
14 == tests added in 0.7 ==
15
16 $ hg init test-symlinks-0.7; cd test-symlinks-0.7;
17 $ touch foo; ln -s foo bar; ln -s nonexistent baz
18
19 import with add and addremove -- symlink walking should _not_ screwup.
20
21 $ hg add
22 adding bar
23 adding baz
24 adding foo
25 $ hg forget bar baz foo
26 $ hg addremove
27 adding bar
28 adding baz
29 adding foo
30
31 commit -- the symlink should _not_ appear added to dir state
32
33 $ hg commit -m 'initial'
34
35 $ touch bomb
36
37 again, symlink should _not_ show up on dir state
38
39 $ hg addremove
40 adding bomb
41
42 Assert screamed here before, should go by without consequence
43
44 $ hg commit -m 'is there a bug?'
45 $ cd ..
46
47
48 == fifo & ignore ==
49
50 $ hg init test; cd test;
51
52 $ mkdir dir
53 $ touch a.c dir/a.o dir/b.o
54
55 test what happens if we want to trick hg
56
57 $ hg commit -A -m 0
58 adding a.c
59 adding dir/a.o
60 adding dir/b.o
61 $ echo "relglob:*.o" > .hgignore
62 $ rm a.c
63 $ rm dir/a.o
64 $ rm dir/b.o
65 $ mkdir dir/a.o
66 $ ln -s nonexistent dir/b.o
67 $ mkfifo a.c
68
69 it should show a.c, dir/a.o and dir/b.o deleted
70
71 $ hg status
72 M dir/b.o
73 ! a.c
74 ! dir/a.o
75 ? .hgignore
76 $ hg status a.c
77 a.c: unsupported file type (type is fifo)
78 ! a.c
79 $ cd ..
80
81
82 == symlinks from outside the tree ==
83
84 test absolute path through symlink outside repo
85
86 $ p=`pwd`
87 $ hg init x
88 $ ln -s x y
89 $ cd x
90 $ touch f
91 $ hg add f
92 $ hg status "$p"/y/f
93 A f
94
95 try symlink outside repo to file inside
96
97 $ ln -s x/f ../z
98
99 this should fail
100
101 $ hg status ../z && { echo hg mistakenly exited with status 0; exit 1; } || :
102 abort: ../z not under root '$TESTTMP/x'
103 $ cd ..
104
105
106 == cloning symlinks ==
107 $ hg init clone; cd clone;
108
109 try cloning symlink in a subdir
110 1. commit a symlink
111
112 $ mkdir -p a/b/c
113 $ cd a/b/c
114 $ ln -s /path/to/symlink/source demo
115 $ cd ../../..
116 $ hg stat
117 ? a/b/c/demo
118 $ hg commit -A -m 'add symlink in a/b/c subdir'
119 adding a/b/c/demo
120
121 2. clone it
122
123 $ cd ..
124 $ hg clone clone clonedest
125 updating to branch default
126 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
127
128
129 == symlink and git diffs ==
130
131 git symlink diff
132
133 $ cd clonedest
134 $ hg diff --git -r null:tip
135 diff --git a/a/b/c/demo b/a/b/c/demo
136 new file mode 120000
137 --- /dev/null
138 +++ b/a/b/c/demo
139 @@ -0,0 +1,1 @@
140 +/path/to/symlink/source
141 \ No newline at end of file
142 $ hg export --git tip > ../sl.diff
143
144 import git symlink diff
145
146 $ hg rm a/b/c/demo
147 $ hg commit -m'remove link'
148 $ hg import ../sl.diff
149 applying ../sl.diff
150 $ hg diff --git -r 1:tip
151 diff --git a/a/b/c/demo b/a/b/c/demo
152 new file mode 120000
153 --- /dev/null
154 +++ b/a/b/c/demo
155 @@ -0,0 +1,1 @@
156 +/path/to/symlink/source
157 \ No newline at end of file
158
159 == symlinks and addremove ==
160
161 directory moved and symlinked
162
163 $ mkdir foo
164 $ touch foo/a
165 $ hg ci -Ama
166 adding foo/a
167 $ mv foo bar
168 $ ln -s bar foo
169 $ hg status
170 ! foo/a
171 ? bar/a
172 ? foo
173
174 now addremove should remove old files
175
176 $ hg addremove
177 adding bar/a
178 adding foo
179 removing foo/a
180
181 commit and update back
182
183 $ hg ci -mb
184 $ hg up '.^'
185 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
186 $ hg up tip
187 2 files updated, 0 files merged, 1 files removed, 0 files unresolved
188
189 $ cd ..
190
191 == symlinks and add with --include ==
192
193 directory moved and symlinked
194
195 $ hg init add-include
196 $ cd add-include
197 $ mkdir foo
198 $ touch foo/a
199 $ hg ci -Ama
200 adding foo/a
201 $ hg mv foo bar
202 moving foo/a to bar/a
203 $ ln -s bar foo
204 $ hg status
205 A bar/a
206 R foo/a
207 ? foo
208
209 can add with --include
210
211 $ hg add -I foo
212 adding foo
213 $ hg status
214 A bar/a
215 A foo
216 R foo/a
217
218 $ cd ..
219
220 == root of repository is symlinked ==
221
222 $ hg init root
223 $ ln -s root link
224 $ cd root
225 $ echo foo > foo
226 $ hg status
227 ? foo
228 $ hg status ../link
229 ? foo
230 $ hg add foo
231 $ hg cp foo "$TESTTMP/link/bar"
232 foo has not been committed yet, so no copy data will be stored for bar.
233 $ cd ..
234
235
236 $ hg init b
237 $ cd b
238 $ ln -s nothing dangling
239 $ hg commit -m 'commit symlink without adding' dangling
240 abort: dangling: file not tracked!
241 [10]
242 $ hg add dangling
243 $ hg commit -m 'add symlink'
244
245 $ hg tip -v
246 changeset: 0:cabd88b706fc
247 tag: tip
248 user: test
249 date: Thu Jan 01 00:00:00 1970 +0000
250 files: dangling
251 description:
252 add symlink
253
254
255 $ hg manifest --debug
256 2564acbe54bbbedfbf608479340b359f04597f80 644 @ dangling
257 $ readlink.py dangling
258 dangling -> nothing
259
260 $ rm dangling
261 $ ln -s void dangling
262 $ hg commit -m 'change symlink'
263 $ readlink.py dangling
264 dangling -> void
265
266
267 modifying link
268
269 $ rm dangling
270 $ ln -s empty dangling
271 $ readlink.py dangling
272 dangling -> empty
273
274
275 reverting to rev 0:
276
277 $ hg revert -r 0 -a
278 reverting dangling
279 $ readlink.py dangling
280 dangling -> nothing
281
282
283 backups:
284
285 $ readlink.py *.orig
286 dangling.orig -> empty
287 $ rm *.orig
288 $ hg up -C
289 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
290
291 copies
292
293 $ hg cp -v dangling dangling2
294 copying dangling to dangling2
295 $ hg st -Cmard
296 A dangling2
297 dangling
298 $ readlink.py dangling dangling2
299 dangling -> void
300 dangling2 -> void
301
302
303 Issue995: hg copy -A incorrectly handles symbolic links
304
305 $ hg up -C
306 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
307 $ mkdir dir
308 $ ln -s dir dirlink
309 $ hg ci -qAm 'add dirlink'
310 $ mkdir newdir
311 $ mv dir newdir/dir
312 $ mv dirlink newdir/dirlink
313 $ hg mv -A dirlink newdir/dirlink
314
315 $ cd ..
316
317 Update between two revisions where a path is a symlink in one and a regular file
318 in the other, with *identical* content (so only the manifest flag differs). The
319 working copy file must actually be converted, and the status must be clean.
320 This exercises the flags-only path (both the Python and Rust `update-from-clean`
321 code paths).
322
323 $ hg init flagonly
324 $ cd flagonly
325 $ advance_fs_time() {
326 > "$PYTHON" "$TESTDIR"/testlib/advance-fs-time.py "$TESTTMP"/test-file.txt
327 > }
328 $ ln -s ../target-content f
329 $ hg ci -qAm 'f is a symlink'
330 $ rm f
331 $ printf '../target-content' > f
332 $ hg ci -qm 'f is a regular file, same content'
333
334 filenodes match, so only the flag differs:
335
336 $ hg manifest --debug -r 0 | grep ' f$'
337 3a8d93ba72f6d400da02a39d21ea4c45369f9829 644 @ f
338 $ hg manifest --debug -r 1 | grep ' f$'
339 3a8d93ba72f6d400da02a39d21ea4c45369f9829 644 f
340
341 symlink -> regular file:
342
343 $ hg update -C -r 0 -q
344 $ f --type f
345 f: link
346 $ hg update -r 1 -q
347 $ f --type f
348 f: file
349 $ cat f
350 ../target-content (no-eol)
351
352 $ advance_fs_time
353 $ hg status
354
355 regular file -> symlink:
356
357 $ hg up -C null --quiet
358 $ hg up -C 1 --quiet
359 $ hg update -r 0 -q
360 $ f --type f
361 f: link
362
363 $ advance_fs_time
364 $ hg status
365
366 $ cd ..