summaryrefslogtreecommitdiff
path: root/builtin-reflog.c
diff options
context:
space:
mode:
authorBrandon Casey <casey@nrlssc.navy.mil>2008-02-22 12:47:08 -0600
committerJunio C Hamano <gitster@pobox.com>2008-02-27 13:26:24 -0800
commit7a0a34ca6f31c6bb5d24ccc0cdab606736d7a322 (patch)
treec4c82fd80edf4e489a8a1720ff2df5083539c627 /builtin-reflog.c
parent6ecbc851fb30f540e1a25761f221aab963cfe619 (diff)
downloadgit-7a0a34ca6f31c6bb5d24ccc0cdab606736d7a322.tar.gz
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 <casey@nrlssc.navy.mil> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-reflog.c')
-rw-r--r--builtin-reflog.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/builtin-reflog.c b/builtin-reflog.c
index 4836ec951b..ab53c8cb7c 100644
--- a/builtin-reflog.c
+++ b/builtin-reflog.c
@@ -276,10 +276,11 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused,
for_each_reflog_ent(ref, expire_reflog_ent, &cb);
finish:
if (cb.newlog) {
- if (fclose(cb.newlog))
+ if (fclose(cb.newlog)) {
status |= error("%s: %s", strerror(errno),
newlog_path);
- if (rename(newlog_path, log_file)) {
+ unlink(newlog_path);
+ } else if (rename(newlog_path, log_file)) {
status |= error("cannot rename %s to %s",
newlog_path, log_file);
unlink(newlog_path);