Commit a1710a28f684298f79a0bab08b0b8930c1d57cf0

Ben Straub 2014-01-29T10:35:46

Enhance testing of signature parameters

diff --git a/src/clone.c b/src/clone.c
index 97d25bd..3443528 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -246,7 +246,7 @@ static int update_head_to_remote(
 			signature, reflog_message);
 	} else {
 		error = git_repository_set_head_detached(
-			repo, &head_info.remote_head_oid, NULL, reflog_message);
+			repo, &head_info.remote_head_oid, signature, reflog_message);
 	}
 
 cleanup:
diff --git a/src/refs.c b/src/refs.c
index adbc166..eb2c342 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -574,7 +574,8 @@ int git_reference_rename(
 
 	error = reference__rename(out, ref, new_name, force, who, log_message);
 
-	git_signature_free(who);
+	if (!signature)
+		git_signature_free(who);
 
 	return error;
 }
diff --git a/tests/clone/nonetwork.c b/tests/clone/nonetwork.c
index 14d2bbf..f00d28b 100644
--- a/tests/clone/nonetwork.c
+++ b/tests/clone/nonetwork.c
@@ -24,6 +24,7 @@ void test_clone_nonetwork__initialize(void)
 	g_options.checkout_opts = dummy_opts;
 	g_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
 	g_options.remote_callbacks = dummy_callbacks;
+	cl_git_pass(git_signature_now(&g_options.signature, "Me", "foo@example.com"));
 }
 
 void test_clone_nonetwork__cleanup(void)
@@ -43,6 +44,7 @@ void test_clone_nonetwork__cleanup(void)
 		g_remote = NULL;
 	}
 
+	git_signature_free(g_options.signature);
 	cl_fixture_cleanup("./foo");
 }
 
@@ -213,6 +215,8 @@ void test_clone_nonetwork__can_detached_head(void)
 	git_object *obj;
 	git_repository *cloned;
 	git_reference *cloned_head;
+	git_reflog *log;
+	const git_reflog_entry *entry;
 
 	cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
 
@@ -226,8 +230,13 @@ void test_clone_nonetwork__can_detached_head(void)
 	cl_git_pass(git_repository_head(&cloned_head, cloned));
 	cl_assert(!git_oid_cmp(git_object_id(obj), git_reference_target(cloned_head)));
 
+	cl_git_pass(git_reflog_read(&log, cloned, "HEAD"));
+	entry = git_reflog_entry_byindex(log, 0);
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
+
 	git_object_free(obj);
 	git_reference_free(cloned_head);
+	git_reflog_free(log);
 	git_repository_free(cloned);
 
 	cl_fixture_cleanup("./foo1");
@@ -252,12 +261,9 @@ static void assert_correct_reflog(const char *name)
 
 void test_clone_nonetwork__clone_updates_reflog_properly(void)
 {
-	cl_git_pass(git_signature_now(&g_options.signature, "Me", "foo@example.com"));
 	cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
 	assert_correct_reflog("HEAD");
 	assert_correct_reflog("refs/heads/master");
-
-	git_signature_free(g_options.signature);
 }
 
 void test_clone_nonetwork__clone_into_updates_reflog_properly(void)
@@ -274,5 +280,5 @@ void test_clone_nonetwork__clone_into_updates_reflog_properly(void)
 	assert_correct_reflog("refs/heads/master");
 
 	git_remote_free(remote);
-	git_signature_free(g_options.signature);
+	git_signature_free(sig);
 }
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index 32e17d6..06dcca5 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -78,22 +78,30 @@ void test_refs_branches_create__creation_creates_new_reflog(void)
 {
 	git_reflog *log;
 	const git_reflog_entry *entry;
+	git_signature *sig;
+
+	cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
 
 	retrieve_known_commit(&target, repo);
-	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "create!"));
+	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, sig, "create!"));
 	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
 
 	cl_assert_equal_i(1, git_reflog_entrycount(log));
 	entry = git_reflog_entry_byindex(log, 0);
 	cl_assert_equal_s("create!", git_reflog_entry_message(entry));
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
 
 	git_reflog_free(log);
+	git_signature_free(sig);
 }
 
 void test_refs_branches_create__default_reflog_message(void)
 {
 	git_reflog *log;
 	const git_reflog_entry *entry;
+	git_signature *sig;
+
+	cl_git_pass(git_signature_default(&sig, repo));
 
 	retrieve_known_commit(&target, repo);
 	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, NULL));
@@ -101,6 +109,8 @@ void test_refs_branches_create__default_reflog_message(void)
 
 	entry = git_reflog_entry_byindex(log, 0);
 	cl_assert_equal_s("Branch: created", git_reflog_entry_message(entry));
+	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
 
 	git_reflog_free(log);
+	git_signature_free(sig);
 }
diff --git a/tests/refs/branches/move.c b/tests/refs/branches/move.c
index 622921d..3d2c815 100644
--- a/tests/refs/branches/move.c
+++ b/tests/refs/branches/move.c
@@ -193,17 +193,22 @@ void test_refs_branches_move__updates_the_reflog(void)
 	git_reference *new_branch;
 	git_reflog *log;
 	const git_reflog_entry *entry;
+	git_signature *sig;
+
+	cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
 
 	cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
-	cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, NULL, "message"));
+	cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, sig, "message"));
 
 	cl_git_pass(git_reflog_read(&log, repo, git_reference_name(new_branch)));
 	entry = git_reflog_entry_byindex(log, 0);
 	cl_assert_equal_s("message", git_reflog_entry_message(entry));
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
 
 	git_reference_free(branch);
 	git_reference_free(new_branch);
 	git_reflog_free(log);
+	git_signature_free(sig);
 }
 
 void test_refs_branches_move__default_reflog_message(void)
@@ -212,6 +217,9 @@ void test_refs_branches_move__default_reflog_message(void)
 	git_reference *new_branch;
 	git_reflog *log;
 	const git_reflog_entry *entry;
+	git_signature *sig;
+
+	cl_git_pass(git_signature_default(&sig, repo));
 
 	cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
 	cl_git_pass(git_branch_move(&new_branch, branch, "master2", 0, NULL, NULL));
@@ -220,9 +228,10 @@ void test_refs_branches_move__default_reflog_message(void)
 	entry = git_reflog_entry_byindex(log, 0);
 	cl_assert_equal_s("Branch: renamed refs/heads/master to refs/heads/master2",
 			git_reflog_entry_message(entry));
+	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
 
 	git_reference_free(branch);
 	git_reference_free(new_branch);
 	git_reflog_free(log);
-
+	git_signature_free(sig);
 }
diff --git a/tests/refs/rename.c b/tests/refs/rename.c
index 63f202c..88f0afd 100644
--- a/tests/refs/rename.c
+++ b/tests/refs/rename.c
@@ -371,15 +371,20 @@ void test_refs_rename__writes_to_reflog(void)
 	git_reference *ref, *new_ref;
 	git_reflog *log;
 	const git_reflog_entry *entry;
+	git_signature *sig;
+
+	cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
 
 	cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name));
 	cl_git_pass(git_reference_rename(&new_ref, ref, ref_one_name_new, false,
-				NULL, "message"));
+				sig, "message"));
 	cl_git_pass(git_reflog_read(&log, g_repo, git_reference_name(new_ref)));
 	entry = git_reflog_entry_byindex(log, 0);
 	cl_assert_equal_s("message", git_reflog_entry_message(entry));
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry)->email);
 
 	git_reflog_free(log);
 	git_reference_free(ref);
 	git_reference_free(new_ref);
+	git_signature_free(sig);
 }
diff --git a/tests/repo/head.c b/tests/repo/head.c
index d28f254..71cfc3c 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -200,11 +200,14 @@ void test_repo_head__setting_head_updates_reflog(void)
 	git_reflog *log;
 	const git_reflog_entry *entry1, *entry2, *entry3;
 	git_object *tag;
+	git_signature *sig;
 
-	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", NULL, "message1"));
-	cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", NULL, "message2"));
+	cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, "message1"));
+	cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", sig, "message2"));
 	cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
-	cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), NULL, "message3"));
+	cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), sig, "message3"));
 
 	cl_git_pass(git_reflog_read(&log, repo, "HEAD"));
 	entry1 = git_reflog_entry_byindex(log, 2);
@@ -213,9 +216,13 @@ void test_repo_head__setting_head_updates_reflog(void)
 	cl_assert_equal_s("message1", git_reflog_entry_message(entry1));
 	cl_assert_equal_s("message2", git_reflog_entry_message(entry2));
 	cl_assert_equal_s("message3", git_reflog_entry_message(entry3));
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry1)->email);
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry2)->email);
+	cl_assert_equal_s("foo@example.com", git_reflog_entry_committer(entry3)->email);
 
 	git_reflog_free(log);
 	git_object_free(tag);
+	git_signature_free(sig);
 }
 
 void test_repo_head__setting_creates_head_ref(void)