update readmes
[git-darcs-import.git] / tests / conflict-doppleganger.pl
blob2eb5fff0222c5a780b71a10d5a0bb1737db7a982
1 #!/usr/bin/env perl
3 # Tests for the doppleganger conflict bug.
5 # For Zooko, with love
6 # Also, for issue81.
8 use lib 'lib/perl';
10 use Test::More 'no_plan';
11 use Test::Darcs;
12 use Shell::Command;
13 use File::Slurp;
14 use strict;
15 use warnings;
17 system 'rm -rf temp';
18 my $wd = `pwd`;
19 chomp $wd;
20 mkdir 'temp';
21 chdir 'temp';
23 sub mycleanup {
24 chdir $wd;
25 system 'rm -rf temp/*';
26 chdir 'temp';
29 ok (dopplegangers_conflict('old-fashioned-inventory'),
30 "default repo format views doppleganger as a conflict");
31 mycleanup;
32 ok (dopplegangers_conflict('hashed'),
33 "hashed repo format views doppleganger as a conflict");
34 mycleanup;
35 ok ((not dopplegangers_conflict('darcs-2')),
36 "with darcs-2 format, doppleganger's don't conflict! ");
37 mycleanup;
38 ok (resolution_dopplegangers_conflict('old-fashioned-inventory'),
39 "default repo format views resolution doppleganger as a conflict");
40 mycleanup;
41 ok (resolution_dopplegangers_conflict('hashed'),
42 "hashed repo format views resolution doppleganger as a conflict");
43 mycleanup;
44 ok (not (resolution_dopplegangers_conflict('darcs-2')),
45 "with darcs-2 format, resolution doppleganger's don't conflict! ");
48 sub dopplegangers_conflict {
49 my $arg_to_init = shift;
50 system 'rm -rf tmp_dopple tmp_ganger';
52 mkpath 'tmp_dopple';
53 chdir 'tmp_dopple';
54 darcs 'init --'.$arg_to_init;
56 # Map args to formats
57 my %fmts = (
58 'old-fashioned-inventory' => 'darcs-1.0',
59 'darcs-2' => 'darcs-2',
60 'hashed' => 'hashed',
63 like((darcs 'show repo'), qr/$fmts{$arg_to_init}/,
64 "reality check: $fmts{$arg_to_init} is repo format of tmp_doppel");
66 touch 'a.txt';
67 darcs "add a.txt";
68 my $out = darcs "record -A base -am 'adding a.txt'";
69 like($out, qr/finished/msxi, "$arg_to_init: recorded patch for adding file.");
71 chdir '../';
73 $out = darcs 'get tmp_dopple tmp_ganger';
74 like($out, qr/inished getting/, 'get tmp_dopple tmp_ganger worked');
75 #diag $out;
77 #like((darcs 'show repo --repodir=tmp_ganger'), qr/$fmts{$arg_to_init}/,
78 # "reality check: $fmts{$arg_to_init} is repo format for tmp_ganger");
80 for my $repo (qw(dopple ganger)) {
81 ok((chdir "tmp_$repo"), "chdir'ed tmp_$repo");
82 `echo "text which appears in both places at once" > a.txt`;
83 my $out = darcs "record -A $repo -am 'recording an identical change'";
84 like($out, qr/finished/msxi, "$arg_to_init: recorded patch in $repo");
85 # diag "in loop: $out";
86 chdir '../';
89 # Now that the conflict has been set up, try pull one patch from the other.
90 chdir 'tmp_ganger';
92 my $pull_out = darcs 'pull -a ../tmp_dopple';
93 my $has_a_conflict_p = ($pull_out =~ m/conflict/msxi);
94 # diag "result: $pull_out";
96 ####
98 # diag "about to to return: $has_a_conflict_p";
100 return $has_a_conflict_p;
103 sub resolution_dopplegangers_conflict {
104 my $arg_to_init = shift;
106 system 'rm -rf temp0 temp1 temp2';
108 # Map args to formats
109 my %fmts = (
110 'old-fashioned-inventory' => 'darcs-1.0',
111 'darcs-2' => 'darcs-2',
112 'hashed' => 'hashed',
115 mkpath 'temp0';
116 chdir 'temp0';
117 darcs 'init --'.$arg_to_init;
118 like((darcs 'show repo'), qr/$fmts{$arg_to_init}/,
119 "reality check: $fmts{$arg_to_init} is repo format of temp0");
120 #diag (darcs 'show repo');
121 chdir '..';
123 # Create a conflict
124 darcs 'get ../temp0 temp1';
125 chdir 'temp1';
126 #diag (darcs 'show repo');
127 like((darcs 'show repo'), qr/$fmts{$arg_to_init}/,
128 "reality check: $fmts{$arg_to_init} is repo format of temp1");
129 `echo "temp1" > a.txt`;
130 darcs "add a.txt";
131 darcs "record -A base -am 'adding a.txt'";
132 chdir '..';
133 darcs 'get ../temp0 temp2';
134 chdir 'temp2';
135 #diag (darcs 'show repo');
136 `echo "temp2" > a.txt`;
137 darcs "add a.txt";
138 darcs "record -A base -am 'adding a.txt'";
139 chdir '..';
141 # Resolve the conflict the same way on both sides
142 for my $repo (qw(dopple ganger)) {
143 darcs "get temp1 tmp_$repo";
144 ok((chdir "tmp_$repo"), "chdir'ed tmp_$repo");
145 darcs "pull -a ../temp2";
146 `echo "text which appears in both places at once" > a.txt`;
147 my $out = darcs "record -A $repo -am 'recording an identical change'";
148 like($out, qr/finished/msxi, "$arg_to_init: recorded patch in $repo");
149 #diag "in loop: $out";
150 chdir '../';
153 # Now that the conflict has been set up, try pull one patch from the other.
154 chdir 'tmp_ganger';
156 my $pull_out = darcs 'pull -a ../tmp_dopple';
157 #diag (darcs 'changes -v');
158 my $has_a_conflict_p = ($pull_out =~ m/conflict/msxi);
159 #diag "result: $pull_out";
160 chdir '..';
163 ####
165 #diag "about to to return: $has_a_conflict_p";
167 return $has_a_conflict_p;