Commit 637edc9c42803420decebae91d82c3dcf3626c96

Vicent Marti 2011-06-30T20:53:59

refs: Remove bogus assertion The assertion in line 360 was there to check that only loose refs were being written as loose, but there are times when we need to re-write a packed reference as loose.

diff --git a/src/refs.c b/src/refs.c
index 612a779..1bb385c 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -357,8 +357,6 @@ static int loose_write(git_reference *ref)
 	int error;
 	struct stat st;
 
-	assert((ref->type & GIT_REF_PACKED) == 0);
-
 	git__joinpath(ref_path, ref->owner->path_repository, ref->name);
 
 	if ((error = git_filebuf_open(&file, ref_path, GIT_FILEBUF_FORCE)) < GIT_SUCCESS)
@@ -1348,8 +1346,6 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
 		 * us to rollback if writing fails
 		 */
 
-		ref->type &= ~GIT_REF_PACKED;
-
 		/* Create the loose ref under its new name */
 		error = loose_write(ref);
 		if (error < GIT_SUCCESS) {
@@ -1357,6 +1353,8 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
 			goto cleanup;
 		}
 
+		ref->type &= ~GIT_REF_PACKED;
+
 		/* Remove from the packfile cache in order to avoid packing it back
 		 * Note : we do not rely on git_reference_delete() because this would
 		 * invalidate the reference.