Hash :
f44fd59e
Author :
Date :
2014-02-05T11:21:14
refs: check the ref's old value when deleting Recognize when the reference has changed since we loaded it.
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
#include "clar_libgit2.h"
#include "repository.h"
#include "git2/reflog.h"
#include "reflog.h"
#include "ref_helpers.h"
static const char *commit_id = "099fabac3a9ea935598528c27f866e34089c2eff";
static const char *refname = "refs/heads/master";
static const char *other_refname = "refs/heads/foo";
static const char *other_commit_id = "a65fedf39aefe402d3bb6e24df4d4f5fe4547750";
static git_repository *g_repo;
void test_refs_races__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_refs_races__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_refs_races__create_matching(void)
{
git_reference *ref, *ref2, *ref3;
git_oid id, other_id;
git_oid_fromstr(&id, commit_id);
git_oid_fromstr(&other_id, other_commit_id);
cl_git_fail_with(GIT_EMODIFIED, git_reference_create_matching(&ref, g_repo, refname, &other_id, 1, NULL, NULL, &other_id));
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, NULL, NULL, &id));
cl_git_fail_with(GIT_EMODIFIED, git_reference_set_target(&ref3, ref, &other_id, NULL, NULL));
git_reference_free(ref);
git_reference_free(ref2);
git_reference_free(ref3);
}
void test_refs_races__symbolic_create_matching(void)
{
git_reference *ref, *ref2, *ref3;
git_oid id, other_id;
git_oid_fromstr(&id, commit_id);
git_oid_fromstr(&other_id, other_commit_id);
cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_create_matching(&ref, g_repo, "HEAD", other_refname, 1, NULL, NULL, other_refname));
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, NULL, refname));
cl_git_fail_with(GIT_EMODIFIED, git_reference_symbolic_set_target(&ref3, ref, other_refname, NULL, NULL));
git_reference_free(ref);
git_reference_free(ref2);
git_reference_free(ref3);
}
void test_refs_races__delete(void)
{
git_reference *ref, *ref2;
git_oid id, other_id;
git_oid_fromstr(&id, commit_id);
git_oid_fromstr(&other_id, other_commit_id);
/* We can delete a value that matches */
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
cl_git_pass(git_reference_delete(ref));
git_reference_free(ref);
/* We cannot delete a symbolic value that doesn't match */
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
cl_git_pass(git_reference_symbolic_create_matching(&ref2, g_repo, "HEAD", other_refname, 1, NULL, NULL, refname));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
git_reference_free(ref2);
cl_git_pass(git_reference_create(&ref, g_repo, refname, &id, 1, NULL, NULL));
git_reference_free(ref);
/* We cannot delete an oid value that doesn't match */
cl_git_pass(git_reference_lookup(&ref, g_repo, refname));
cl_git_pass(git_reference_create_matching(&ref2, g_repo, refname, &other_id, 1, NULL, NULL, &id));
cl_git_fail_with(GIT_EMODIFIED, git_reference_delete(ref));
git_reference_free(ref);
git_reference_free(ref2);
}