Make overwrite test more comprehensive Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
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
diff --git a/tests/t10-refs.c b/tests/t10-refs.c
index c151104..528c29a 100644
--- a/tests/t10-refs.c
+++ b/tests/t10-refs.c
@@ -297,17 +297,33 @@ END_TEST
static const char *ref_name = "refs/heads/other";
static const char *ref_master_name = "refs/heads/master";
+static const char *ref_branch_name = "refs/heads/branch";
+static const char *ref_test_name = "refs/heads/test";
BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference")
- git_reference *ref;
+ git_reference *ref, *branch_ref;
git_repository *repo;
must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
- must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
+ /* The target needds to exist and we need to check the name has changed */
+ must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name));
+ must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_branch_name));
+ /* Ensure it points to the right place*/
+ must_pass(git_reference_lookup(&ref, repo, ref_name));
+ must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC);
+ must_be_true(!strcmp(git_reference_target(ref), ref_branch_name));
+
+ /* Ensure we can't create it unless we force it to */
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
must_pass(git_reference_create_symbolic_force(&ref, repo, ref_name, ref_master_name));
- git_reference_delete(ref);
+ /* Ensure it points to the right place */
+ must_pass(git_reference_lookup(&ref, repo, ref_name));
+ must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC);
+ must_be_true(!strcmp(git_reference_target(ref), ref_master_name));
+
+ must_pass(git_reference_delete(ref));
+ must_pass(git_reference_delete(branch_ref));
git_repository_free(repo);
END_TEST
@@ -322,10 +338,21 @@ BEGIN_TEST(overwrite1, "Overwrite an existing object id reference")
must_be_true(ref->type & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ /* Create it */
must_pass(git_reference_create_oid(&ref, repo, ref_name, &id));
+
+ must_pass(git_reference_lookup(&ref, repo, ref_test_name));
+ must_be_true(ref->type & GIT_REF_OID);
+ git_oid_cpy(&id, git_reference_oid(ref));
+
+ /* Ensure we can't overwrite unless we force it */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id));
must_pass(git_reference_create_oid_force(&ref, repo, ref_name, &id));
+ /* Ensure it has been overwritten */
+ must_pass(git_reference_lookup(&ref, repo, ref_name));
+ must_be_true(!git_oid_cmp(&id, git_reference_oid(ref)));
+
git_reference_delete(ref);
git_repository_free(repo);
END_TEST
@@ -345,6 +372,11 @@ BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symboli
must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
must_pass(git_reference_create_symbolic_force(&ref, repo, ref_name, ref_master_name));
+ /* Ensure it points to the right place */
+ must_pass(git_reference_lookup(&ref, repo, ref_name));
+ must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC);
+ must_be_true(!strcmp(git_reference_target(ref), ref_master_name));
+
git_reference_delete(ref);
git_repository_free(repo);
END_TEST
@@ -360,10 +392,17 @@ BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object
must_be_true(ref->type & GIT_REF_OID);
git_oid_cpy(&id, git_reference_oid(ref));
+ /* Create the symbolic ref */
must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name));
+ /* It shouldn't overwrite unless we tell it to */
must_fail(git_reference_create_oid(&ref, repo, ref_name, &id));
must_pass(git_reference_create_oid_force(&ref, repo, ref_name, &id));
+ /* Ensure it points to the right place */
+ must_pass(git_reference_lookup(&ref, repo, ref_name));
+ must_be_true(git_reference_type(ref) & GIT_REF_OID);
+ must_be_true(!git_oid_cmp(git_reference_oid(ref), &id));
+
git_reference_delete(ref);
git_repository_free(repo);
END_TEST