Subject: [PATCH 7/7] refs: do not update ref(log) referring to external objects

From: Nguyễn Thái Ngọc Duy <[email-masked]>
Date: Thu, 24 Jan 2013 15:42:20 +0700

Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
---
 refs.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/refs.c b/refs.c
index 541fec2..86003af 100644
--- a/refs.c
+++ b/refs.c
@@ -2014,6 +2014,18 @@ static int log_ref_write(const char *refname, const unsigned char *old_sha1,
 	char *logrec;
 	const char *committer;
 
+	if (object_database_contaminated) {
+		struct object_info oi;
+		if (sha1_object_info_extended(old_sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external))
+			return error("cannot update reflog pointing to an external SHA-1 %s",
+				     sha1_to_hex(old_sha1));
+		if (sha1_object_info_extended(new_sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external))
+			return error("cannot update reflog pointing to an external SHA-1 %s",
+				     sha1_to_hex(new_sha1));
+	}
+
 	if (log_all_ref_updates < 0)
 		log_all_ref_updates = !is_bare_repository();
 
@@ -2054,6 +2066,18 @@ int write_ref_sha1(struct ref_lock *lock,
 
 	if (!lock)
 		return -1;
+
+	if (object_database_contaminated) {
+		struct object_info oi;
+		if (sha1_object_info_extended(sha1, &oi) == -1 ||
+		    (oi.alt && oi.alt->external)) {
+			error("cannot update ref pointing to an external SHA-1 %s",
+			      sha1_to_hex(sha1));
+			unlock_ref(lock);
+			return -1;
+		}
+	}
+
 	if (!lock->force_write && !hashcmp(lock->old_sha1, sha1)) {
 		unlock_ref(lock);
 		return 0;
-- 
1.8.0.rc3.18.g0d9b108