summaryrefslogtreecommitdiff
path: root/tests/repo
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-03-19 16:30:37 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2014-03-19 16:52:20 +0100
commit6aaae94a7060834a68f3fd24d8006dbfe769e04a (patch)
treed0a9531c535c7fdbacfc77206c558222d5ae2731 /tests/repo
parentafc57eb48fc69d3e4808648c090aa6f91f9b29aa (diff)
downloadlibgit2-6aaae94a7060834a68f3fd24d8006dbfe769e04a.tar.gz
reflog: handle the birth of a branch
The reflog append function was overzealous in its checking. When passed an old and new ids, it should not do any checking, but just serialize the data to a reflog entry.
Diffstat (limited to 'tests/repo')
-rw-r--r--tests/repo/head.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/repo/head.c b/tests/repo/head.c
index 130ed8588..d68a5a61e 100644
--- a/tests/repo/head.c
+++ b/tests/repo/head.c
@@ -368,3 +368,51 @@ void test_repo_head__set_to_current_target(void)
git_signature_free(sig);
}
+
+void test_repo_head__branch_birth(void)
+{
+ git_signature *sig;
+ git_oid id;
+ git_tree *tree;
+ git_reference *ref;
+ const char *msg;
+ git_reflog *log;
+ size_t nentries, nentries_after;
+
+ cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
+ nentries = git_reflog_entrycount(log);
+ git_reflog_free(log);
+
+ cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
+
+ cl_git_pass(git_repository_head(&ref, repo));
+ cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
+ git_reference_free(ref);
+
+ msg = "message 1";
+ cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", sig, msg));
+
+ cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
+ nentries_after = git_reflog_entrycount(log);
+ git_reflog_free(log);
+
+ cl_assert_equal_i(nentries, nentries_after);
+
+ msg = "message 2";
+ cl_git_pass(git_commit_create(&id, repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL));
+
+ git_tree_free(tree);
+
+ cl_git_pass(git_reflog_read(&log, repo, "refs/heads/orphan"));
+ cl_assert_equal_i(1, git_reflog_entrycount(log));
+ git_reflog_free(log);
+
+ cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
+ nentries_after = git_reflog_entrycount(log);
+ git_reflog_free(log);
+
+ cl_assert_equal_i(nentries + 1, nentries_after);
+
+ git_signature_free(sig);
+
+}