hg-i18n-cs / tests / test-import

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
#!/bin/sh

hg init a
mkdir a/d1
mkdir a/d1/d2
echo line 1 > a/a
echo line 1 > a/d1/d2/a
hg --cwd a ci -Ama

echo line 2 >> a/a
hg --cwd a ci -u someone -d '1 0' -m'second change'

echo % import exported patch
hg clone -r0 a b
hg --cwd a export tip > tip.patch
hg --cwd b import ../tip.patch
echo % message should be same
hg --cwd b tip | grep 'second change'
echo % committer should be same
hg --cwd b tip | grep someone
rm -r b

echo % import exported patch with external patcher
cat > dummypatch.py <<EOF
print 'patching file a'
file('a', 'wb').write('line2\n')
EOF
chmod +x dummypatch.py
hg clone -r0 a b
hg --cwd a export tip > tip.patch
hg --config ui.patch='python ../dummypatch.py' --cwd b import ../tip.patch
cat b/a
rm -r b

echo % import of plain diff should fail without message
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import ../tip.patch
rm -r b

echo % import of plain diff should be ok with message
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import -mpatch ../tip.patch
rm -r b

echo % import of plain diff with specific date and user
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import -mpatch -d '1 0' -u 'user@nowhere.net' ../tip.patch
hg -R b tip -pv
rm -r b

echo % import of plain diff should be ok with --no-commit
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
hg --cwd b import --no-commit ../tip.patch
hg --cwd b diff --nodates
rm -r b

echo % hg -R repo import
# put the clone in a subdir - having a directory named "a"
# used to hide a bug.
mkdir dir
hg clone -r0 a dir/b
hg --cwd a export tip > dir/tip.patch
cd dir
hg -R b import tip.patch
cd ..
rm -r dir

echo % import from stdin
hg clone -r0 a b
hg --cwd a export tip | hg --cwd b import -
rm -r b

echo % import two patches in one stream
hg init b
hg --cwd a export 0:tip | hg --cwd b import -
hg --cwd a id
hg --cwd b id
rm -r b

echo % override commit message
hg clone -r0 a b
hg --cwd a export tip | hg --cwd b import -m 'override' -
hg --cwd b tip | grep override
rm -r b

cat > mkmsg.py <<EOF
import email.Message, sys
msg = email.Message.Message()
msg.set_payload('email commit message\n' + open('tip.patch', 'rb').read())
msg['Subject'] = 'email patch'
msg['From'] = 'email patcher'
sys.stdout.write(msg.as_string())
EOF

echo % plain diff in email, subject, message body
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
python mkmsg.py > msg.patch
hg --cwd b import ../msg.patch
hg --cwd b tip | grep email
rm -r b

echo % plain diff in email, no subject, message body
hg clone -r0 a b
grep -v '^Subject:' msg.patch | hg --cwd b import -
rm -r b

echo % plain diff in email, subject, no message body
hg clone -r0 a b
grep -v '^email ' msg.patch | hg --cwd b import -
rm -r b

echo % plain diff in email, no subject, no message body, should fail
hg clone -r0 a b
egrep -v '^(Subject|email)' msg.patch | hg --cwd b import -
rm -r b

echo % hg export in email, should use patch header
hg clone -r0 a b
hg --cwd a export tip > tip.patch
python mkmsg.py | hg --cwd b import -
hg --cwd b tip | grep second
rm -r b

# subject: duplicate detection, removal of [PATCH]
# The '---' tests the gitsendmail handling without proper mail headers
cat > mkmsg2.py <<EOF
import email.Message, sys
msg = email.Message.Message()
msg.set_payload('email patch\n\nnext line\n---\n' + open('tip.patch').read())
msg['Subject'] = '[PATCH] email patch'
msg['From'] = 'email patcher'
sys.stdout.write(msg.as_string())
EOF

echo '% plain diff in email, [PATCH] subject, message body with subject'
hg clone -r0 a b
hg --cwd a diff -r0:1 > tip.patch
python mkmsg2.py | hg --cwd b import -
hg --cwd b tip --template '{desc}\n'
rm -r b

# We weren't backing up the correct dirstate file when importing many patches
# (issue963)
echo '% import patch1 patch2; rollback'
echo line 3 >> a/a
hg --cwd a ci -m'third change'
hg --cwd a export -o '../patch%R' 1 2
hg clone -qr0 a b
hg --cwd b parents --template 'parent: {rev}\n'
hg --cwd b import ../patch1 ../patch2
hg --cwd b rollback
hg --cwd b parents --template 'parent: {rev}\n'
rm -r b

# bug non regression test
# importing a patch in a subdirectory failed at the commit stage
echo line 2 >> a/d1/d2/a
hg --cwd a ci -u someoneelse -d '1 0' -m'subdir change'
echo % hg import in a subdirectory
hg clone -r0 a b
hg --cwd a export tip | sed -e 's/d1\/d2\///' > tip.patch
dir=`pwd`
cd b/d1/d2 2>&1 > /dev/null
hg import  ../../../tip.patch
cd "$dir"
echo "% message should be 'subdir change'"
hg --cwd b tip | grep 'subdir change'
echo "% committer should be 'someoneelse'"
hg --cwd b tip | grep someoneelse
echo "% should be empty"
hg --cwd b status


# Test fuzziness (ambiguous patch location, fuzz=2)
echo % test fuzziness
hg init fuzzy
cd fuzzy
echo line1 > a
echo line0 >> a
echo line3 >> a
hg ci -Am adda
echo line1 > a
echo line2 >> a
echo line0 >> a
echo line3 >> a
hg ci -m change a
hg export tip > tip.patch
hg up -C 0
echo line1 > a
echo line0 >> a
echo line1 >> a
echo line0 >> a
hg ci -m brancha
hg import --no-commit -v tip.patch
hg revert -a
echo '% test fuzziness with eol=auto'
hg --config patch.eol=auto import --no-commit -v tip.patch
cd ..

# Test hunk touching empty files (issue906)
hg init empty
cd empty
touch a
touch b1
touch c1
echo d > d
hg ci -Am init
echo a > a
echo b > b1
hg mv b1 b2
echo c > c1
hg copy c1 c2
rm d
touch d
hg diff --git
hg ci -m empty
hg export --git tip > empty.diff
hg up -C 0
hg import empty.diff
for name in a b1 b2 c1 c2 d;
do
    echo % $name file
    test -f $name && cat $name
done
cd ..

# Test importing a patch ending with a binary file removal
echo % test trailing binary removal
hg init binaryremoval
cd binaryremoval
echo a > a
python -c "file('b', 'wb').write('a\x00b')"
hg ci -Am addall
hg rm a
hg rm b
hg st
hg ci -m remove
hg export --git . > remove.diff
cat remove.diff | grep git
hg up -C 0
hg import remove.diff
hg manifest
cd ..

echo % 'test update+rename with common name (issue 927)'
hg init t
cd t
touch a
hg ci -Am t
echo a > a
# Here, bfile.startswith(afile)
hg copy a a2
hg ci -m copya
hg export --git tip > copy.diff
hg up -C 0
hg import copy.diff
echo % view a
# a should contain an 'a'
cat a
echo % view a2
# and a2 should have duplicated it
cat a2
cd ..

echo % 'test -p0'
hg init p0
cd p0
echo a > a
hg ci -Am t
hg import -p0 - << EOF
foobar
--- a	Sat Apr 12 22:43:58 2008 -0400
+++ a	Sat Apr 12 22:44:05 2008 -0400
@@ -1,1 +1,1 @@
-a
+bb
EOF
hg status
cat a
cd ..

echo % 'test paths outside repo root'
mkdir outside
touch outside/foo
hg init inside
cd inside
hg import - <<EOF
diff --git a/a b/b
rename from ../outside/foo
rename to bar
EOF
cd ..

echo '% test import with similarity (issue295)'
hg init sim
cd sim
echo 'this is a test' > a
hg ci -Ama
cat > ../rename.diff <<EOF
diff --git a/a b/a
deleted file mode 100644
--- a/a
+++ /dev/null
@@ -1,1 +0,0 @@
-this is a test
diff --git a/b b/b
new file mode 100644
--- /dev/null
+++ b/b
@@ -0,0 +1,2 @@
+this is a test
+foo
EOF
hg import --no-commit -v -s 1 ../rename.diff
hg st -C
hg revert -a
rm b
hg import --no-commit -v -s 100 ../rename.diff
hg st -C
cd ..


echo '% add empty file from the end of patch (issue 1495)'
hg init addemptyend
cd addemptyend
touch a
hg addremove
hg ci -m "commit"
cat > a.patch <<EOF
diff --git a/a b/a
--- a/a
+++ b/a
@@ -0,0 +1,1 @@
+a
diff --git a/b b/b
new file mode 100644
EOF
hg import --no-commit a.patch
cd ..

echo '% create file when source is not /dev/null'
cat > create.patch <<EOF
diff -Naur proj-orig/foo proj-new/foo
--- proj-orig/foo       1969-12-31 16:00:00.000000000 -0800
+++ proj-new/foo        2009-07-17 16:50:45.801368000 -0700
@@ -0,0 +1,1 @@
+a
EOF
# some people have patches like the following too
cat > create2.patch <<EOF
diff -Naur proj-orig/foo proj-new/foo
--- proj-orig/foo.orig  1969-12-31 16:00:00.000000000 -0800
+++ proj-new/foo        2009-07-17 16:50:45.801368000 -0700
@@ -0,0 +1,1 @@
+a
EOF
hg init oddcreate
cd oddcreate
hg import --no-commit ../create.patch
cat foo
rm foo
hg revert foo
hg import --no-commit ../create2.patch
cat foo

echo % 'first line mistaken for email headers (issue 1859)'
hg init emailconfusion
cd emailconfusion
cat > a.patch <<EOF
module: summary

description


diff -r 000000000000 -r 9b4c1e343b55 test.txt
--- /dev/null
+++ b/a
@@ -0,0 +1,1 @@
+a
EOF
hg import -d '0 0' a.patch
hg parents -v
cd ..

echo % '--- in commit message'
hg init commitconfusion
cd commitconfusion
cat > a.patch <<EOF
module: summary

--- description

diff --git a/a b/a
new file mode 100644
--- /dev/null
+++ b/a
@@ -0,0 +1,1 @@
+a
EOF
hg import -d '0 0' a.patch
hg parents -v
cd ..

echo '% tricky header splitting'
cat > trickyheaders.patch <<EOF
From: User A <user@a>
Subject: [PATCH] from: tricky!

# HG changeset patch
# User User B
# Date 1266264441 18000
# Branch stable
# Node ID f2be6a1170ac83bf31cb4ae0bad00d7678115bc0
# Parent  0000000000000000000000000000000000000000
from: tricky!

That is not a header.

diff -r 000000000000 -r f2be6a1170ac foo
--- /dev/null
+++ b/foo
@@ -0,0 +1,1 @@
+foo
EOF

hg init trickyheaders
cd trickyheaders
hg import -d '0 0' ../trickyheaders.patch
hg export --git tip
cd ..

echo '% issue2102'
hg init issue2102
cd issue2102
mkdir -p src/cmd/gc
touch src/cmd/gc/mksys.bash
hg ci -Am init
hg import - <<EOF
# HG changeset patch
# User Rob Pike
# Date 1216685449 25200
# Node ID 03aa2b206f499ad6eb50e6e207b9e710d6409c98
# Parent  93d10138ad8df586827ca90b4ddb5033e21a3a84
help management of empty pkg and lib directories in perforce

R=gri
DELTA=4  (4 added, 0 deleted, 0 changed)
OCL=13328
CL=13328

diff --git a/lib/place-holder b/lib/place-holder
new file mode 100644
--- /dev/null
+++ b/lib/place-holder
@@ -0,0 +1,2 @@
+perforce does not maintain empty directories.
+this file helps.
diff --git a/pkg/place-holder b/pkg/place-holder
new file mode 100644
--- /dev/null
+++ b/pkg/place-holder
@@ -0,0 +1,2 @@
+perforce does not maintain empty directories.
+this file helps.
diff --git a/src/cmd/gc/mksys.bash b/src/cmd/gc/mksys.bash
old mode 100644
new mode 100755
EOF
hg sum
hg diff --git -c tip
cd ..
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.