From 4ba0bd54b35f6ac637ec1274911dde1629aa04a1 Mon Sep 17 00:00:00 2001 From: Johannes Sixt Date: Mon, 8 Jan 2007 17:45:25 +0100 Subject: [PATCH] rename() fails on Windows if the destination exists. --- builtin-reflog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builtin-reflog.c b/builtin-reflog.c index 6d14184736..4877bb060b 100644 --- a/builtin-reflog.c +++ b/builtin-reflog.c @@ -274,6 +274,12 @@ static int expire_reflog(const char *ref, const unsigned char *sha1, int unused, if (fclose(cb.newlog)) status |= error("%s: %s", strerror(errno), newlog_path); +#ifdef __MINGW32__ + /* rename fails if the destination exists */ + if (unlink(lock->log_file)) + status |= error("cannot remove %s", lock->log_file); + else +#endif if (rename(newlog_path, lock->log_file)) { status |= error("cannot rename %s to %s", newlog_path, lock->log_file);