Commit 0d847a31 by Ben Straub

Reset helpers: use revparse instead

parent 3b6a5bac
......@@ -86,7 +86,7 @@ void test_index_names__cleaned_on_reset_hard(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
......@@ -99,7 +99,7 @@ void test_index_names__cleaned_on_reset_mixed(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_names__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
......
......@@ -295,7 +295,7 @@ void test_index_reuc__cleaned_on_reset_hard(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_reuc__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
......@@ -308,7 +308,7 @@ void test_index_reuc__cleaned_on_reset_mixed(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
test_index_reuc__add();
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
......@@ -321,7 +321,7 @@ void test_index_reuc__retained_on_reset_soft(void)
{
git_object *target;
retrieve_target_from_oid(&target, repo, "3a34580a35add43a4cf361e8e9a30060a905c876");
cl_git_pass(git_revparse_single(&target, repo, "3a34580"));
git_reset(repo, target, GIT_RESET_HARD);
......
......@@ -29,15 +29,16 @@ void test_refs_branches_create__cleanup(void)
static void retrieve_target_from_oid(git_commit **out, git_repository *repo, const char *sha)
{
git_oid oid;
git_object *obj;
cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_commit_lookup(out, repo, &oid));
cl_git_pass(git_revparse_single(&obj, repo, sha));
cl_git_pass(git_commit_lookup(out, repo, git_object_id(obj)));
git_object_free(obj);
}
static void retrieve_known_commit(git_commit **commit, git_repository *repo)
{
retrieve_target_from_oid(commit, repo, "e90810b8df3e80c413d903f631643c716887138d");
retrieve_target_from_oid(commit, repo, "e90810b8df3");
}
#define NEW_BRANCH_NAME "new-branch-on-the-block"
......
......@@ -69,8 +69,7 @@ void test_reset_hard__resetting_reverts_modified_files(void)
cl_assert_equal_s(before[i], content.ptr);
}
retrieve_target_from_oid(
&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
......@@ -95,7 +94,7 @@ void test_reset_hard__cannot_reset_in_a_bare_repository(void)
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD));
......@@ -152,7 +151,7 @@ void test_reset_hard__resetting_reverts_unmerged(void)
unmerged_index_init(index, entries);
cl_git_pass(git_index_write(index));
retrieve_target_from_oid(&target, repo, "26a125ee1bfc5df1e1b2e9441bbe63c8a7ae989f");
cl_git_pass(git_revparse_single(&target, repo, "26a125e"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
cl_assert(git_path_exists("status/conflicting_file") == 0);
......@@ -183,7 +182,7 @@ void test_reset_hard__cleans_up_merge(void)
cl_git_pass(git_buf_joinpath(&orig_head_path, git_repository_path(repo), "ORIG_HEAD"));
cl_git_mkfile(git_buf_cstr(&orig_head_path), "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
retrieve_target_from_oid(&target, repo, "0017bd4ab1ec30440b17bae1680cff124ab5f1f6");
cl_git_pass(git_revparse_single(&target, repo, "0017bd4"));
cl_git_pass(git_reset(repo, target, GIT_RESET_HARD));
cl_assert(!git_path_exists(git_buf_cstr(&merge_head_path)));
......
......@@ -27,7 +27,7 @@ void test_reset_mixed__cannot_reset_in_a_bare_repository(void)
cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git")));
cl_assert(git_repository_is_bare(bare) == true);
retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED));
......@@ -40,7 +40,7 @@ void test_reset_mixed__resetting_refreshes_the_index_to_the_commit_tree(void)
cl_git_pass(git_status_file(&status, repo, "macro_bad"));
cl_assert(status == GIT_STATUS_CURRENT);
retrieve_target_from_oid(&target, repo, "605812ab7fe421fdd325a935d35cb06a9234a7d7");
cl_git_pass(git_revparse_single(&target, repo, "605812a"));
cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED));
......
#include "clar_libgit2.h"
#include "reset_helpers.h"
void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_object_lookup(object_out, repo, &oid, GIT_OBJ_ANY));
}
......@@ -3,4 +3,3 @@
#define KNOWN_COMMIT_IN_BARE_REPO "e90810b8df3e80c413d903f631643c716887138d"
#define KNOWN_COMMIT_IN_ATTR_REPO "217878ab49e1314388ea2e32dc6fdb58a1b969e0"
extern void retrieve_target_from_oid(git_object **object_out, git_repository *repo, const char *sha);
......@@ -26,8 +26,7 @@ static void assert_reset_soft(bool should_be_detached)
cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD"));
cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO));
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert(git_repository_head_detached(repo) == should_be_detached);
......@@ -60,7 +59,7 @@ void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_ch
git_oid_fmt(raw_head_oid, &oid);
raw_head_oid[GIT_OID_HEXSZ] = '\0';
retrieve_target_from_oid(&target, repo, raw_head_oid);
cl_git_pass(git_revparse_single(&target, repo, raw_head_oid));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
......@@ -73,7 +72,7 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
git_oid oid;
/* b25fa35 is a tag, pointing to another tag which points to commit e90810b */
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
cl_git_pass(git_revparse_single(&target, repo, "b25fa35"));
cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT));
......@@ -85,13 +84,13 @@ void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void
void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void)
{
/* 53fc32d is the tree of commit e90810b */
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
cl_git_pass(git_revparse_single(&target, repo, "53fc32d"));
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
git_object_free(target);
/* 521d87c is an annotated tag pointing to a blob */
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
cl_git_pass(git_revparse_single(&target, repo, "521d87c"));
cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT));
}
......@@ -99,7 +98,7 @@ void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_lo
{
git_reference *head;
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
make_head_unborn(repo, NON_EXISTING_HEAD);
......@@ -123,7 +122,7 @@ void test_reset_soft__fails_when_merging(void)
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO);
cl_git_pass(git_revparse_single(&target, repo, KNOWN_COMMIT_IN_BARE_REPO));
cl_assert_equal_i(GIT_EUNMERGED, git_reset(repo, target, GIT_RESET_SOFT));
cl_git_pass(p_unlink(git_buf_cstr(&merge_head_path)));
......
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