1#!/usr/bin/perl -w
2use strict;
3use Test::More;
4use SVK::Test;
5plan tests => 29;
6our ($output, $answer);
7# build another tree to be mirrored ourself
8my ($xd, $svk) = build_test('test');
9
10my $tree = create_basic_tree ($xd, '/test/');
11
12my ($copath, $corpath) = get_copath ('svm');
13
14my ($srepospath, $spath, $srepos) =$xd->find_repos ('/test/A', 1);
15my $suuid = $srepos->fs->get_uuid;
16
17$svk->copy ('-m', 'just make some more revisions', '/test/A', "/test/A-$_") for (1..20);
18
19my $uri = uri($srepospath);
20is_output ($svk, 'mirror', ['//m', $uri.($spath eq '/' ? '' : $spath)],
21	   ['Mirror initialized.  Run svk sync //m to start mirroring.']);
22
23is_output ($svk, 'mirror', [$uri.($spath eq '/' ? '' : $spath), '//m'],
24	   ['/m already exists.']);
25
26is_output_like ($svk, 'mirror', [], qr'SYNOPSIS', 'add - help');
27
28is_output ($svk, 'mirror', ['--upgrade'],
29	   ['nothing to upgrade']);
30is_output ($svk, 'mirror', ['--upgrade', '//m'],
31	   ['nothing to upgrade']);
32
33is_output ($svk, 'sync', ['//'],
34	   ['// is not a mirrored path.']);
35is_output ($svk, 'sync', ['//what'],
36	   ['//what is not a mirrored path.']);
37
38is_output ($svk, 'sync', ['/what/'],
39	   ["No such depot: what."]);
40$svk->sync (-a => '/what/',
41	    ["No such depot: what."]);
42
43$svk->sync ('//m');
44$svk->copy ('-m', 'branch', '//m', '//l');
45$svk->checkout ('//l', $copath);
46ok (-e "$corpath/be");
47append_file ("$copath/be", "from local branch of svm'ed directory\n");
48mkdir "$copath/T/";
49append_file ("$copath/T/xd", "local new file\n");
50
51$svk->add ("$copath/T");
52$svk->delete ("$copath/Q/qu");
53
54$svk->commit ('-m', 'local modification from branch', "$copath");
55$svk->merge (qw/-C -r 4:5/, '-m', 'merge back to remote', '//l', '//m');
56$svk->merge (qw/-r 4:5/, '-m', 'merge back to remote', '//l', '//m');
57$svk->sync ('//m');
58
59#$svk->merge (qw/-r 5:6/, '//m', $copath);
60$svk->switch ('//m', $copath);
61$svk->update ($copath);
62
63append_file ("$copath/T/xd", "back to mirror directly\n");
64overwrite_file ("$copath/T/foo", "back to mirror directly\n");
65$svk->add ("$copath/T/foo");
66$svk->status ($copath);
67
68is_output ($svk, 'commit', ['-m', 'commit to mirrored path', $copath],
69        ['Commit into mirrored path: merging back directly.',
70        "Merging back to mirror source $uri/A.",
71        'Merge back committed as revision 24.',
72        "Syncing $uri/A",
73        'Retrieving log information from 24 to 24',
74        'Committed revision 7 from revision 24.']);
75mkdir ("$copath/N");
76$svk->add ("$copath/N");
77is_output ($svk, 'commit', ['-m', 'commit to deep mirrored path', $copath],
78        ['Commit into mirrored path: merging back directly.',
79        "Merging back to mirror source $uri/A.",
80        'Merge back committed as revision 25.',
81        "Syncing $uri/A",
82        'Retrieving log information from 25 to 25',
83        'Committed revision 8 from revision 25.']);
84append_file ("$copath/T/xd", "back to mirror directly again\n");
85$svk->commit ('-m', 'commit to deep mirrored path', "$copath/T/xd");
86ok(1);
87
88$svk->copy ('-m', 'branch in source', '/test/A', '/test/A-98');
89$svk->copy ('-m', 'branch in source', '/test/A-98', '/test/A-99');
90
91$svk->mirror ('//m-99', "$uri/A-99");
92$svk->copy ('-m', 'make a copy', '//m-99', '//m-99-intermediate');
93$svk->move ('-m', 'move the copy', '//m-99-intermediate', '//m-99-copy');
94
95my ($copath2, $corpath2) = get_copath ('svm2');
96$svk->checkout ('//m-99-copy', $copath2);
97is_output($svk, 'update', ['--sync', '--merge', $copath2], [
98        "Syncing $uri/A-99",
99        'Retrieving log information from 1 to 28',
100        'Committed revision 13 from revision 28.',
101        'Auto-merging (0, 13) /m-99 to /m-99-copy (base /:0).',
102        'A   Q',
103        'A   Q/qz',
104        'A   T',
105        'A   T/foo',
106        'A   T/xd',
107        'A   be',
108        'A   N',
109        "New merge ticket: $suuid:/A-99:28",
110        'Committed revision 14.',
111        "Syncing //m-99-copy(/m-99-copy) in $corpath2 to 14.",
112        __('A   t/checkout/svm2/Q'),
113        __('A   t/checkout/svm2/Q/qz'),
114        __('A   t/checkout/svm2/T'),
115        __('A   t/checkout/svm2/T/foo'),
116        __('A   t/checkout/svm2/T/xd'),
117        __('A   t/checkout/svm2/be'),
118        __('A   t/checkout/svm2/N'), ]);
119
120is_output($svk, 'smerge', ['-m', '', '--from', $copath2], [
121        "Auto-merging (0, 14) /m-99-copy to /m-99 (base /m-99:13).",
122        "Merging back to mirror source $uri/A-99.",
123        "Empty merge.",
124        ]);
125
126my ($copath3, $corpath3) = get_copath ('svm3');
127$svk->checkout ('//m-99', $copath3);
128append_file ("$copath3/T/xd", "modify something\n");
129$svk->commit ('-m', 'local modification from mirrored path', "$copath3");
130append_file ("$copath3/T/xd", "modify something again\n");
131$svk->commit ('-m', 'local modification from mirrored path', "$copath3");
132
133is_output($svk, 'update', ['--sync', '--merge', '--incremental', "$copath2/T"], [
134        "Syncing $uri/A-99",
135        'Auto-merging (13, 16) /m-99 to /m-99-copy (base /m-99:13).',
136        '===> Auto-merging (13, 15) /m-99 to /m-99-copy (base /m-99:13).',
137        'U   T/xd',
138        "New merge ticket: $suuid:/A-99:29",
139        'Committed revision 17.',
140        '===> Auto-merging (15, 16) /m-99 to /m-99-copy (base /m-99:15).',
141        'U   T/xd',
142        "New merge ticket: $suuid:/A-99:30",
143        'Committed revision 18.',
144        "Syncing //m-99-copy/T(/m-99-copy/T) in ".__("$corpath2/T to 18."),
145        __("U   $copath2/T/xd"),
146        ]);
147
148
149is_output_like ($svk, 'mirror', ['--list'],
150            qr"//m.*\Q$uri\E/A\n//m-99.*\Q$uri\E/A-99");
151
152is_output_like ($svk, 'mirror', ['//m-99', "$uri/A-99"],
153            qr"already", 'repeated mirror failed');
154
155is_output_like ($svk, 'mirror', ['--detach', '//l'],
156            qr"not a mirrored", '--detach on non-mirrored path');
157
158is_output_like ($svk, 'mirror', ['--detach', '//m/T'],
159            qr"inside", '--detach inside a mirrored path');
160
161is_output ($svk, 'mirror', ['--detach', '//m'], [
162            "Mirror path '//m' detached.",
163            ], '--detach on mirrored path');
164
165is_output_like ($svk, 'mirror', ['--detach', '//m'],
166            qr"not a mirrored", '--detach on non-mirrored path');
167
168is_output ($svk, 'mirror', ['//m', $uri.($spath eq '/' ? '' : $spath)],
169	   ['/m already exists.']);
170
171$svk->copy ('-m', 'make a copy', '//m-99-copy', '//m-99-copy-twice');
172
173my ($copath4, $corpath4) = get_copath ('svm4');
174$svk->checkout ('//m-99-copy-twice', $copath4);
175is_output($svk, 'update', ['--sync', '--merge', $copath4], [
176        "Syncing $uri/A-99",
177        'Auto-merging (16, 16) /m-99 to /m-99-copy-twice (base /m-99:16).',
178        "Empty merge.",
179        "Syncing //m-99-copy-twice(/m-99-copy-twice) in $corpath4 to 20.",
180        ]);
181
182is_output($svk, 'smerge', ['-m', '', '--sync', '--from', $copath4], [
183        "Auto-merging (0, 20) /m-99-copy-twice to /m-99 (base /m-99:16).",
184        "Merging back to mirror source $uri/A-99.",
185        "Empty merge.",
186        ]);
187
188is_output ($svk, 'delete', ['-m', 'die!', '//m-99'],
189        ['Committed revision 22.']);
190SKIP:{
191skip 'recover not implemented.', 4;
192
193$answer = 'y';
194is_output ($svk, 'mirror', ['--recover', '//m'],
195	   ['Analyzing revision 19...',
196            '----------------------------------------------------------------------',
197            'SVM: discard mirror for /m',
198            'Analyzing revision 9...',
199            '----------------------------------------------------------------------',
200            'commit to deep mirrored path',
201            'Committed revision 23.',
202            'Committed revision 24.',
203            "Property 'svm:headrev' set on repository revision 24.",
204            "Property 'svn:author' set on repository revision 24.",
205            "Property 'svn:date' set on repository revision 24.",
206            "Property 'svn:log' set on repository revision 24.",
207            'Mirror state successfully recovered.',
208            'Committed revision 25.',
209            '//m added back to the list of mirrored paths.',
210           ]);
211
212is_output ($svk, 'mirror', ['--recover', '//m'],
213	   ['Analyzing revision 24...',
214            '----------------------------------------------------------------------',
215            'commit to deep mirrored path',
216            'No need to revert; it is already the head revision.',
217           ]);
218$svk->mv (-m => 'move on mirror', '//m/Q' => '//m/Q-moved');
219is_ancestor ($svk, '//m/Q-moved', '/m/Q', 6);
220
221is_output ($svk, 'ps', ['foo' => 'bar', -m => 'ps on mirror', '//m/Q-moved'],
222	   ["Merging back to mirror source $uri/A.",
223	    'Merge back committed as revision 32.',
224	    "Syncing $uri/A",
225	    'Retrieving log information from 32 to 32',
226	    'Committed revision 27 from revision 32.']);
227
228}
229