Skip to content

Commit a0a9675

Browse files
pcloudsgitster
authored andcommitted
update-index --split-index: do not split if $GIT_DIR is read only
If $GIT_DIR is read only, we can't write $GIT_DIR/sharedindex. This could happen when $GIT_INDEX_FILE is set to somehwere outside $GIT_DIR. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c18b80a commit a0a9675

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

read-cache.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,14 +2030,21 @@ static void remove_temporary_sharedindex_on_signal(int signo)
20302030
raise(signo);
20312031
}
20322032

2033-
static int write_shared_index(struct index_state *istate)
2033+
static int write_shared_index(struct index_state *istate,
2034+
struct lock_file *lock, unsigned flags)
20342035
{
20352036
struct split_index *si = istate->split_index;
20362037
static int installed_handler;
20372038
int fd, ret;
20382039

20392040
temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
2040-
fd = xmkstemp(temporary_sharedindex);
2041+
fd = mkstemp(temporary_sharedindex);
2042+
if (fd < 0) {
2043+
free(temporary_sharedindex);
2044+
temporary_sharedindex = NULL;
2045+
hashclr(si->base_sha1);
2046+
return do_write_locked_index(istate, lock, flags);
2047+
}
20412048
if (!installed_handler) {
20422049
atexit(remove_temporary_sharedindex);
20432050
sigchain_push_common(remove_temporary_sharedindex_on_signal);
@@ -2070,7 +2077,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
20702077
}
20712078

20722079
if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
2073-
int ret = write_shared_index(istate);
2080+
int ret = write_shared_index(istate, lock, flags);
20742081
if (ret)
20752082
return ret;
20762083
}

0 commit comments

Comments
 (0)