comparison tests/test-inherit-mode.t @ 12096:bb69460e9d2d

tests: unify test-inherit-mode
author Nicolas Dumazet <nicdumz.commits@gmail.com>
date Mon, 30 Aug 2010 12:46:19 +0900
parents tests/test-inherit-mode@68cfd7d208a5
children 4c4aeaab2339
comparison
equal deleted inserted replaced
12095:80b0865b3fa5 12096:bb69460e9d2d
1 test that new files created in .hg inherit the permissions from .hg/store
2
3
4 $ "$TESTDIR/hghave" unix-permissions || exit 80
5
6 $ mkdir dir
7
8 just in case somebody has a strange $TMPDIR
9
10 $ chmod g-s dir
11 $ cd dir
12
13 $ cat >printmodes.py <<EOF
14 > import os, sys
15 >
16 > allnames = []
17 > isdir = {}
18 > for root, dirs, files in os.walk(sys.argv[1]):
19 > for d in dirs:
20 > name = os.path.join(root, d)
21 > isdir[name] = 1
22 > allnames.append(name)
23 > for f in files:
24 > name = os.path.join(root, f)
25 > allnames.append(name)
26 > allnames.sort()
27 > for name in allnames:
28 > suffix = name in isdir and '/' or ''
29 > print '%05o %s%s' % (os.lstat(name).st_mode & 07777, name, suffix)
30 > EOF
31
32 $ cat >mode.py <<EOF
33 > import sys
34 > import os
35 > print '%05o' % os.lstat(sys.argv[1]).st_mode
36 > EOF
37
38 $ umask 077
39
40 $ hg init repo
41 $ cd repo
42
43 $ chmod 0770 .hg/store
44
45 before commit
46 store can be written by the group, other files cannot
47 store is setgid
48
49 $ python ../printmodes.py .
50 00700 ./.hg/
51 00600 ./.hg/00changelog.i
52 00600 ./.hg/requires
53 00770 ./.hg/store/
54
55 $ mkdir dir
56 $ touch foo dir/bar
57 $ hg ci -qAm 'add files'
58
59 after commit
60 working dir files can only be written by the owner
61 files created in .hg can be written by the group
62 (in particular, store/**, dirstate, branch cache file, undo files)
63 new directories are setgid
64
65 $ python ../printmodes.py .
66 00700 ./.hg/
67 00600 ./.hg/00changelog.i
68 00660 ./.hg/dirstate
69 00660 ./.hg/last-message.txt
70 00600 ./.hg/requires
71 00770 ./.hg/store/
72 00660 ./.hg/store/00changelog.i
73 00660 ./.hg/store/00manifest.i
74 00770 ./.hg/store/data/
75 00770 ./.hg/store/data/dir/
76 00660 ./.hg/store/data/dir/bar.i
77 00660 ./.hg/store/data/foo.i
78 00660 ./.hg/store/fncache
79 00660 ./.hg/store/undo
80 00660 ./.hg/undo.branch
81 00660 ./.hg/undo.desc
82 00660 ./.hg/undo.dirstate
83 00700 ./dir/
84 00600 ./dir/bar
85 00600 ./foo
86
87 $ umask 007
88 $ hg init ../push
89
90 before push
91 group can write everything
92
93 $ python ../printmodes.py ../push
94 00770 ../push/.hg/
95 00660 ../push/.hg/00changelog.i
96 00660 ../push/.hg/requires
97 00770 ../push/.hg/store/
98
99 $ umask 077
100 $ hg -q push ../push
101
102 after push
103 group can still write everything
104
105 $ python ../printmodes.py ../push
106 00770 ../push/.hg/
107 00660 ../push/.hg/00changelog.i
108 00660 ../push/.hg/branchheads.cache
109 00660 ../push/.hg/requires
110 00770 ../push/.hg/store/
111 00660 ../push/.hg/store/00changelog.i
112 00660 ../push/.hg/store/00manifest.i
113 00770 ../push/.hg/store/data/
114 00770 ../push/.hg/store/data/dir/
115 00660 ../push/.hg/store/data/dir/bar.i
116 00660 ../push/.hg/store/data/foo.i
117 00660 ../push/.hg/store/fncache
118 00660 ../push/.hg/store/undo
119 00660 ../push/.hg/undo.branch
120 00660 ../push/.hg/undo.desc
121 00660 ../push/.hg/undo.dirstate
122
123
124 Test that we don't lose the setgid bit when we call chmod.
125 Not all systems support setgid directories (e.g. HFS+), so
126 just check that directories have the same mode.
127
128 $ cd ..
129 $ hg init setgid
130 $ cd setgid
131 $ chmod g+rwx .hg/store
132 $ chmod g+s .hg/store 2> /dev/null
133 $ mkdir dir
134 $ touch dir/file
135 $ hg ci -qAm 'add dir/file'
136 $ storemode=`python ../mode.py .hg/store`
137 $ dirmode=`python ../mode.py .hg/store/data/dir`
138 $ if [ "$storemode" != "$dirmode" ]; then
139 > echo "$storemode != $dirmode"
140 $ fi