File: 053_conflicts

package info (click to toggle)
fsvs 1.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 2,964 kB
  • ctags: 1,464
  • sloc: ansic: 16,650; sh: 5,885; perl: 783; makefile: 338; python: 90
file content (288 lines) | stat: -rwxr-xr-x 6,480 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

set -e 
$PREPARE_CLEAN > /dev/null
$INCLUDE_FUNCS
cd $WC

logfile=$LOGDIR/053.conflicts


#### Define the test files.
# A list of numbers
seq 1 20 > common_ancestor
# Lines *2 gets changed
perl -pe 's/2$/2changed-repos/' < common_ancestor > repository
# Now change line 7.
perl -pe 's/^7$/7local/' < common_ancestor > locally_changed
# What the merged file should look like
diff3 -m locally_changed common_ancestor repository > merged_ok
# Another local data, with conflict
perl -pe 's/^2$/2 is changed=conflict/' < common_ancestor > will_conflict
# Output of the merge conflict can be done only when we know the revision 
# numbers; these get encoded in the filenames.
touch merged_conflict


target=myfile

# Put into repository.
cat common_ancestor > $target
$BINq ci -m 1 $target -o delay=yes > $logfile 
rev_old=`grep "revision	" $logfile | tail -1 | cut -f2 -d"	" | cut -f1 -d" "` 

cat repository > $target
$BINq ci -m 2 $target -o delay=yes > $logfile 
rev_new=`grep "revision	" $logfile | tail -1 | cut -f2 -d"	" | cut -f1 -d" "` 


# Now create the merge conflict compare file.
if diff3 -m -L $target.mine -L $target.r$rev_old -L $target.r$rev_new will_conflict common_ancestor repository > merged_conflict
then
	$ERROR "merge doesn't gives a conflict?"
fi
if [[ $? == 1 ]]
then
	$ERROR "Expected error code of merge not given"
fi
if [[ `egrep '<<<<|>>>>|====|\|\|\|\|' < merged_conflict | wc -l` -eq 4 ]]
then
	$INFO "merged_conflict seems ok."
else
	$ERROR "merged_conflict wrong?"
fi



# We start with the "old" version.
$BINq up -r$rev_old

# Now we change something ....
cat locally_changed > $target

# and try to get the newer version.
if $BINq up -o conflict=stop > $logfile 2>&1
then
  $ERROR "Didn't stop on conflict"
else
  $SUCCESS "Stop on conflict=stop"
fi
if $BINdflt st -v $target | grep "^....x. "
then
  $ERROR "Marked as conflict on conflict=stop?"
fi


if $BINq up -o conflict=local > $logfile 2>&1
then
	if cmp $target locally_changed
	then
		md5sum $target locally_changed
		$SUCCESS "conflict=local works"
	else
		diff -u $target locally_changed
		$ERROR "conflict=local doesn't work - wrong data"
	fi
else
	cat $logfile
  $ERROR "conflict=local doesn't work"
fi

if $BINdflt st -v $target | grep "^....x. "
then
  $ERROR "Marked as conflict on conflict=local?"
fi

if [[ x`$BINq st $target` != x ]]
then
	$BINq st $target
  $ERROR "unexpected status output on conflict=local - should be empty."
fi


# Goto old revision
$BINq up -r$rev_old -o conflict=local
if ! cmp $target locally_changed
then
	$ERROR "Returning to old revision doesn't work - 1"
fi

if $BINq up -o conflict=remote > $logfile 2>&1
then
	if cmp $target repository
	then
		md5sum $target repository
		$SUCCESS "conflict=remote works"
	else
		diff -u $target repository
		$ERROR "conflict=remote doesn't work - wrong data"
	fi
else
	cat $logfile
  $ERROR "conflict=repository doesn't work"
fi

if $BINdflt st -v $target | grep "^...x. "
then
  $ERROR "Marked as conflict on conflict=repos?"
fi


# Goto old revision. There's no conflict now, as we took the committed 
# version.
$BINq up -r$rev_old -o conflict=stop
if ! cmp $target common_ancestor
then
	$ERROR "Returning to old revision doesn't work - 2"
fi


# Now test getting both files.
cat locally_changed > $target
$BINq up -o conflict=both
if ! cmp $target.mine locally_changed
then
	$ERROR "conflict=both: wrong data for $target.mine."
fi
if ! cmp $target.r$rev_new repository
then
	$ERROR "conflict=both: wrong data for $target.r$rev_new."
fi

if $BINdflt st -v $target | grep "^....x. "
then
	$SUCCESS "conflict=both works."
else
  $ERROR "No conflict on conflict=both?"
fi


# Revert should leave only a single file.
$BINq revert $target
if [[ `ls -dla $target* | wc -l` -eq 1 ]]
then
	$SUCCESS "aux files removed after revert."
else
  ls -dla $target*
	$ERROR "unexpected auxillary files after revert."
fi


rm $target*
# Now that should just work.
$BINq up -r$rev_old -o conflict=remote

# Test doing a merge
cat locally_changed > $target
$BINq up -o conflict=merge
if ! cmp $target merged_ok
then
	$ERROR "conflict=merge: wrong data for $target."
fi
if [[ `ls -dla $target* | wc -l` -eq 1 ]]
then
	$SUCCESS "conflict=merge works."
else
  ls -dla $target*
	$ERROR "conflict=merge: unexpected auxillary files."
fi


# This should give the old file.
$BINq up -r$rev_old -o conflict=merge
if cmp $target locally_changed
then
	$SUCCESS "reverse merge ok"
else
	diff -u $target locally_changed
	$ERROR "reverse merge wrong?"
fi


# Now do a conflict
cat will_conflict > $target
touch time_mark_file
sleep 1
$BINq up -o conflict=merge -o delay=yes > $logfile
if ! cmp $target merged_conflict
then
	diff -u $target merged_conflict
	$ERROR "conflict=merge with conflict: wrong data for $target."
fi

if [[ `ls -dla $target* | wc -l` -ne 4 ]]
then
  ls -dla $target*
	$ERROR "conflict=merge: unexpected auxillary files."
fi

if [[ -e $target && -e $target.r$rev_new && $target.r$rev_old && $target.mine ]]
then
	$SUCCESS "conflict=merge producing conflict has auxillary files."
else
  ls -dla $target*
	$ERROR "conflict=merge: expected auxillary files missing."
fi


if $BINdflt st -v $target | grep "^....x. "
then
	$SUCCESS "conflict marker set."
else
  $ERROR "No conflict on mis-merge?"
fi

if $BINdflt ci $target -m conflict
then
	$ERROR "shouldn't commit a conflicted file!"
else
	$SUCCESS "doesn't commit a conflicted file"
fi


# resolve should leave only a single file, and process only known.
$BINq resolve *
if [[ `ls -dla $target* | wc -l` -eq 1 ]]
then
	$SUCCESS "aux files removed after revert (2)."
else
  ls -dla $target*
	$ERROR "unexpected auxillary files after revert (2)."
fi

# After resolve only $target should be seen - not any other files.
# With just "status" we'd get a line for ".", too - which we don't want.
$BINdflt st * > $logfile
if [[ `grep '^N' < $logfile | wc -l` -ne 7 ]]
then
	cat $logfile
  $ERROR "resolve takes unknown files, too"
fi
if [[ `grep -v '^N' < $logfile` == ".mC."*"$target" ]]
then
  $SUCCESS "resolve takes only the known files."
else
	cat $logfile
  $ERROR "Wrong status after resolve"
fi


# Look whether the merged file has a NOW timestamp - ie. newer than the 
# marked file
if [[ $target -ot time_mark_file ]]
then
	ls -la --full-time $target time_mark_file
	$ERROR "Timestamp of merged file wrong"
else
  $SUCCESS "merged file has mtime NOW"
fi


if $BINdflt ci $target -m 1
then
	$SUCCESS "Can commit after revert."
else
	$ERROR "Can't commit?"
fi