Commit a5815a2a by Carlos Martín Nieto

Add tests for the annotated versions of ref-modifying functions

This also brings the soft-reset tests back to life. The function name
was missing an underscore, meaning they had not been running.
parent 62dd4d71
...@@ -97,6 +97,7 @@ void test_refs_branches_create__default_reflog_message(void) ...@@ -97,6 +97,7 @@ void test_refs_branches_create__default_reflog_message(void)
git_reflog *log; git_reflog *log;
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
const git_reflog_entry *entry; const git_reflog_entry *entry;
git_annotated_commit *annotated;
git_signature *sig; git_signature *sig;
git_config *cfg; git_config *cfg;
...@@ -116,6 +117,21 @@ void test_refs_branches_create__default_reflog_message(void) ...@@ -116,6 +117,21 @@ void test_refs_branches_create__default_reflog_message(void)
cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry)); cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email); cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
cl_git_pass(git_reference_remove(repo, "refs/heads/" NEW_BRANCH_NAME));
git_reference_free(branch);
git_reflog_free(log);
git_buf_clear(&buf);
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "e90810b8df3"));
cl_git_pass(git_branch_create_from_annotated(&branch, repo, NEW_BRANCH_NAME, annotated, true));
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
entry = git_reflog_entry_byindex(log, 0);
cl_git_pass(git_buf_printf(&buf, "branch: Created from e90810b8df3"));
cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
git_annotated_commit_free(annotated);
git_buf_free(&buf); git_buf_free(&buf);
git_reflog_free(log); git_reflog_free(log);
git_signature_free(sig); git_signature_free(sig);
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "refs.h" #include "refs.h"
#include "repo_helpers.h" #include "repo_helpers.h"
#include "posix.h" #include "posix.h"
#include "git2/annotated_commit.h"
static const char *g_email = "foo@example.com"; static const char *g_email = "foo@example.com";
static git_repository *repo; static git_repository *repo;
...@@ -251,6 +252,7 @@ void test_repo_head__setting_head_updates_reflog(void) ...@@ -251,6 +252,7 @@ void test_repo_head__setting_head_updates_reflog(void)
{ {
git_object *tag; git_object *tag;
git_signature *sig; git_signature *sig;
git_annotated_commit *annotated;
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com")); cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
...@@ -264,6 +266,12 @@ void test_repo_head__setting_head_updates_reflog(void) ...@@ -264,6 +266,12 @@ void test_repo_head__setting_head_updates_reflog(void)
test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d"); test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked"); test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "haacked~0"));
cl_git_pass(git_repository_set_head_detached_from_annotated(repo, annotated));
test_reflog(repo, 0, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from haacked to haacked~0");
git_annotated_commit_free(annotated);
git_object_free(tag); git_object_free(tag);
git_signature_free(sig); git_signature_free(sig);
} }
......
...@@ -201,6 +201,7 @@ void test_reset_hard__cleans_up_merge(void) ...@@ -201,6 +201,7 @@ void test_reset_hard__cleans_up_merge(void)
void test_reset_hard__reflog_is_correct(void) void test_reset_hard__reflog_is_correct(void)
{ {
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Add a file which name should appear before the " const char *exp_msg = "commit: Add a file which name should appear before the "
"\"subdir/\" folder while being dealt with by the treewalker"; "\"subdir/\" folder while being dealt with by the treewalker";
...@@ -215,7 +216,7 @@ void test_reset_hard__reflog_is_correct(void) ...@@ -215,7 +216,7 @@ void test_reset_hard__reflog_is_correct(void)
git_object_free(target); git_object_free(target);
/* Moved branch, expect default message */ /* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}")); cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target)))); cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL)); cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
...@@ -223,4 +224,14 @@ void test_reset_hard__reflog_is_correct(void) ...@@ -223,4 +224,14 @@ void test_reset_hard__reflog_is_correct(void)
reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf)); reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));
git_buf_free(&buf); git_buf_free(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_HARD, NULL));
reflog_check(repo, "HEAD", 5, NULL, exp_msg);
reflog_check(repo, "refs/heads/master", 5, NULL, exp_msg);
git_annotated_commit_free(annotated);
} }
...@@ -51,6 +51,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void) ...@@ -51,6 +51,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
void test_reset_mixed__reflog_is_correct(void) void test_reset_mixed__reflog_is_correct(void)
{ {
git_buf buf = GIT_BUF_INIT; git_buf buf = GIT_BUF_INIT;
git_annotated_commit *annotated;
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context"; const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
...@@ -65,13 +66,20 @@ void test_reset_mixed__reflog_is_correct(void) ...@@ -65,13 +66,20 @@ void test_reset_mixed__reflog_is_correct(void)
git_object_free(target); git_object_free(target);
target = NULL; target = NULL;
/* Moved branch, expect default message */ /* Moved branch, expect id in message */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}")); cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
git_buf_clear(&buf); git_buf_clear(&buf);
cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target)))); cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL)); cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf)); reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf)); reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
git_buf_free(&buf); git_buf_free(&buf);
/* Moved branch, expect revspec in message */
exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_MIXED, NULL));
reflog_check(repo, "HEAD", 11, NULL, exp_msg);
reflog_check(repo, "refs/heads/master", 11, NULL, exp_msg);
git_annotated_commit_free(annotated);
} }
...@@ -155,28 +155,35 @@ void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE ...@@ -155,28 +155,35 @@ void test_reset_soft__fails_when_index_contains_conflicts_independently_of_MERGE
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL)); cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT, NULL));
} }
void test_reset_soft_reflog_is_correct(void) void test_reset_soft__reflog_is_correct(void)
{ {
const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context"; git_annotated_commit *annotated;
const char *exp_msg = "checkout: moving from br2 to master";
const char *master_msg = "commit: checking in";
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "HEAD", 7, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "refs/heads/master", 2, "yoram.harmelin@gmail.com", master_msg);
/* Branch not moving, no reflog entry */ /* Branch not moving, no reflog entry */
cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}")); cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL)); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "HEAD", 7, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "refs/heads/master", 2, "yoram.harmelin@gmail.com", master_msg);
git_object_free(target);
/* Moved branch, expect default message */ /* Moved branch, expect id in message */
exp_msg = "reset: moving to be3563ae3f795b2b4353bcce3a527ad0a4f7f644";
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}")); cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL)); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "HEAD", 8, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 10, NULL, "reset: moving"); reflog_check(repo, "refs/heads/master", 3, NULL, exp_msg);
/* Moved branch, expect custom message */ /* Moved branch, expect message with annotated string */
cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}")); exp_msg = "reset: moving to HEAD~^{commit}";
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT, NULL)); cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_SOFT, NULL));
reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg); reflog_check(repo, "HEAD", 9, "yoram.harmelin@gmail.com", exp_msg);
reflog_check(repo, "refs/heads/master", 11, NULL, "message1"); reflog_check(repo, "refs/heads/master", 4, NULL, exp_msg);
git_annotated_commit_free(annotated);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment