Enhance testing of signature parameters
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
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)