Skip to content

Commit 472d4d8

Browse files
committed
Don't overwrite existing objects
It's redundant to do this (git doesn't) and Windows doesn't allow us to overwrite a read-only file (which objects are). Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
1 parent 2cbca8b commit 472d4d8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/odb_loose.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,17 @@ static int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream)
670670
return git__rethrow(error, "Failed to write loose backend");
671671

672672
stream->finished = 1;
673+
674+
/*
675+
* Don't try to add an existing object to the repository. This
676+
* is what git does and allows us to sidestep the fact that
677+
* we're not allowed to overwrite a read-only file on Windows.
678+
*/
679+
if (git_futils_exists(final_path) == GIT_SUCCESS) {
680+
git_filebuf_cleanup(&stream->fbuf);
681+
return GIT_SUCCESS;
682+
}
683+
673684
return git_filebuf_commit_at(&stream->fbuf, final_path, GIT_OBJECT_FILE_MODE);
674685
}
675686

0 commit comments

Comments
 (0)