Skip to content

Commit a9e87e3

Browse files
committed
Merge branch 'cc/shared-index-permfix' into maint
The split index code did not honor core.sharedrepository setting correctly. * cc/shared-index-permfix: t1700: make sure split-index respects core.sharedrepository t1301: move modebits() to test-lib-functions.sh read-cache: use shared perms when writing shared index
2 parents 76de71b + 3ee83f4 commit a9e87e3

File tree

4 files changed

+50
-11
lines changed

4 files changed

+50
-11
lines changed

read-cache.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2428,6 +2428,14 @@ static int write_shared_index(struct index_state *istate,
24282428
delete_tempfile(&temporary_sharedindex);
24292429
return ret;
24302430
}
2431+
ret = adjust_shared_perm(get_tempfile_path(&temporary_sharedindex));
2432+
if (ret) {
2433+
int save_errno = errno;
2434+
error("cannot fix permission bits on %s", get_tempfile_path(&temporary_sharedindex));
2435+
delete_tempfile(&temporary_sharedindex);
2436+
errno = save_errno;
2437+
return ret;
2438+
}
24312439
ret = rename_tempfile(&temporary_sharedindex,
24322440
git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
24332441
if (!ret) {

t/t1301-shared-repo.sh

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ test_expect_success 'shared = 0400 (faulty permission u-w)' '
1919
)
2020
'
2121

22-
modebits () {
23-
ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
24-
}
25-
2622
for u in 002 022
2723
do
2824
test_expect_success POSIXPERM "shared=1 does not clear bits preset by umask $u" '
@@ -88,7 +84,7 @@ do
8884
8985
rm -f .git/info/refs &&
9086
git update-server-info &&
91-
actual="$(modebits .git/info/refs)" &&
87+
actual="$(test_modebits .git/info/refs)" &&
9288
verbose test "x$actual" = "x-$y"
9389
9490
'
@@ -98,7 +94,7 @@ do
9894
9995
rm -f .git/info/refs &&
10096
git update-server-info &&
101-
actual="$(modebits .git/info/refs)" &&
97+
actual="$(test_modebits .git/info/refs)" &&
10298
verbose test "x$actual" = "x-$x"
10399
104100
'
@@ -111,7 +107,7 @@ test_expect_success POSIXPERM 'info/refs respects umask in unshared repo' '
111107
umask 002 &&
112108
git update-server-info &&
113109
echo "-rw-rw-r--" >expect &&
114-
modebits .git/info/refs >actual &&
110+
test_modebits .git/info/refs >actual &&
115111
test_cmp expect actual
116112
'
117113

@@ -177,7 +173,7 @@ test_expect_success POSIXPERM 'remote init does not use config from cwd' '
177173
umask 0022 &&
178174
git init --bare child.git &&
179175
echo "-rw-r--r--" >expect &&
180-
modebits child.git/config >actual &&
176+
test_modebits child.git/config >actual &&
181177
test_cmp expect actual
182178
'
183179

@@ -187,7 +183,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (local)' '
187183
echo whatever >templates/foo &&
188184
git init --template=templates &&
189185
echo "-rw-rw-rw-" >expect &&
190-
modebits .git/foo >actual &&
186+
test_modebits .git/foo >actual &&
191187
test_cmp expect actual
192188
'
193189

@@ -198,7 +194,7 @@ test_expect_success POSIXPERM 're-init respects core.sharedrepository (remote)'
198194
test_path_is_missing child.git/foo &&
199195
git init --bare --template=../templates child.git &&
200196
echo "-rw-rw-rw-" >expect &&
201-
modebits child.git/foo >actual &&
197+
test_modebits child.git/foo >actual &&
202198
test_cmp expect actual
203199
'
204200

@@ -209,7 +205,7 @@ test_expect_success POSIXPERM 'template can set core.sharedrepository' '
209205
cp .git/config templates/config &&
210206
git init --bare --template=../templates child.git &&
211207
echo "-rw-rw-rw-" >expect &&
212-
modebits child.git/HEAD >actual &&
208+
test_modebits child.git/HEAD >actual &&
213209
test_cmp expect actual
214210
'
215211

t/t1700-split-index.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,4 +370,34 @@ test_expect_success 'check splitIndex.sharedIndexExpire set to "never" and "now"
370370
test $(ls .git/sharedindex.* | wc -l) -le 2
371371
'
372372

373+
while read -r mode modebits
374+
do
375+
test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '
376+
# Remove existing shared index files
377+
git config core.splitIndex false &&
378+
git update-index --force-remove one &&
379+
rm -f .git/sharedindex.* &&
380+
# Create one new shared index file
381+
git config core.sharedrepository "$mode" &&
382+
git config core.splitIndex true &&
383+
: >one &&
384+
git update-index --add one &&
385+
echo "$modebits" >expect &&
386+
test_modebits .git/index >actual &&
387+
test_cmp expect actual &&
388+
shared=$(ls .git/sharedindex.*) &&
389+
case "$shared" in
390+
*" "*)
391+
# we have more than one???
392+
false ;;
393+
*)
394+
test_modebits "$shared" >actual &&
395+
test_cmp expect actual ;;
396+
esac
397+
'
398+
done <<\EOF
399+
0666 -rw-rw-rw-
400+
0642 -rw-r---w-
401+
EOF
402+
373403
test_done

t/test-lib-functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ test_chmod () {
216216
git update-index --add "--chmod=$@"
217217
}
218218

219+
# Get the modebits from a file.
220+
test_modebits () {
221+
ls -l "$1" | sed -e 's|^\(..........\).*|\1|'
222+
}
223+
219224
# Unset a configuration variable, but don't fail if it doesn't exist.
220225
test_unconfig () {
221226
config_dir=

0 commit comments

Comments
 (0)