Skip to content

Commit 7a0a34c

Browse files
drafnelgitster
authored andcommitted
builtin-reflog.c: don't install new reflog on write failure
When expiring reflog entries, a new temporary log is written which contains only the entries to retain. After it is written, it is renamed to replace the existing reflog. Currently, we check that writing of the new log is successful and print a message on failure, but the original reflog is still replaced with the new reflog even on failure. This patch causes the original reflog to be retained if we fail when writing the new reflog. Signed-off-by: Brandon Casey <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ecbc85 commit 7a0a34c

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

builtin-reflog.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
276276
for_each_reflog_ent(ref, expire_reflog_ent, &cb);
277277
finish:
278278
if (cb.newlog) {
279-
if (fclose(cb.newlog))
279+
if (fclose(cb.newlog)) {
280280
status |= error("%s: %s", strerror(errno),
281281
newlog_path);
282-
if (rename(newlog_path, log_file)) {
282+
unlink(newlog_path);
283+
} else if (rename(newlog_path, log_file)) {
283284
status |= error("cannot rename %s to %s",
284285
newlog_path, log_file);
285286
unlink(newlog_path);

0 commit comments

Comments
 (0)