reflog_expire(): never update a reference to null_sha1
[gitweb.git] / refs.c
diff --git a/refs.c b/refs.c
index 4684ffe2a6ff7c749aa0c51389c7ee9bb5024c7a..05a4be0c0628098dec80d9bd8a564cfc019c2427 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -4081,10 +4081,13 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
                /*
                 * It doesn't make sense to adjust a reference pointed
                 * to by a symbolic ref based on expiring entries in
-                * the symbolic reference's reflog.
+                * the symbolic reference's reflog. Nor can we update
+                * a reference if there are no remaining reflog
+                * entries.
                 */
                int update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&
-                       !(type & REF_ISSYMREF);
+                       !(type & REF_ISSYMREF) &&
+                       !is_null_sha1(cb.last_kept_sha1);
 
                if (close_lock_file(&reflog_lock)) {
                        status |= error("couldn't write %s: %s", log_file,