Reset helpers: use revparse instead
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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231
diff --git a/tests/index/names.c b/tests/index/names.c
index 9007b1b..4e9cda5 100644
--- a/tests/index/names.c
+++ b/tests/index/names.c
@@ -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));
diff --git a/tests/index/reuc.c b/tests/index/reuc.c
index a18d560..0d70306 100644
--- a/tests/index/reuc.c
+++ b/tests/index/reuc.c
@@ -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);
diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index abe5f59..94ecc0b 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -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"
diff --git a/tests/reset/hard.c b/tests/reset/hard.c
index 0f80d32..8e9a94c 100644
--- a/tests/reset/hard.c
+++ b/tests/reset/hard.c
@@ -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)));
diff --git a/tests/reset/mixed.c b/tests/reset/mixed.c
index 7b90c23..75aedf0 100644
--- a/tests/reset/mixed.c
+++ b/tests/reset/mixed.c
@@ -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));
diff --git a/tests/reset/reset_helpers.c b/tests/reset/reset_helpers.c
index 17edca4..a792c03 100644
--- a/tests/reset/reset_helpers.c
+++ b/tests/reset/reset_helpers.c
@@ -1,10 +1,3 @@
#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));
-}
diff --git a/tests/reset/reset_helpers.h b/tests/reset/reset_helpers.h
index 5dbe9d2..82249ff 100644
--- a/tests/reset/reset_helpers.h
+++ b/tests/reset/reset_helpers.h
@@ -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);
diff --git a/tests/reset/soft.c b/tests/reset/soft.c
index bd6fcc2..f5501ac 100644
--- a/tests/reset/soft.c
+++ b/tests/reset/soft.c
@@ -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)));