summaryrefslogtreecommitdiff
path: root/tests-clar/refs
diff options
context:
space:
mode:
authorBen Straub <bstraub@github.com>2012-07-27 11:17:21 -0700
committerBen Straub <bstraub@github.com>2012-07-27 11:17:21 -0700
commita4827a5b5c2a9d2d8a35a5a76adcc9881a11b07b (patch)
tree137edda22ef9ccdf75e847cb504a11efa2de0e18 /tests-clar/refs
parent15445f9ef7fea43a550a78c7425ae91c53a1c108 (diff)
parent31637cd56a5ed339fdebc9cd51af8f50a7794f24 (diff)
downloadlibgit2-a4827a5b5c2a9d2d8a35a5a76adcc9881a11b07b.tar.gz
Merge remote-tracking branch 'upstream/development' into test-merge
Diffstat (limited to 'tests-clar/refs')
-rw-r--r--tests-clar/refs/branches/create.c57
-rw-r--r--tests-clar/refs/branches/delete.c1
-rw-r--r--tests-clar/refs/branches/foreach.c5
-rw-r--r--tests-clar/refs/branches/lookup.c35
-rw-r--r--tests-clar/refs/branches/move.c50
-rw-r--r--tests-clar/refs/branches/tracking.c69
-rw-r--r--tests-clar/refs/foreachglob.c4
-rw-r--r--tests-clar/refs/read.c16
-rw-r--r--tests-clar/refs/reflog/drop.c130
-rw-r--r--tests-clar/refs/reflog/reflog.c (renamed from tests-clar/refs/reflog.c)122
-rw-r--r--tests-clar/refs/remotetracking.c49
-rw-r--r--tests-clar/refs/revparse.c43
12 files changed, 396 insertions, 185 deletions
diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c
index ad7e1fd2c..fe72d4708 100644
--- a/tests-clar/refs/branches/create.c
+++ b/tests-clar/refs/branches/create.c
@@ -1,19 +1,22 @@
#include "clar_libgit2.h"
#include "refs.h"
-#include "branch.h"
static git_repository *repo;
-static git_oid branch_target_oid;
static git_object *target;
+static git_reference *branch;
void test_refs_branches_create__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+
+ branch = NULL;
}
void test_refs_branches_create__cleanup(void)
{
+ git_reference_free(branch);
+
git_object_free(target);
git_repository_free(repo);
@@ -39,54 +42,24 @@ void test_refs_branches_create__can_create_a_local_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
- cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
-}
-
-void test_refs_branches_create__creating_a_local_branch_triggers_the_creation_of_a_new_direct_reference(void)
-{
- git_reference *branch;
-
- retrieve_known_commit(&target, repo);
-
- cl_git_fail(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));
-
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
-
- cl_git_pass(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));
- cl_assert(git_reference_type(branch) == GIT_REF_OID);
-
- git_reference_free(branch);
+ cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
+ cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target)));
}
void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void)
{
retrieve_known_commit(&target, repo);
- cl_git_fail(git_branch_create(&branch_target_oid, repo, "br2", target, 0));
+ cl_git_fail(git_branch_create(&branch, repo, "br2", target, 0));
}
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
retrieve_known_commit(&target, repo);
- cl_git_pass(git_branch_create(&branch_target_oid, repo, "br2", target, 1));
- cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
-}
-
-void test_refs_branches_create__can_not_create_a_branch_pointing_at_an_object_unknown_from_the_repository(void)
-{
- git_repository *repo2;
-
- /* Open another instance of the same repository */
- cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git")));
-
- /* Retrieve a commit object from this different repository */
- retrieve_known_commit(&target, repo2);
-
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
-
- git_repository_free(repo2);
+ cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
+ cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target)));
+ cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
}
void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_it_to_its_commit(void)
@@ -94,8 +67,8 @@ void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_i
/* b25fa35 is a tag, pointing to another tag which points to a commit */
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
- cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
- cl_git_pass(git_oid_streq(&branch_target_oid, "e90810b8df3e80c413d903f631643c716887138d"));
+ cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
+ cl_git_pass(git_oid_streq(git_reference_oid(branch), "e90810b8df3e80c413d903f631643c716887138d"));
}
void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit_object(void)
@@ -103,11 +76,11 @@ void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit
/* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
+ cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
- cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
+ cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
}
diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c
index 03d3c56d7..699655f27 100644
--- a/tests-clar/refs/branches/delete.c
+++ b/tests-clar/refs/branches/delete.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "refs.h"
-#include "branch.h"
static git_repository *repo;
static git_reference *fake_remote;
diff --git a/tests-clar/refs/branches/foreach.c b/tests-clar/refs/branches/foreach.c
index b6e973799..794233cc9 100644
--- a/tests-clar/refs/branches/foreach.c
+++ b/tests-clar/refs/branches/foreach.c
@@ -1,6 +1,5 @@
#include "clar_libgit2.h"
#include "refs.h"
-#include "branch.h"
static git_repository *repo;
static git_reference *fake_remote;
@@ -48,7 +47,7 @@ static void assert_retrieval(unsigned int flags, unsigned int expected_count)
void test_refs_branches_foreach__retrieve_all_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 10);
+ assert_retrieval(GIT_BRANCH_LOCAL | GIT_BRANCH_REMOTE, 11);
}
void test_refs_branches_foreach__retrieve_remote_branches(void)
@@ -58,7 +57,7 @@ void test_refs_branches_foreach__retrieve_remote_branches(void)
void test_refs_branches_foreach__retrieve_local_branches(void)
{
- assert_retrieval(GIT_BRANCH_LOCAL, 8);
+ assert_retrieval(GIT_BRANCH_LOCAL, 9);
}
struct expectations {
diff --git a/tests-clar/refs/branches/lookup.c b/tests-clar/refs/branches/lookup.c
new file mode 100644
index 000000000..2aabf9889
--- /dev/null
+++ b/tests-clar/refs/branches/lookup.c
@@ -0,0 +1,35 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *branch;
+
+void test_refs_branches_lookup__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ branch = NULL;
+}
+
+void test_refs_branches_lookup__cleanup(void)
+{
+ git_reference_free(branch);
+
+ git_repository_free(repo);
+}
+
+void test_refs_branches_lookup__can_retrieve_a_local_branch(void)
+{
+ cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL));
+}
+
+void test_refs_branches_lookup__can_retrieve_a_remote_tracking_branch(void)
+{
+ cl_git_pass(git_branch_lookup(&branch, repo, "test/master", GIT_BRANCH_REMOTE));
+}
+
+void test_refs_branches_lookup__trying_to_retrieve_an_unknown_branch_returns_ENOTFOUND(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "where/are/you", GIT_BRANCH_LOCAL));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_lookup(&branch, repo, "over/here", GIT_BRANCH_REMOTE));
+}
diff --git a/tests-clar/refs/branches/move.c b/tests-clar/refs/branches/move.c
index 242e5cd01..6750473e1 100644
--- a/tests-clar/refs/branches/move.c
+++ b/tests-clar/refs/branches/move.c
@@ -1,72 +1,64 @@
#include "clar_libgit2.h"
-#include "branch.h"
+#include "refs.h"
static git_repository *repo;
+static git_reference *ref;
void test_refs_branches_move__initialize(void)
{
- cl_fixture_sandbox("testrepo.git");
- cl_git_pass(git_repository_open(&repo, "testrepo.git"));
+ repo = cl_git_sandbox_init("testrepo.git");
+
+ cl_git_pass(git_reference_lookup(&ref, repo, "refs/heads/br2"));
}
void test_refs_branches_move__cleanup(void)
{
- git_repository_free(repo);
-
- cl_fixture_cleanup("testrepo.git");
+ git_reference_free(ref);
+ cl_git_sandbox_cleanup();
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
void test_refs_branches_move__can_move_a_local_branch(void)
{
- cl_git_pass(git_branch_move(repo, "br2", NEW_BRANCH_NAME, 0));
+ cl_git_pass(git_branch_move(ref, NEW_BRANCH_NAME, 0));
+ cl_assert_equal_s(GIT_REFS_HEADS_DIR NEW_BRANCH_NAME, git_reference_name(ref));
}
void test_refs_branches_move__can_move_a_local_branch_to_a_different_namespace(void)
{
/* Downward */
- cl_git_pass(git_branch_move(repo, "br2", "somewhere/" NEW_BRANCH_NAME, 0));
+ cl_git_pass(git_branch_move(ref, "somewhere/" NEW_BRANCH_NAME, 0));
/* Upward */
- cl_git_pass(git_branch_move(repo, "somewhere/" NEW_BRANCH_NAME, "br2", 0));
+ cl_git_pass(git_branch_move(ref, "br2", 0));
}
void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_namespace(void)
{
/* Downward */
- cl_git_pass(git_branch_move(repo, "br2", "br2/" NEW_BRANCH_NAME, 0));
+ cl_git_pass(git_branch_move(ref, "br2/" NEW_BRANCH_NAME, 0));
/* Upward */
- cl_git_pass(git_branch_move(repo, "br2/" NEW_BRANCH_NAME, "br2", 0));
+ cl_git_pass(git_branch_move(ref, "br2", 0));
}
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
{
- cl_git_fail(git_branch_move(repo, "br2", "master", 0));
+ cl_git_fail(git_branch_move(ref, "master", 0));
}
-void test_refs_branches_move__can_not_move_a_non_existing_branch(void)
+void test_refs_branches_move__can_not_move_a_non_branch(void)
{
- cl_git_fail(git_branch_move(repo, "i-am-no-branch", NEW_BRANCH_NAME, 0));
-}
+ git_reference *tag;
-void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
-{
- cl_git_pass(git_branch_move(repo, "br2", "master", 1));
-}
+ cl_git_pass(git_reference_lookup(&tag, repo, "refs/tags/e90810b"));
+ cl_git_fail(git_branch_move(tag, NEW_BRANCH_NAME, 0));
-void test_refs_branches_move__can_not_move_a_branch_through_its_canonical_name(void)
-{
- cl_git_fail(git_branch_move(repo, "refs/heads/br2", NEW_BRANCH_NAME, 1));
+ git_reference_free(tag);
}
-void test_refs_branches_move__moving_a_non_exisiting_branch_returns_ENOTFOUND(void)
+void test_refs_branches_move__can_force_move_over_an_existing_branch(void)
{
- int error;
-
- error = git_branch_move(repo, "where/am/I", NEW_BRANCH_NAME, 0);
- cl_git_fail(error);
-
- cl_assert_equal_i(GIT_ENOTFOUND, error);
+ cl_git_pass(git_branch_move(ref, "master", 1));
}
diff --git a/tests-clar/refs/branches/tracking.c b/tests-clar/refs/branches/tracking.c
new file mode 100644
index 000000000..8f7019437
--- /dev/null
+++ b/tests-clar/refs/branches/tracking.c
@@ -0,0 +1,69 @@
+#include "clar_libgit2.h"
+#include "refs.h"
+
+static git_repository *repo;
+static git_reference *branch;
+
+void test_refs_branches_tracking__initialize(void)
+{
+ cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
+
+ branch = NULL;
+}
+
+void test_refs_branches_tracking__cleanup(void)
+{
+ git_reference_free(branch);
+
+ git_repository_free(repo);
+}
+
+void test_refs_branches_tracking__can_retrieve_the_remote_tracking_reference_of_a_local_branch(void)
+{
+ git_reference *branch, *tracking;
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
+
+ cl_git_pass(git_branch_tracking(&tracking, branch));
+
+ cl_assert_equal_s("refs/remotes/test/master", git_reference_name(tracking));
+
+ git_reference_free(branch);
+ git_reference_free(tracking);
+}
+
+void test_refs_branches_tracking__can_retrieve_the_local_tracking_reference_of_a_local_branch(void)
+{
+ git_reference *branch, *tracking;
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/track-local"));
+
+ cl_git_pass(git_branch_tracking(&tracking, branch));
+
+ cl_assert_equal_s("refs/heads/master", git_reference_name(tracking));
+
+ git_reference_free(branch);
+ git_reference_free(tracking);
+}
+
+void test_refs_branches_tracking__cannot_retrieve_a_remote_tracking_reference_from_a_non_branch(void)
+{
+ git_reference *branch, *tracking;
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
+
+ cl_git_fail(git_branch_tracking(&tracking, branch));
+
+ git_reference_free(branch);
+}
+
+void test_refs_branches_tracking__trying_to_retrieve_a_remote_tracking_reference_from_a_plain_local_branch_returns_GIT_ENOTFOUND(void)
+{
+ git_reference *branch, *tracking;
+
+ cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/subtrees"));
+
+ cl_assert_equal_i(GIT_ENOTFOUND, git_branch_tracking(&tracking, branch));
+
+ git_reference_free(branch);
+}
diff --git a/tests-clar/refs/foreachglob.c b/tests-clar/refs/foreachglob.c
index d1412a94b..b024d36d4 100644
--- a/tests-clar/refs/foreachglob.c
+++ b/tests-clar/refs/foreachglob.c
@@ -46,7 +46,7 @@ static void assert_retrieval(const char *glob, unsigned int flags, int expected_
void test_refs_foreachglob__retrieve_all_refs(void)
{
/* 7 heads (including one packed head) + 1 note + 2 remotes + 6 tags */
- assert_retrieval("*", GIT_REF_LISTALL, 17);
+ assert_retrieval("*", GIT_REF_LISTALL, 18);
}
void test_refs_foreachglob__retrieve_remote_branches(void)
@@ -56,7 +56,7 @@ void test_refs_foreachglob__retrieve_remote_branches(void)
void test_refs_foreachglob__retrieve_local_branches(void)
{
- assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 8);
+ assert_retrieval("refs/heads/*", GIT_REF_LISTALL, 9);
}
void test_refs_foreachglob__retrieve_partially_named_references(void)
diff --git a/tests-clar/refs/read.c b/tests-clar/refs/read.c
index ce4eefeba..1948e0a56 100644
--- a/tests-clar/refs/read.c
+++ b/tests-clar/refs/read.c
@@ -202,3 +202,19 @@ void test_refs_read__unfound_return_ENOTFOUND(void)
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/master"));
cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&reference, g_repo, "refs/tags/test/farther/master"));
}
+
+static void assert_is_branch(const char *name, bool expected_branchness)
+{
+ git_reference *reference;
+ cl_git_pass(git_reference_lookup(&reference, g_repo, name));
+ cl_assert_equal_i(expected_branchness, git_reference_is_branch(reference));
+ git_reference_free(reference);
+}
+
+void test_refs_read__can_determine_if_a_reference_is_a_local_branch(void)
+{
+ assert_is_branch("refs/heads/master", true);
+ assert_is_branch("refs/heads/packed", true);
+ assert_is_branch("refs/remotes/test/master", false);
+ assert_is_branch("refs/tags/e90810b", false);
+}
diff --git a/tests-clar/refs/reflog/drop.c b/tests-clar/refs/reflog/drop.c
new file mode 100644
index 000000000..86781c041
--- /dev/null
+++ b/tests-clar/refs/reflog/drop.c
@@ -0,0 +1,130 @@
+#include "clar_libgit2.h"
+
+#include "reflog.h"
+
+static git_repository *g_repo;
+static git_reflog *g_reflog;
+static unsigned int entrycount;
+
+void test_refs_reflog_drop__initialize(void)
+{
+ git_reference *ref;
+
+ g_repo = cl_git_sandbox_init("testrepo.git");
+ cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
+
+ git_reflog_read(&g_reflog, ref);
+ entrycount = git_reflog_entrycount(g_reflog);
+
+ git_reference_free(ref);
+}
+
+void test_refs_reflog_drop__cleanup(void)
+{
+ git_reflog_free(g_reflog);
+
+ cl_git_sandbox_cleanup();
+}
+
+void test_refs_reflog_drop__dropping_a_non_exisiting_entry_from_the_log_returns_ENOTFOUND(void)
+{
+ cl_assert_equal_i(GIT_ENOTFOUND, git_reflog_drop(g_reflog, entrycount, 0));
+
+ cl_assert_equal_i(entrycount, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_drop_an_entry(void)
+{
+ cl_assert(entrycount > 4);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 2, 0));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_drop_an_entry_and_rewrite_the_log_history(void)
+{
+ const git_reflog_entry *before_previous, *before_next;
+ const git_reflog_entry *after_next;
+ git_oid before_next_old_oid;
+
+ cl_assert(entrycount > 4);
+
+ before_previous = git_reflog_entry_byindex(g_reflog, 3);
+ before_next = git_reflog_entry_byindex(g_reflog, 1);
+ git_oid_cpy(&before_next_old_oid, &before_next->oid_old);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 2, 1));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ after_next = git_reflog_entry_byindex(g_reflog, 1);
+
+ cl_assert_equal_i(0, git_oid_cmp(&before_next->oid_cur, &after_next->oid_cur));
+ cl_assert(git_oid_cmp(&before_next_old_oid, &after_next->oid_old) != 0);
+ cl_assert_equal_i(0, git_oid_cmp(&before_previous->oid_cur, &after_next->oid_old));
+}
+
+void test_refs_reflog_drop__can_drop_the_first_entry(void)
+{
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 0, 0));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_drop_the_last_entry(void)
+{
+ const git_reflog_entry *entry;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 0));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0);
+}
+
+void test_refs_reflog_drop__can_drop_the_last_entry_and_rewrite_the_log_history(void)
+{
+ const git_reflog_entry *entry;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+
+ entry = git_reflog_entry_byindex(g_reflog, entrycount - 2);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+}
+
+void test_refs_reflog_drop__can_drop_all_the_entries(void)
+{
+ cl_assert(--entrycount > 0);
+
+ do {
+ cl_git_pass(git_reflog_drop(g_reflog, --entrycount, 1));
+ } while (entrycount > 0);
+
+ cl_git_pass(git_reflog_drop(g_reflog, 0, 1));
+
+ cl_assert_equal_i(0, git_reflog_entrycount(g_reflog));
+}
+
+void test_refs_reflog_drop__can_persist_deletion_on_disk(void)
+{
+ git_reference *ref;
+
+ cl_assert(entrycount > 2);
+
+ cl_git_pass(git_reference_lookup(&ref, g_repo, g_reflog->ref_name));
+ cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1));
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+ cl_git_pass(git_reflog_write(g_reflog));
+
+ git_reflog_free(g_reflog);
+
+ git_reflog_read(&g_reflog, ref);
+ git_reference_free(ref);
+
+ cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog));
+}
diff --git a/tests-clar/refs/reflog.c b/tests-clar/refs/reflog/reflog.c
index 05f3786bb..20f08f523 100644
--- a/tests-clar/refs/reflog.c
+++ b/tests-clar/refs/reflog/reflog.c
@@ -7,7 +7,7 @@
static const char *new_ref = "refs/heads/test-reflog";
static const char *current_master_tip = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
-static const char *commit_msg = "commit: bla bla";
+#define commit_msg "commit: bla bla"
static git_repository *g_repo;
@@ -24,66 +24,60 @@ static void assert_signature(git_signature *expected, git_signature *actual)
// Fixture setup and teardown
-void test_refs_reflog__initialize(void)
+void test_refs_reflog_reflog__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
}
-void test_refs_reflog__cleanup(void)
+void test_refs_reflog_reflog__cleanup(void)
{
cl_git_sandbox_cleanup();
}
-
-
-void test_refs_reflog__write_then_read(void)
+void test_refs_reflog_reflog__append_then_read(void)
{
// write a reflog for a given reference and ensure it can be read back
- git_repository *repo2;
+ git_repository *repo2;
git_reference *ref, *lookedup_ref;
git_oid oid;
git_signature *committer;
git_reflog *reflog;
- git_reflog_entry *entry;
- char oid_str[GIT_OID_HEXSZ+1];
+ const git_reflog_entry *entry;
/* Create a new branch pointing at the HEAD */
git_oid_fromstr(&oid, current_master_tip);
cl_git_pass(git_reference_create_oid(&ref, g_repo, new_ref, &oid, 0));
- git_reference_free(ref);
- cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
- cl_git_pass(git_reflog_write(ref, NULL, committer, NULL));
- cl_git_fail(git_reflog_write(ref, NULL, committer, "no ancestor NULL for an existing reflog"));
- cl_git_fail(git_reflog_write(ref, NULL, committer, "no\nnewline"));
- cl_git_pass(git_reflog_write(ref, &oid, committer, commit_msg));
+ cl_git_pass(git_reflog_read(&reflog, ref));
+
+ cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline"));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL));
+ cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n"));
+ cl_git_pass(git_reflog_write(reflog));
+ git_reflog_free(reflog);
/* Reopen a new instance of the repository */
cl_git_pass(git_repository_open(&repo2, "testrepo.git"));
- /* Lookup the preivously created branch */
+ /* Lookup the previously created branch */
cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref));
/* Read and parse the reflog for this branch */
cl_git_pass(git_reflog_read(&reflog, lookedup_ref));
- cl_assert(reflog->entries.length == 2);
+ cl_assert_equal_i(2, git_reflog_entrycount(reflog));
- entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0);
+ entry = git_reflog_entry_byindex(reflog, 0);
assert_signature(committer, entry->committer);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
- cl_assert_equal_s("0000000000000000000000000000000000000000", oid_str);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
- cl_assert_equal_s(current_master_tip, oid_str);
+ cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
cl_assert(entry->msg == NULL);
- entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1);
+ entry = git_reflog_entry_byindex(reflog, 1);
assert_signature(committer, entry->committer);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old);
- cl_assert_equal_s(current_master_tip, oid_str);
- git_oid_tostr(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur);
- cl_assert_equal_s(current_master_tip, oid_str);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_old) == 0);
+ cl_assert(git_oid_cmp(&oid, &entry->oid_cur) == 0);
cl_assert_equal_s(commit_msg, entry->msg);
git_signature_free(committer);
@@ -94,35 +88,7 @@ void test_refs_reflog__write_then_read(void)
git_reference_free(lookedup_ref);
}
-void test_refs_reflog__dont_write_bad(void)
-{
- // avoid writing an obviously wrong reflog
- git_reference *ref;
- git_oid oid;
- git_signature *committer;
-
- /* Create a new branch pointing at the HEAD */
- git_oid_fromstr(&oid, current_master_tip);
- cl_git_pass(git_reference_create_oid(&ref, g_repo, new_ref, &oid, 0));
- git_reference_free(ref);
- cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref));
-
- cl_git_pass(git_signature_now(&committer, "foo", "foo@bar"));
-
- /* Write the reflog for the new branch */
- cl_git_pass(git_reflog_write(ref, NULL, committer, NULL));
-
- /* Try to update the reflog with wrong information:
- * It's no new reference, so the ancestor OID cannot
- * be NULL. */
- cl_git_fail(git_reflog_write(ref, NULL, committer, NULL));
-
- git_signature_free(committer);
-
- git_reference_free(ref);
-}
-
-void test_refs_reflog__renaming_the_reference_moves_the_reflog(void)
+void test_refs_reflog_reflog__renaming_the_reference_moves_the_reflog(void)
{
git_reference *master;
git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
@@ -145,6 +111,7 @@ void test_refs_reflog__renaming_the_reference_moves_the_reflog(void)
git_buf_free(&moved_log_path);
git_buf_free(&master_log_path);
}
+
static void assert_has_reflog(bool expected_result, const char *name)
{
git_reference *ref;
@@ -156,9 +123,50 @@ static void assert_has_reflog(bool expected_result, const char *name)
git_reference_free(ref);
}
-void test_refs_reflog__reference_has_reflog(void)
+void test_refs_reflog_reflog__reference_has_reflog(void)
{
assert_has_reflog(true, "HEAD");
assert_has_reflog(true, "refs/heads/master");
assert_has_reflog(false, "refs/heads/subtrees");
}
+
+void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_returns_an_empty_one(void)
+{
+ git_reference *subtrees;
+ git_reflog *reflog;
+ git_buf subtrees_log_path = GIT_BUF_INIT;
+
+ cl_git_pass(git_reference_lookup(&subtrees, g_repo, "refs/heads/subtrees"));
+
+ git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, git_reference_name(subtrees));
+ cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path)));
+
+ cl_git_pass(git_reflog_read(&reflog, subtrees));
+
+ cl_assert_equal_i(0, git_reflog_entrycount(reflog));
+
+ git_reflog_free(reflog);
+ git_reference_free(subtrees);
+ git_buf_free(&subtrees_log_path);
+}
+
+void test_refs_reflog_reflog__cannot_write_a_moved_reflog(void)
+{
+ git_reference *master;
+ git_buf master_log_path = GIT_BUF_INIT, moved_log_path = GIT_BUF_INIT;
+ git_reflog *reflog;
+
+ cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master"));
+ cl_git_pass(git_reflog_read(&reflog, master));
+
+ cl_git_pass(git_reflog_write(reflog));
+
+ cl_git_pass(git_reference_rename(master, "refs/moved", 0));
+
+ cl_git_fail(git_reflog_write(reflog));
+
+ git_reflog_free(reflog);
+ git_reference_free(master);
+ git_buf_free(&moved_log_path);
+ git_buf_free(&master_log_path);
+}
diff --git a/tests-clar/refs/remotetracking.c b/tests-clar/refs/remotetracking.c
deleted file mode 100644
index c4ec588ee..000000000
--- a/tests-clar/refs/remotetracking.c
+++ /dev/null
@@ -1,49 +0,0 @@
-#include "clar_libgit2.h"
-
-static git_repository *g_repo;
-
-void test_refs_remotetracking__initialize(void)
-{
- cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
-}
-
-void test_refs_remotetracking__cleanup(void)
-{
- git_repository_free(g_repo);
-}
-
-void test_refs_remotetracking__unfound_returns_GIT_ENOTFOUND(void)
-{
- git_reference *branch, *tracking;
-
- cl_git_pass(git_reference_lookup(&branch, g_repo, "refs/heads/subtrees"));
-
- cl_assert_equal_i(GIT_ENOTFOUND, git_reference_remote_tracking_from_branch(&tracking, branch));
-
- git_reference_free(branch);
-}
-
-void test_refs_remotetracking__retrieving_from_a_non_head_fails(void)
-{
- git_reference *branch, *tracking;
-
- cl_git_pass(git_reference_lookup(&branch, g_repo, "refs/tags/e90810b"));
-
- cl_git_fail(git_reference_remote_tracking_from_branch(&tracking, branch));
-
- git_reference_free(branch);
-}
-
-void test_refs_remotetracking__can_retrieve_a_remote_tracking_branch_reference(void)
-{
- git_reference *branch, *tracking;
-
- cl_git_pass(git_reference_lookup(&branch, g_repo, "refs/heads/master"));
-
- cl_git_pass(git_reference_remote_tracking_from_branch(&tracking, branch));
-
- cl_assert_equal_s("refs/remotes/test/master", git_reference_name(tracking));
-
- git_reference_free(branch);
- git_reference_free(tracking);
-}
diff --git a/tests-clar/refs/revparse.c b/tests-clar/refs/revparse.c
index 56d57b21c..02acb8844 100644
--- a/tests-clar/refs/revparse.c
+++ b/tests-clar/refs/revparse.c
@@ -64,6 +64,8 @@ void test_refs_revparse__invalid_reference_name(void)
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense^1"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "this doesn't make sense~2"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, ""));
+
}
void test_refs_revparse__shas(void)
@@ -75,6 +77,9 @@ void test_refs_revparse__shas(void)
void test_refs_revparse__head(void)
{
test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD^0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("HEAD~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
}
void test_refs_revparse__full_refs(void)
@@ -99,12 +104,18 @@ void test_refs_revparse__describe_output(void)
void test_refs_revparse__nth_parent(void)
{
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "be3563a^-1"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "^"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "be3563a^{tree}^"));
+
test_object("be3563a^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
test_object("be3563a^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
test_object("be3563a^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
test_object("be3563a^1^1", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
+ test_object("be3563a^^", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
test_object("be3563a^2^1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
test_object("be3563a^0", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("be3563a^{commit}^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
test_object("be3563a^42", NULL);
}
@@ -113,34 +124,56 @@ void test_refs_revparse__not_tag(void)
{
test_object("point_to_blob^{}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
test_object("wrapped_tag^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
+ test_object("master^{tree}^{}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
+ test_object("e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
+ test_object("tags/e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
+ test_object("e908^{}", "e90810b8df3e80c413d903f631643c716887138d");
}
void test_refs_revparse__to_type(void)
{
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{trip}"));
+
test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
test_object("point_to_blob^{blob}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
-
- cl_git_fail(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
+ test_object("master^{commit}^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
}
void test_refs_revparse__linear_history(void)
{
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "~"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "foo~bar"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "master~bar"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "master~-1"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "master~0bar"));
test_object("master~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
test_object("master~1", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
test_object("master~2", "9fd738e8f7967c078dceed8190330fc8648ee56a");
test_object("master~1~1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("master~~", "9fd738e8f7967c078dceed8190330fc8648ee56a");
}
void test_refs_revparse__chaining(void)
{
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{0}@{0}"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{u}@{-1}"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-1}@{-1}"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-3}@{0}"));
+
+ test_object("master@{0}~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
+ test_object("@{u}@{0}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
+ test_object("@{-1}@{0}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
+ test_object("@{-4}@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
test_object("master~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
test_object("master~1^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
test_object("master^1^2~1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
+ test_object("master^^2^", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
test_object("master^1^1^1^1^1", "8496071c1b46c854b31185ea97743be6a8774479");
+ test_object("master^^1^2^1", NULL);
}
void test_refs_revparse__upstream(void)
@@ -158,6 +191,10 @@ void test_refs_revparse__upstream(void)
void test_refs_revparse__ordinal(void)
{
cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{-2}"));
+
+ /* TODO: make the test below actually fail
+ * cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
+ */
test_object("nope@{0}", NULL);
test_object("master@{31415}", NULL);
@@ -177,6 +214,7 @@ void test_refs_revparse__previous_head(void)
{
cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-xyz}"));
cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-0}"));
+ cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-1b}"));
test_object("@{-42}", NULL);
@@ -353,6 +391,7 @@ void test_refs_revparse__colon(void)
test_object(":/one", "c47800c7266a2be04c571c04d5a6614691ea99bd");
test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9");
test_object("test/master^2:branch_file.txt", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
+ test_object("test/master@{1}:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
}
void test_refs_revparse__disambiguation(void)