##// END OF EJS Templates
tests: fix module-import warnings in test-update-atomic.t...
Pulkit Goyal -
r41394:0a0927f7 default
parent child Browse files
Show More
@@ -1,146 +1,147
1 #require execbit unix-permissions
1 #require execbit unix-permissions
2
2
3 Checking that experimental.atomic-file works.
3 Checking that experimental.atomic-file works.
4
4
5 $ cat > $TESTTMP/show_mode.py <<EOF
5 $ cat > $TESTTMP/show_mode.py <<EOF
6 > from __future__ import print_function
6 > from __future__ import print_function
7 > import os
8 > import stat
7 > import sys
9 > import sys
8 > import os
10 > ST_MODE = stat.ST_MODE
9 > from stat import ST_MODE
10 >
11 >
11 > for file_path in sys.argv[1:]:
12 > for file_path in sys.argv[1:]:
12 > file_stat = os.stat(file_path)
13 > file_stat = os.stat(file_path)
13 > octal_mode = oct(file_stat[ST_MODE] & 0o777).replace('o', '')
14 > octal_mode = oct(file_stat[ST_MODE] & 0o777).replace('o', '')
14 > print("%s:%s" % (file_path, octal_mode))
15 > print("%s:%s" % (file_path, octal_mode))
15 >
16 >
16 > EOF
17 > EOF
17
18
18 $ hg init repo
19 $ hg init repo
19 $ cd repo
20 $ cd repo
20
21
21 $ cat > .hg/showwrites.py <<EOF
22 $ cat > .hg/showwrites.py <<EOF
22 > from __future__ import print_function
23 > from __future__ import print_function
23 > from mercurial import pycompat
24 > from mercurial import pycompat
24 > from mercurial.utils import stringutil
25 > from mercurial.utils import stringutil
25 > def uisetup(ui):
26 > def uisetup(ui):
26 > from mercurial import vfs
27 > from mercurial import vfs
27 > class newvfs(vfs.vfs):
28 > class newvfs(vfs.vfs):
28 > def __call__(self, *args, **kwargs):
29 > def __call__(self, *args, **kwargs):
29 > print(pycompat.sysstr(stringutil.pprint(
30 > print(pycompat.sysstr(stringutil.pprint(
30 > ('vfs open', args, sorted(list(kwargs.items()))))))
31 > ('vfs open', args, sorted(list(kwargs.items()))))))
31 > return super(newvfs, self).__call__(*args, **kwargs)
32 > return super(newvfs, self).__call__(*args, **kwargs)
32 > vfs.vfs = newvfs
33 > vfs.vfs = newvfs
33 > EOF
34 > EOF
34
35
35 $ for v in a1 a2 b1 b2 c ro; do echo $v > $v; done
36 $ for v in a1 a2 b1 b2 c ro; do echo $v > $v; done
36 $ chmod +x b*
37 $ chmod +x b*
37 $ hg commit -Aqm _
38 $ hg commit -Aqm _
38
39
39 # We check that
40 # We check that
40 # - the changes are actually atomic
41 # - the changes are actually atomic
41 # - that permissions are correct (all 4 cases of (executable before) * (executable after))
42 # - that permissions are correct (all 4 cases of (executable before) * (executable after))
42 # - that renames work, though they should be atomic anyway
43 # - that renames work, though they should be atomic anyway
43 # - that it works when source files are read-only (but directories are read-write still)
44 # - that it works when source files are read-only (but directories are read-write still)
44
45
45 $ for v in a1 a2 b1 b2 ro; do echo changed-$v > $v; done
46 $ for v in a1 a2 b1 b2 ro; do echo changed-$v > $v; done
46 $ chmod -x *1; chmod +x *2
47 $ chmod -x *1; chmod +x *2
47 $ hg rename c d
48 $ hg rename c d
48 $ hg commit -qm _
49 $ hg commit -qm _
49
50
50 Check behavior without update.atomic-file
51 Check behavior without update.atomic-file
51
52
52 $ hg update -r 0 -q
53 $ hg update -r 0 -q
53 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb"
54 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb"
54 ('vfs open', ('a1', 'wb'), [('atomictemp', False), ('backgroundclose', True)])
55 ('vfs open', ('a1', 'wb'), [('atomictemp', False), ('backgroundclose', True)])
55
56
56 $ python $TESTTMP/show_mode.py *
57 $ python $TESTTMP/show_mode.py *
57 a1:0644
58 a1:0644
58 a2:0755
59 a2:0755
59 b1:0644
60 b1:0644
60 b2:0755
61 b2:0755
61 d:0644
62 d:0644
62 ro:0644
63 ro:0644
63
64
64 Add a second revision for the ro file so we can test update when the file is
65 Add a second revision for the ro file so we can test update when the file is
65 present or not
66 present or not
66
67
67 $ echo "ro" > ro
68 $ echo "ro" > ro
68
69
69 $ hg commit -qm _
70 $ hg commit -qm _
70
71
71 Check behavior without update.atomic-file first
72 Check behavior without update.atomic-file first
72
73
73 $ hg update -C -r 0 -q
74 $ hg update -C -r 0 -q
74
75
75 $ hg update -r 1
76 $ hg update -r 1
76 6 files updated, 0 files merged, 1 files removed, 0 files unresolved
77 6 files updated, 0 files merged, 1 files removed, 0 files unresolved
77
78
78 $ python $TESTTMP/show_mode.py *
79 $ python $TESTTMP/show_mode.py *
79 a1:0644
80 a1:0644
80 a2:0755
81 a2:0755
81 b1:0644
82 b1:0644
82 b2:0755
83 b2:0755
83 d:0644
84 d:0644
84 ro:0644
85 ro:0644
85
86
86 Manually reset the mode of the read-only file
87 Manually reset the mode of the read-only file
87
88
88 $ chmod a-w ro
89 $ chmod a-w ro
89
90
90 $ python $TESTTMP/show_mode.py ro
91 $ python $TESTTMP/show_mode.py ro
91 ro:0444
92 ro:0444
92
93
93 Now the file is present, try to update and check the permissions of the file
94 Now the file is present, try to update and check the permissions of the file
94
95
95 $ hg up -r 2
96 $ hg up -r 2
96 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
97 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
97
98
98 $ python $TESTTMP/show_mode.py ro
99 $ python $TESTTMP/show_mode.py ro
99 ro:0644
100 ro:0644
100
101
101 # The file which was read-only is now writable in the default behavior
102 # The file which was read-only is now writable in the default behavior
102
103
103 Check behavior with update.atomic-files
104 Check behavior with update.atomic-files
104
105
105
106
106 $ cat >> .hg/hgrc <<EOF
107 $ cat >> .hg/hgrc <<EOF
107 > [experimental]
108 > [experimental]
108 > update.atomic-file = true
109 > update.atomic-file = true
109 > EOF
110 > EOF
110
111
111 $ hg update -C -r 0 -q
112 $ hg update -C -r 0 -q
112 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb"
113 $ hg update -r 1 --config extensions.showwrites=.hg/showwrites.py 2>&1 | grep "a1'.*wb"
113 ('vfs open', ('a1', 'wb'), [('atomictemp', True), ('backgroundclose', True)])
114 ('vfs open', ('a1', 'wb'), [('atomictemp', True), ('backgroundclose', True)])
114 $ hg st -A --rev 1
115 $ hg st -A --rev 1
115 C a1
116 C a1
116 C a2
117 C a2
117 C b1
118 C b1
118 C b2
119 C b2
119 C d
120 C d
120 C ro
121 C ro
121
122
122 Check the file permission after update
123 Check the file permission after update
123 $ python $TESTTMP/show_mode.py *
124 $ python $TESTTMP/show_mode.py *
124 a1:0644
125 a1:0644
125 a2:0755
126 a2:0755
126 b1:0644
127 b1:0644
127 b2:0755
128 b2:0755
128 d:0644
129 d:0644
129 ro:0644
130 ro:0644
130
131
131 Manually reset the mode of the read-only file
132 Manually reset the mode of the read-only file
132
133
133 $ chmod a-w ro
134 $ chmod a-w ro
134
135
135 $ python $TESTTMP/show_mode.py ro
136 $ python $TESTTMP/show_mode.py ro
136 ro:0444
137 ro:0444
137
138
138 Now the file is present, try to update and check the permissions of the file
139 Now the file is present, try to update and check the permissions of the file
139
140
140 $ hg update -r 2 --traceback
141 $ hg update -r 2 --traceback
141 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
142 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
142
143
143 $ python $TESTTMP/show_mode.py ro
144 $ python $TESTTMP/show_mode.py ro
144 ro:0644
145 ro:0644
145
146
146 # The behavior is the same as without atomic update
147 # The behavior is the same as without atomic update
General Comments 0
You need to be logged in to leave comments. Login now