-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.js
1674 lines (1586 loc) · 60.2 KB
/
test.js
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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const path = require('path')
const fs = require('fs')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const writeFileAtomic = require('write-file-atomic')
async function run (command, expectStdoutLines = null) {
const { stdout, stderr } = await exec(command)
console.log('RUN:', command)
console.log(stdout)
if (stderr) console.error('ERROR:', stderr)
expect(stderr).toBe('')
if (expectStdoutLines) {
expect(stdout.split('\n').map(x => x.trim()).filter(x => !!x)).toEqual(expectStdoutLines)
}
return { stdout, stderr }
}
async function addGitRepoCommit (folder, repoPath, data, timeIndex, message, { chmod = null, mode = 'file' } = {}) {
const to60num = (x) => `${('' + (x % 60 - x % 10)).substring(0, 1)}${x % 10}`
await exec(`mkdir -p ${path.dirname(path.join(folder, repoPath))}`)
if (mode === 'file') {
await writeFileAtomic(path.join(folder, repoPath), data)
} else if (mode === 'link') {
await exec(`ln -s ${data} ${path.join(folder, repoPath)}`)
} else {
throw new Error('addGitRepoCommit(): unknown file mode')
}
if (chmod) await exec(`chmod ${chmod} ${path.join(folder, repoPath)}`)
await exec(`git -C ${folder} add ${repoPath}`)
const commiterDate = `2010-01-01T22:${to60num(timeIndex)}:00Z`
const commiterName = `Name2`
const commiterEmail = `[email protected]`
const authorDate = `2005-${to60num(timeIndex + 4)}-07T${(timeIndex === 0) ? 22 : 23}:13:13Z`
const authorName = `User`
const authorEmail = `[email protected]`
await exec(`GIT_COMMITTER_DATE="${commiterDate}" git -C ${folder} -c user.name="${commiterName}" -c user.email=${commiterEmail} commit --author='${authorName} <${authorEmail}>' --date "${authorDate}" -am '${message}'`)
}
async function prepareGitRepo (folder) {
const filename = 'test.txt'
const renamedFilename = 'Test.txt'
const text1 = 'Initial text'
const text2 = 'Changed text'
await exec(`rm -rf ${folder}`)
await exec(`mkdir -p ${folder}`)
await exec(`git -C ${folder} init`)
await addGitRepoCommit(folder, filename, text1, 0, 'initial commit')
await addGitRepoCommit(folder, filename, text2, 1, 'change initial text')
await exec(`git -C ${folder} rm ${filename}`)
await addGitRepoCommit(folder, renamedFilename, text2, 2, 'rename file')
await addGitRepoCommit(folder, `${renamedFilename}.link`, renamedFilename, 3, 'create link', { mode: 'link' })
await addGitRepoCommit(folder, 'sTest.txt', text1, 4, 'another file')
await addGitRepoCommit(folder, path.join('bin', 'script.js'), '#!/usr/bin/env node\nconsole.log(911)\n', 5, 'add script!', { chmod: '+x' })
}
const DEFAULT_PREPARE_GIT_REPO_PATHS = [
'test.txt',
'Test.txt',
'Test.txt.link',
'sTest.txt',
'bin/script.js',
]
const DEFAULT_PREPARE_GIT_REPO_HISTORY = [
'commit 43a8998c57a1885fb9bb4ae8342b2e8a9285f002',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit a9384415955e78b0adfd00e5fb95b99eff97138c',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'diff --git a/sTest.txt b/sTest.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/sTest.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
'commit dded478c4d2bf21367a88d7e9bb2b6ea18eb3c50',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'diff --git a/Test.txt.link b/Test.txt.link',
'new file mode 120000',
'index 0000000..d7da186',
'--- /dev/null',
'+++ b/Test.txt.link',
'@@ -0,0 +1 @@',
'+Test.txt',
'\\ No newline at end of file',
'commit ee01df4e6cc73e4210e87c94b853a96103ca02c2',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'diff --git a/test.txt b/Test.txt',
'similarity index 100%',
'rename from test.txt',
'rename to Test.txt',
'commit d0dc86bea4f548db93905b71da1c6915594bfd5b',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'diff --git a/test.txt b/test.txt',
'index 6dbb898..41c4a21 100644',
'--- a/test.txt',
'+++ b/test.txt',
'@@ -1 +1 @@',
'-Initial text',
'\\ No newline at end of file',
'+Changed text',
'\\ No newline at end of file',
'commit c731fd997376f68806c5cbe100edc7000acb75db',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
'diff --git a/test.txt b/test.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/test.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
]
test('prepareGitRepo()', async () => {
const folder = 'ignore.prepare-git-repo'
await prepareGitRepo(folder)
await run(`git -C ${folder} log --pretty='format:%H %aI "%an" <%ae> %cI "%cn" <%ce> %s'`, [
'43a8998c57a1885fb9bb4ae8342b2e8a9285f002 2005-09-07T23:13:13+00:00 "User" <[email protected]> 2010-01-01T22:05:00+00:00 "Name2" <[email protected]> add script!',
'a9384415955e78b0adfd00e5fb95b99eff97138c 2005-08-07T23:13:13+00:00 "User" <[email protected]> 2010-01-01T22:04:00+00:00 "Name2" <[email protected]> another file',
'dded478c4d2bf21367a88d7e9bb2b6ea18eb3c50 2005-07-07T23:13:13+00:00 "User" <[email protected]> 2010-01-01T22:03:00+00:00 "Name2" <[email protected]> create link',
'ee01df4e6cc73e4210e87c94b853a96103ca02c2 2005-06-07T23:13:13+00:00 "User" <[email protected]> 2010-01-01T22:02:00+00:00 "Name2" <[email protected]> rename file',
'd0dc86bea4f548db93905b71da1c6915594bfd5b 2005-05-07T23:13:13+00:00 "User" <[email protected]> 2010-01-01T22:01:00+00:00 "Name2" <[email protected]> change initial text',
'c731fd997376f68806c5cbe100edc7000acb75db 2005-04-07T22:13:13+00:00 "User" <[email protected]> 2010-01-01T22:00:00+00:00 "Name2" <[email protected]> initial commit',
])
await run(`git -C ${folder} log -p`, DEFAULT_PREPARE_GIT_REPO_HISTORY)
})
function expectLogPath (path, paths, ignoredPaths, allowedPaths, skippedPaths) {
const logs = JSON.parse(fs.readFileSync(path, { encoding: 'utf-8' }))
expect(logs.paths).toEqual(paths)
expect(logs.ignoredPaths).toEqual(ignoredPaths)
expect(logs.allowedPaths).toEqual(allowedPaths)
expect(logs.skippedPaths).toEqual(skippedPaths)
}
test('gitexporter save git history', async () => {
const folder = 'ignore.save-history'
const config = `{
"forceReCreateRepo": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}"
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[],
[
'test.txt',
'Test.txt',
'Test.txt.link',
'sTest.txt',
'bin/script.js',
],
[],
)
await run(`git -C ${folder}-target log -p`, DEFAULT_PREPARE_GIT_REPO_HISTORY)
})
test('gitexporter allowed paths', async () => {
const folder = 'ignore.allowed-paths'
const config = `{
"forceReCreateRepo": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"allowedPaths": ["test.txt"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
await run(`ls -a ${folder}-target`, ['.', '..', '.git', 'Test.txt'])
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[],
[
'test.txt',
'Test.txt',
],
[
'Test.txt.link',
'sTest.txt',
'bin/script.js',
],
)
// NOTE: probably may have some differences on register sensitive filepath filesystems?!
await run(`git -C ${folder}-target log -p`, [
'commit 867aa676ef2a4d5de5756a53dbff77d4a726e3e9',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'commit 427f8e83a1658852b8c6f4be99b4664976746aab',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'commit f44ba5da1dae5ced415f214f92ec0ba3e4d25a20',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit ee01df4e6cc73e4210e87c94b853a96103ca02c2',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'diff --git a/test.txt b/Test.txt',
'similarity index 100%',
'rename from test.txt',
'rename to Test.txt',
'commit d0dc86bea4f548db93905b71da1c6915594bfd5b',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'diff --git a/test.txt b/test.txt',
'index 6dbb898..41c4a21 100644',
'--- a/test.txt',
'+++ b/test.txt',
'@@ -1 +1 @@',
'-Initial text',
'\\ No newline at end of file',
'+Changed text',
'\\ No newline at end of file',
'commit c731fd997376f68806c5cbe100edc7000acb75db',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
'diff --git a/test.txt b/test.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/test.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
])
})
test('gitexporter ignored paths', async () => {
const folder = 'ignore.ignored-paths'
const config = `{
"forceReCreateRepo": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["test.txt"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
await run(`ls -a ${folder}-target`, ['.', '..', '.git', 'Test.txt.link', 'bin', 'sTest.txt'])
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[
'test.txt',
'Test.txt',
],
DEFAULT_PREPARE_GIT_REPO_PATHS,
[],
)
await run(`git -C ${folder}-target log -p`, [
'commit 57662116ed2bfa91dadce6eff592866add37484a',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit b7278d18a44009568e418c3c133086ab222807d7',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'diff --git a/sTest.txt b/sTest.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/sTest.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
'commit 6b2f22e047180853f9927bffc8da3015f82fe568',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'diff --git a/Test.txt.link b/Test.txt.link',
'new file mode 120000',
'index 0000000..d7da186',
'--- /dev/null',
'+++ b/Test.txt.link',
'@@ -0,0 +1 @@',
'+Test.txt',
'\\ No newline at end of file',
'commit f995e7171c59eca6d1c664cfa4b074a117109cf5',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'commit 8e4da0cc03de0ae8f434a878a00eb9d600d3de56',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'commit 2ddd8f9d41399241dec8f4dce64e6365335baa1f',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
])
})
test('gitexporter ignored and allowed paths', async () => {
const folder = 'ignore.ignored-allowed-paths'
const config = `{
"forceReCreateRepo": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["*.txt"],
"allowedPaths": ["*.js"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
await run(`ls -a ${folder}-target`, ['.', '..', '.git', 'bin'])
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[
'test.txt',
'Test.txt',
'sTest.txt',
],
[
'bin/script.js',
],
[
'Test.txt.link',
],
)
await run(`git -C ${folder}-target log -p`, [
'commit 7917736a48e49c96b1cdc50847f80885df814300',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit dd10c6696fe79dc6c0f403d612206a6dd41f45d3',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'commit d6f6abe8b06b56013246276299a9671213671ee0',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit f995e7171c59eca6d1c664cfa4b074a117109cf5',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'commit 8e4da0cc03de0ae8f434a878a00eb9d600d3de56',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'commit 2ddd8f9d41399241dec8f4dce64e6365335baa1f',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
])
})
function expectStdout (data, contains = null, notContains = null) {
expect(data).toHaveProperty('stdout')
if (contains && contains.length) {
for (const c of contains) {
expect(data.stdout).toContain(c)
}
}
if (notContains && notContains.length) {
for (const c of notContains) {
expect(data.stdout).not.toContain(c)
}
}
}
test('gitexporter follow by logfile', async () => {
const folder = 'ignore.follow-by-logfile'
const config = `{
"forceReCreateRepo": false,
"followByLogFile": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["sTest.txt", "*.link"],
"allowedPaths": ["*"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Checkout: 46c01f27346ad1e77ffcc81e38b914ea17ae0395'],
['Follow target repo state', 'Follow log stopped'],
)
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[
'Test.txt.link',
'sTest.txt',
],
DEFAULT_PREPARE_GIT_REPO_PATHS,
[],
)
await addGitRepoCommit(folder, 'some-file.txt', 'hollo world!', 6, 'add hollo')
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 6 commits', 'Follow log stopped! last commit 7/7 46c01f27346ad1e77ffcc81e38b914ea17ae0395', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
)
expectLogPath(
`${folder}-target.log.json`,
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[
'Test.txt.link',
'sTest.txt',
],
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
)
expectLogPath(
`${folder}-target.log.json`,
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[
'Test.txt.link',
'sTest.txt',
],
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[],
)
await run(`git -C ${folder}-target log -p`, [
'commit 95655d5bd61e5d8c71acde522f28c0d46fb17330',
'Author: User <[email protected]>',
'Date: Fri Oct 7 23:13:13 2005 +0000',
'add hollo',
'diff --git a/some-file.txt b/some-file.txt',
'new file mode 100644',
'index 0000000..ff0d2a6',
'--- /dev/null',
'+++ b/some-file.txt',
'@@ -0,0 +1 @@',
'+hollo world!',
'\\ No newline at end of file',
'commit 46c01f27346ad1e77ffcc81e38b914ea17ae0395',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit 427f8e83a1658852b8c6f4be99b4664976746aab',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'commit f44ba5da1dae5ced415f214f92ec0ba3e4d25a20',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit ee01df4e6cc73e4210e87c94b853a96103ca02c2',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'diff --git a/test.txt b/Test.txt',
'similarity index 100%',
'rename from test.txt',
'rename to Test.txt',
'commit d0dc86bea4f548db93905b71da1c6915594bfd5b',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'diff --git a/test.txt b/test.txt',
'index 6dbb898..41c4a21 100644',
'--- a/test.txt',
'+++ b/test.txt',
'@@ -1 +1 @@',
'-Initial text',
'\\ No newline at end of file',
'+Changed text',
'\\ No newline at end of file',
'commit c731fd997376f68806c5cbe100edc7000acb75db',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
'diff --git a/test.txt b/test.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/test.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
])
})
test('gitexporter follow by number of commits', async () => {
const folder = 'ignore.follow-by-number-of-commits'
const config = `{
"forceReCreateRepo": false,
"followByLogFile": false,
"followByNumberOfCommits": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["sTest.txt", "*.link"],
"allowedPaths": ["*"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Checkout: 46c01f27346ad1e77ffcc81e38b914ea17ae0395'],
['WARN', 'Follow target repo state', 'Follow log stopped'],
)
expectLogPath(
`${folder}-target.log.json`,
DEFAULT_PREPARE_GIT_REPO_PATHS,
[
'Test.txt.link',
'sTest.txt',
],
DEFAULT_PREPARE_GIT_REPO_PATHS,
[],
)
await addGitRepoCommit(folder, 'some-file.txt', 'hollo world!', 6, 'add hollo')
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by number of commits: 6 commits', 'Follow log stopped! last commit 7/7 46c01f27346ad1e77ffcc81e38b914ea17ae0395', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
['WARN'],
)
expectLogPath(
`${folder}-target.log.json`,
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[
'Test.txt.link',
'sTest.txt',
],
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by number of commits: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
['WARN'],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by number of commits: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
['WARN'],
)
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by number of commits: 7 commits', 'Follow log stopped! last commit 7 95655d5bd61e5d8c71acde522f28c0d46fb17330', 'Checkout: 95655d5bd61e5d8c71acde522f28c0d46fb17330'],
['WARN'],
)
expectLogPath(
`${folder}-target.log.json`,
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[
'Test.txt.link',
'sTest.txt',
],
[...DEFAULT_PREPARE_GIT_REPO_PATHS, ...['some-file.txt']],
[],
)
await run(`git -C ${folder}-target log -p`, [
'commit 95655d5bd61e5d8c71acde522f28c0d46fb17330',
'Author: User <[email protected]>',
'Date: Fri Oct 7 23:13:13 2005 +0000',
'add hollo',
'diff --git a/some-file.txt b/some-file.txt',
'new file mode 100644',
'index 0000000..ff0d2a6',
'--- /dev/null',
'+++ b/some-file.txt',
'@@ -0,0 +1 @@',
'+hollo world!',
'\\ No newline at end of file',
'commit 46c01f27346ad1e77ffcc81e38b914ea17ae0395',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit 427f8e83a1658852b8c6f4be99b4664976746aab',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'commit f44ba5da1dae5ced415f214f92ec0ba3e4d25a20',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit ee01df4e6cc73e4210e87c94b853a96103ca02c2',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'diff --git a/test.txt b/Test.txt',
'similarity index 100%',
'rename from test.txt',
'rename to Test.txt',
'commit d0dc86bea4f548db93905b71da1c6915594bfd5b',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'diff --git a/test.txt b/test.txt',
'index 6dbb898..41c4a21 100644',
'--- a/test.txt',
'+++ b/test.txt',
'@@ -1 +1 @@',
'-Initial text',
'\\ No newline at end of file',
'+Changed text',
'\\ No newline at end of file',
'commit c731fd997376f68806c5cbe100edc7000acb75db',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
'diff --git a/test.txt b/test.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/test.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
])
})
test('gitexporter commitTransformer', async () => {
const folder = 'ignore.commit-transformer'
const config = `{
"forceReCreateRepo": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"commitTransformer": "./${folder}.transformer.js",
"allowedPaths": ["*"]
}`
const transformer = `
module.exports = function (commit, files) {
commit.message = 'XXX: ' + commit.message
}
`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config)
await writeFileAtomic(`${folder}.transformer.js`, transformer)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
await run(`git -C ${folder}-target log -p`, [
'commit a5eb28f672bd8c801088c16da026d3cef8c2c5dd',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'XXX: add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit b5d8d9a675509efabd89348aceef6cffff809a75',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'XXX: another file',
'diff --git a/sTest.txt b/sTest.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/sTest.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
'commit 737d203709702b8b1670beb3e001a7511db3089c',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'XXX: create link',
'diff --git a/Test.txt.link b/Test.txt.link',
'new file mode 120000',
'index 0000000..d7da186',
'--- /dev/null',
'+++ b/Test.txt.link',
'@@ -0,0 +1 @@',
'+Test.txt',
'\\ No newline at end of file',
'commit 5be2808ce613d73bbcc570931dbb9b71b36c13fa',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'XXX: rename file',
'diff --git a/test.txt b/Test.txt',
'similarity index 100%',
'rename from test.txt',
'rename to Test.txt',
'commit bcc480d7ff93cbfab7808289bce89e8c442f801d',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'XXX: change initial text',
'diff --git a/test.txt b/test.txt',
'index 6dbb898..41c4a21 100644',
'--- a/test.txt',
'+++ b/test.txt',
'@@ -1 +1 @@',
'-Initial text',
'\\ No newline at end of file',
'+Changed text',
'\\ No newline at end of file',
'commit 918eea168bf7ea3d29c71ea841e4c2e64ee9e35f',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'XXX: initial commit',
'diff --git a/test.txt b/test.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/test.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
])
})
test('gitexporter followByLogFile syncAllFilesOnLastFollowCommit: true', async () => {
const folder = 'ignore.sync-tree-by-log-true'
const config1 = `{
"forceReCreateRepo": false,
"syncAllFilesOnLastFollowCommit": true,
"followByLogFile": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["test.txt", "*.link"],
"allowedPaths": ["*"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config1)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
const config2 = `{
"forceReCreateRepo": false,
"syncAllFilesOnLastFollowCommit": true,
"followByLogFile": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"allowedPaths": ["*"]
}`
await writeFileAtomic(`${folder}.config.json`, config2)
await addGitRepoCommit(folder, 'some-file.txt', 'hollo world!', 6, 'add hollo')
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 6 commits', 'Follow log stopped! last commit 7/7 449f22bdf5add1e83d1a30d50afa924c23cbe5ac'],
)
await run(`git -C ${folder}-target log -p`, [
'commit 61d9922a45251600a04ed4d5f082610f21cdd107',
'Author: User <[email protected]>',
'Date: Fri Oct 7 23:13:13 2005 +0000',
'add hollo',
'diff --git a/Test.txt b/Test.txt',
'new file mode 100644',
'index 0000000..41c4a21',
'--- /dev/null',
'+++ b/Test.txt',
'@@ -0,0 +1 @@',
'+Changed text',
'\\ No newline at end of file',
'diff --git a/some-file.txt b/some-file.txt',
'new file mode 100644',
'index 0000000..ff0d2a6',
'--- /dev/null',
'+++ b/some-file.txt',
'@@ -0,0 +1 @@',
'+hollo world!',
'\\ No newline at end of file',
'commit 449f22bdf5add1e83d1a30d50afa924c23cbe5ac',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit 3abcc91755c2232f1a481ad330a419d7820f8a0c',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'diff --git a/sTest.txt b/sTest.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/sTest.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
'commit d6f6abe8b06b56013246276299a9671213671ee0',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit f995e7171c59eca6d1c664cfa4b074a117109cf5',
'Author: User <[email protected]>',
'Date: Tue Jun 7 23:13:13 2005 +0000',
'rename file',
'commit 8e4da0cc03de0ae8f434a878a00eb9d600d3de56',
'Author: User <[email protected]>',
'Date: Sat May 7 23:13:13 2005 +0000',
'change initial text',
'commit 2ddd8f9d41399241dec8f4dce64e6365335baa1f',
'Author: User <[email protected]>',
'Date: Thu Apr 7 22:13:13 2005 +0000',
'initial commit',
])
})
test('gitexporter followByLogFile syncAllFilesOnLastFollowCommit: true; delete on config changes!', async () => {
const folder = 'ignore.sync-tree-by-log-true-delete'
const config1 = `{
"forceReCreateRepo": false,
"syncAllFilesOnLastFollowCommit": true,
"followByLogFile": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["test.txt", "*.link"],
"allowedPaths": ["*"]
}`
await run(`rm -rf ${folder}*`)
await prepareGitRepo(`${folder}`)
await writeFileAtomic(`${folder}.config.json`, config1)
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`)
const config2 = `{
"forceReCreateRepo": false,
"syncAllFilesOnLastFollowCommit": true,
"followByLogFile": true,
"targetRepoPath": "${folder}-target",
"sourceRepoPath": "${folder}",
"ignoredPaths": ["sTest.txt"],
"allowedPaths": ["*"]
}`
await writeFileAtomic(`${folder}.config.json`, config2)
await addGitRepoCommit(folder, 'some-file.txt', 'hollo world!', 6, 'add hollo')
expectStdout(
await run(`node --unhandled-rejections=strict index.js ${folder}.config.json`),
['Finish', 'Follow target repo state by log file: 6 commits', 'Follow log stopped! last commit 7/7 449f22bdf5add1e83d1a30d50afa924c23cbe5ac'],
['Follow target repo state by number of commits'],
)
await run(`git -C ${folder}-target log -p`, [
'commit 0b827da4fd071f60c65ed3df318f793865a4be9d',
'Author: User <[email protected]>',
'Date: Fri Oct 7 23:13:13 2005 +0000',
'add hollo',
'diff --git a/Test.txt b/Test.txt',
'new file mode 100644',
'index 0000000..41c4a21',
'--- /dev/null',
'+++ b/Test.txt',
'@@ -0,0 +1 @@',
'+Changed text',
'\\ No newline at end of file',
'diff --git a/sTest.txt b/sTest.txt',
'deleted file mode 100644',
'index 6dbb898..0000000',
'--- a/sTest.txt',
'+++ /dev/null',
'@@ -1 +0,0 @@',
'-Initial text',
'\\ No newline at end of file',
'diff --git a/some-file.txt b/some-file.txt',
'new file mode 100644',
'index 0000000..ff0d2a6',
'--- /dev/null',
'+++ b/some-file.txt',
'@@ -0,0 +1 @@',
'+hollo world!',
'\\ No newline at end of file',
'commit 449f22bdf5add1e83d1a30d50afa924c23cbe5ac',
'Author: User <[email protected]>',
'Date: Wed Sep 7 23:13:13 2005 +0000',
'add script!',
'diff --git a/bin/script.js b/bin/script.js',
'new file mode 100755',
'index 0000000..ca29b27',
'--- /dev/null',
'+++ b/bin/script.js',
'@@ -0,0 +1,2 @@',
'+#!/usr/bin/env node',
'+console.log(911)',
'commit 3abcc91755c2232f1a481ad330a419d7820f8a0c',
'Author: User <[email protected]>',
'Date: Sun Aug 7 23:13:13 2005 +0000',
'another file',
'diff --git a/sTest.txt b/sTest.txt',
'new file mode 100644',
'index 0000000..6dbb898',
'--- /dev/null',
'+++ b/sTest.txt',
'@@ -0,0 +1 @@',
'+Initial text',
'\\ No newline at end of file',
'commit d6f6abe8b06b56013246276299a9671213671ee0',
'Author: User <[email protected]>',
'Date: Thu Jul 7 23:13:13 2005 +0000',
'create link',
'commit f995e7171c59eca6d1c664cfa4b074a117109cf5',