Skip to content

Commit

Permalink
update-index --split-index: do not split if $GIT_DIR is read only
Browse files Browse the repository at this point in the history
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 <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jun 13, 2014
1 parent c18b80a commit a0a9675
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions read-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,14 +2030,21 @@ static void remove_temporary_sharedindex_on_signal(int signo)
raise(signo);
}

static int write_shared_index(struct index_state *istate)
static int write_shared_index(struct index_state *istate,
struct lock_file *lock, unsigned flags)
{
struct split_index *si = istate->split_index;
static int installed_handler;
int fd, ret;

temporary_sharedindex = git_pathdup("sharedindex_XXXXXX");
fd = xmkstemp(temporary_sharedindex);
fd = mkstemp(temporary_sharedindex);
if (fd < 0) {
free(temporary_sharedindex);
temporary_sharedindex = NULL;
hashclr(si->base_sha1);
return do_write_locked_index(istate, lock, flags);
}
if (!installed_handler) {
atexit(remove_temporary_sharedindex);
sigchain_push_common(remove_temporary_sharedindex_on_signal);
Expand Down Expand Up @@ -2070,7 +2077,7 @@ int write_locked_index(struct index_state *istate, struct lock_file *lock,
}

if (istate->cache_changed & SPLIT_INDEX_ORDERED) {
int ret = write_shared_index(istate);
int ret = write_shared_index(istate, lock, flags);
if (ret)
return ret;
}
Expand Down

0 comments on commit a0a9675

Please sign in to comment.