Skip to content

Commit c9d6c78

Browse files
avargitster
authored andcommitted
read-cache: make the split index obey umask settings
Make the split index write out its .git/sharedindex_* files with the same permissions as .git/index. This only changes the behavior when core.sharedRepository isn't set, i.e. the user's umask settings will be respected. This hasn't been the case ever since the split index was originally implemented in c18b80a ("update-index: new options to enable/disable split index mode", 2014-06-13). A mkstemp()-like function has always been used to create it. First mkstemp() itself, and then later our own mkstemp()-like in f6ecc62 ("write_shared_index(): use tempfile module", 2015-08-10) A related bug was fixed in df801f3 ("read-cache: use shared perms when writing shared index", 2017-06-25). Since then the split index has respected core.sharedRepository. However, using that setting should not be required simply to make git obey the user's umask setting. It's intended for the use-case of overriding whatever that umask is set to. This fixes cases where the user has e.g. set his umask to 022 on a shared server in anticipation of other user's needing to run "status", "log" etc. in his repository. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cae598d commit c9d6c78

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

read-cache.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2774,7 +2774,8 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
27742774
struct tempfile *temp;
27752775
int saved_errno;
27762776

2777-
temp = mks_tempfile(git_path("sharedindex_XXXXXX"));
2777+
/* Same initial permissions as the main .git/index file */
2778+
temp = mks_tempfile_sm(git_path("sharedindex_XXXXXX"), 0, 0666);
27782779
if (!temp) {
27792780
oidclr(&si->base_oid);
27802781
ret = do_write_locked_index(istate, lock, flags);

t/t1700-split-index.sh

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

372+
test_expect_success POSIXPERM 'same mode for index & split index' '
373+
git init same-mode &&
374+
(
375+
cd same-mode &&
376+
test_commit A &&
377+
test_modebits .git/index >index_mode &&
378+
test_must_fail git config core.sharedRepository &&
379+
git -c core.splitIndex=true status &&
380+
shared=$(ls .git/sharedindex.*) &&
381+
case "$shared" in
382+
*" "*)
383+
# we have more than one???
384+
false ;;
385+
*)
386+
test_modebits "$shared" >split_index_mode &&
387+
test_cmp index_mode split_index_mode ;;
388+
esac
389+
)
390+
'
391+
372392
while read -r mode modebits
373393
do
374394
test_expect_success POSIXPERM "split index respects core.sharedrepository $mode" '

0 commit comments

Comments
 (0)