]> git.proxmox.com Git - libgit2.git/blame - tests-clar/refs/revparse.c
Propose unified rev-parse API
[libgit2.git] / tests-clar / refs / revparse.c
CommitLineData
ac250c56
BS
1#include "clar_libgit2.h"
2
3#include "git2/revparse.h"
35bed94f 4#include "buffer.h"
5#include "refs.h"
6#include "path.h"
ac250c56
BS
7
8static git_repository *g_repo;
9static git_object *g_obj;
ac250c56 10
387d01b8 11/* Helpers */
35bed94f 12static void test_object_inrepo(const char *spec, const char *expected_oid, git_repository *repo)
ac250c56 13{
e28dd29b 14 char objstr[64] = {0};
1decf88b 15 git_object *obj = NULL;
16 int error;
27ee8483 17
35bed94f 18 error = git_revparse_single(&obj, repo, spec);
27ee8483 19
1decf88b 20 if (expected_oid != NULL) {
21 cl_assert_equal_i(0, error);
22 git_oid_fmt(objstr, git_object_id(obj));
23 cl_assert_equal_s(objstr, expected_oid);
24 } else
25 cl_assert_equal_i(GIT_ENOTFOUND, error);
ac250c56 26
1decf88b 27 git_object_free(obj);
28}
ac250c56 29
35bed94f 30static void test_object(const char *spec, const char *expected_oid)
31{
32 test_object_inrepo(spec, expected_oid, g_repo);
33}
34
b208d900
GP
35static void test_rangelike(const char *rangelike,
36 const char *expected_left,
37 const char *expected_right,
38 int expected_threedots)
39{
40 char objstr[64] = {0};
812e5aea 41 git_object *left = NULL, *right = NULL;
b208d900
GP
42 int threedots;
43 int error;
44
45 error = git_revparse_rangelike(&left, &right, &threedots, g_repo, rangelike);
46
47 if (expected_left != NULL) {
48 cl_assert_equal_i(0, error);
49 cl_assert_equal_i(threedots, expected_threedots);
50 git_oid_fmt(objstr, git_object_id(left));
51 cl_assert_equal_s(objstr, expected_left);
52 git_oid_fmt(objstr, git_object_id(right));
53 cl_assert_equal_s(objstr, expected_right);
54 } else
55 cl_assert(error != 0);
56
57 git_object_free(left);
58 git_object_free(right);
59}
60
61
ac250c56
BS
62void test_refs_revparse__initialize(void)
63{
34922eee 64 cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
ac250c56
BS
65}
66
67void test_refs_revparse__cleanup(void)
68{
34922eee 69 git_repository_free(g_repo);
ac250c56
BS
70}
71
9d7bdf71
BS
72void test_refs_revparse__nonexistant_object(void)
73{
ce9e8e11 74 test_object("this-does-not-exist", NULL);
3e82d6c6 75 test_object("this-does-not-exist^1", NULL);
76 test_object("this-does-not-exist~2", NULL);
ce9e8e11 77}
1decf88b 78
cc146626 79static void assert_invalid_spec(const char *invalid_spec)
ce9e8e11 80{
cc146626 81 cl_assert_equal_i(
82 GIT_EINVALIDSPEC, git_revparse_single(&g_obj, g_repo, invalid_spec));
83}
279b45b0 84
cc146626 85void test_refs_revparse__invalid_reference_name(void)
86{
87 assert_invalid_spec("this doesn't make sense");
88 assert_invalid_spec("Inv@{id");
89 assert_invalid_spec("");
9d7bdf71
BS
90}
91
ac250c56
BS
92void test_refs_revparse__shas(void)
93{
e28dd29b 94 test_object("c47800c7266a2be04c571c04d5a6614691ea99bd", "c47800c7266a2be04c571c04d5a6614691ea99bd");
95 test_object("c47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd");
ac250c56
BS
96}
97
98void test_refs_revparse__head(void)
99{
e28dd29b 100 test_object("HEAD", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
d448392e 101 test_object("HEAD^0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
102 test_object("HEAD~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
103 test_object("master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
ac250c56
BS
104}
105
106void test_refs_revparse__full_refs(void)
107{
e28dd29b 108 test_object("refs/heads/master", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
109 test_object("refs/heads/test", "e90810b8df3e80c413d903f631643c716887138d");
110 test_object("refs/tags/test", "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
ac250c56
BS
111}
112
113void test_refs_revparse__partial_refs(void)
114{
e28dd29b 115 test_object("point_to_blob", "1385f264afb75a56a5bec74243be9b367ba4ca08");
116 test_object("packed-test", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
117 test_object("br2", "a4a7dce85cf63874e984719f4fdd239f5145052f");
ac250c56
BS
118}
119
120void test_refs_revparse__describe_output(void)
121{
e28dd29b 122 test_object("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd");
123 test_object("not-good", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
ac250c56
BS
124}
125
023c6f69
BS
126void test_refs_revparse__nth_parent(void)
127{
cc146626 128 assert_invalid_spec("be3563a^-1");
129 assert_invalid_spec("^");
130 assert_invalid_spec("be3563a^{tree}^");
131 assert_invalid_spec("point_to_blob^{blob}^");
132 assert_invalid_spec("this doesn't make sense^1");
d448392e 133
e28dd29b 134 test_object("be3563a^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
135 test_object("be3563a^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
136 test_object("be3563a^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
137 test_object("be3563a^1^1", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
d448392e 138 test_object("be3563a^^", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045");
e28dd29b 139 test_object("be3563a^2^1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
140 test_object("be3563a^0", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
d448392e 141 test_object("be3563a^{commit}^", "9fd738e8f7967c078dceed8190330fc8648ee56a");
0e7af9e7 142
1decf88b 143 test_object("be3563a^42", NULL);
9d7bdf71
BS
144}
145
146void test_refs_revparse__not_tag(void)
147{
e28dd29b 148 test_object("point_to_blob^{}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
149 test_object("wrapped_tag^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
d448392e 150 test_object("master^{}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
151 test_object("master^{tree}^{}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
152 test_object("e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
153 test_object("tags/e90810b^{}", "e90810b8df3e80c413d903f631643c716887138d");
154 test_object("e908^{}", "e90810b8df3e80c413d903f631643c716887138d");
9d7bdf71
BS
155}
156
157void test_refs_revparse__to_type(void)
158{
cc146626 159 assert_invalid_spec("wrapped_tag^{trip}");
160 test_object("point_to_blob^{commit}", NULL);
161 cl_assert_equal_i(
162 GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}"));
d448392e 163
e28dd29b 164 test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
165 test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
166 test_object("point_to_blob^{blob}", "1385f264afb75a56a5bec74243be9b367ba4ca08");
d448392e 167 test_object("master^{commit}^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
023c6f69
BS
168}
169
38533d5a
BS
170void test_refs_revparse__linear_history(void)
171{
cc146626 172 assert_invalid_spec("~");
173 test_object("foo~bar", NULL);
174
175 assert_invalid_spec("master~bar");
176 assert_invalid_spec("master~-1");
177 assert_invalid_spec("master~0bar");
178 assert_invalid_spec("this doesn't make sense~2");
179 assert_invalid_spec("be3563a^{tree}~");
180 assert_invalid_spec("point_to_blob^{blob}~");
eb6bc45f 181
e28dd29b 182 test_object("master~0", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
183 test_object("master~1", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
184 test_object("master~2", "9fd738e8f7967c078dceed8190330fc8648ee56a");
185 test_object("master~1~1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
d448392e 186 test_object("master~~", "9fd738e8f7967c078dceed8190330fc8648ee56a");
38533d5a
BS
187}
188
189void test_refs_revparse__chaining(void)
190{
cc146626 191 assert_invalid_spec("master@{0}@{0}");
192 assert_invalid_spec("@{u}@{-1}");
193 assert_invalid_spec("@{-1}@{-1}");
194 assert_invalid_spec("@{-3}@{0}");
d448392e 195
196 test_object("master@{0}~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
197 test_object("@{u}@{0}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
198 test_object("@{-1}@{0}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
199 test_object("@{-4}@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
e28dd29b 200 test_object("master~1^1", "9fd738e8f7967c078dceed8190330fc8648ee56a");
201 test_object("master~1^2", "c47800c7266a2be04c571c04d5a6614691ea99bd");
202 test_object("master^1^2~1", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
d448392e 203 test_object("master^^2^", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
e28dd29b 204 test_object("master^1^1^1^1^1", "8496071c1b46c854b31185ea97743be6a8774479");
d448392e 205 test_object("master^^1^2^1", NULL);
38533d5a
BS
206}
207
3cd90893 208void test_refs_revparse__upstream(void)
209{
cc146626 210 assert_invalid_spec("e90810b@{u}");
211 assert_invalid_spec("refs/tags/e90810b@{u}");
212 test_object("refs/heads/e90810b@{u}", NULL);
3cd90893 213
214 test_object("master@{upstream}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
215 test_object("@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
216 test_object("master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
217 test_object("heads/master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
218 test_object("refs/heads/master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
219}
220
3d78ab64 221void test_refs_revparse__ordinal(void)
023c6f69 222{
cc146626 223 assert_invalid_spec("master@{-2}");
d448392e 224
225 /* TODO: make the test below actually fail
226 * cl_git_fail(git_revparse_single(&g_obj, g_repo, "master@{1a}"));
227 */
a51bdbcf 228
1decf88b 229 test_object("nope@{0}", NULL);
230 test_object("master@{31415}", NULL);
3d78ab64 231 test_object("@{1000}", NULL);
b8460c20 232 test_object("@{2}", NULL);
08ac23a5 233
e28dd29b 234 test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
235 test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
3d78ab64 236
237 test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
238 test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
239 test_object("heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
240 test_object("refs/heads/master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
241}
242
243void test_refs_revparse__previous_head(void)
244{
cc146626 245 assert_invalid_spec("@{-xyz}");
246 assert_invalid_spec("@{-0}");
247 assert_invalid_spec("@{-1b}");
3d78ab64 248
249 test_object("@{-42}", NULL);
250
251 test_object("@{-2}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
252 test_object("@{-1}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
886f183a
BS
253}
254
35bed94f 255static void create_fake_stash_reference_and_reflog(git_repository *repo)
256{
d00d5464 257 git_reference *master, *new_master;
35bed94f 258 git_buf log_path = GIT_BUF_INIT;
259
260 git_buf_joinpath(&log_path, git_repository_path(repo), "logs/refs/fakestash");
261
262 cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&log_path)));
263
264 cl_git_pass(git_reference_lookup(&master, repo, "refs/heads/master"));
d00d5464
ET
265 cl_git_pass(git_reference_rename(&new_master, master, "refs/fakestash", 0));
266 git_reference_free(master);
35bed94f 267
268 cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path)));
269
270 git_buf_free(&log_path);
d00d5464 271 git_reference_free(new_master);
35bed94f 272}
273
274void test_refs_revparse__reflog_of_a_ref_under_refs(void)
275{
276 git_repository *repo = cl_git_sandbox_init("testrepo.git");
277
278 test_object_inrepo("refs/fakestash", NULL, repo);
279
280 create_fake_stash_reference_and_reflog(repo);
281
282 /*
283 * $ git reflog -1 refs/fakestash
284 * a65fedf refs/fakestash@{0}: commit: checking in
285 *
286 * $ git reflog -1 refs/fakestash@{0}
287 * a65fedf refs/fakestash@{0}: commit: checking in
288 *
289 * $ git reflog -1 fakestash
290 * a65fedf fakestash@{0}: commit: checking in
291 *
292 * $ git reflog -1 fakestash@{0}
293 * a65fedf fakestash@{0}: commit: checking in
294 */
295 test_object_inrepo("refs/fakestash", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
296 test_object_inrepo("refs/fakestash@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
297 test_object_inrepo("fakestash", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
298 test_object_inrepo("fakestash@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
299
300 cl_git_sandbox_cleanup();
301}
302
886f183a
BS
303void test_refs_revparse__revwalk(void)
304{
cc146626 305 test_object("master^{/not found in any commit}", NULL);
306 test_object("master^{/merge}", NULL);
307 assert_invalid_spec("master^{/((}");
886f183a 308
e28dd29b 309 test_object("master^{/anoth}", "5b5b025afb0b4c913b4c338a42934a3863bf3644");
310 test_object("master^{/Merge}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
311 test_object("br2^{/Merge}", "a4a7dce85cf63874e984719f4fdd239f5145052f");
312 test_object("master^{/fo.rth}", "9fd738e8f7967c078dceed8190330fc8648ee56a");
886f183a
BS
313}
314
315void test_refs_revparse__date(void)
316{
494ae940 317 /*
318 * $ git reflog HEAD --date=iso
319 * a65fedf HEAD@{2012-04-30 08:23:41 -0900}: checkout: moving from br2 to master
320 * a4a7dce HEAD@{2012-04-30 08:23:37 -0900}: commit: checking in
321 * c47800c HEAD@{2012-04-30 08:23:28 -0900}: checkout: moving from master to br2
322 * a65fedf HEAD@{2012-04-30 08:23:23 -0900}: commit:
323 * be3563a HEAD@{2012-04-30 10:22:43 -0700}: clone: from /Users/ben/src/libgit2/tes
324 *
325 * $ git reflog HEAD --date=raw
326 * a65fedf HEAD@{1335806621 -0900}: checkout: moving from br2 to master
327 * a4a7dce HEAD@{1335806617 -0900}: commit: checking in
328 * c47800c HEAD@{1335806608 -0900}: checkout: moving from master to br2
329 * a65fedf HEAD@{1335806603 -0900}: commit:
330 * be3563a HEAD@{1335806563 -0700}: clone: from /Users/ben/src/libgit2/tests/resour
331 */
1decf88b 332 test_object("HEAD@{10 years ago}", NULL);
a346992f 333
494ae940 334 test_object("HEAD@{1 second}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
335 test_object("HEAD@{1 second ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
336 test_object("HEAD@{2 days ago}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
337
338 /*
339 * $ git reflog master --date=iso
340 * a65fedf master@{2012-04-30 09:23:23 -0800}: commit: checking in
341 * be3563a master@{2012-04-30 09:22:43 -0800}: clone: from /Users/ben/src...
342 *
343 * $ git reflog master --date=raw
344 * a65fedf master@{1335806603 -0800}: commit: checking in
345 * be3563a master@{1335806563 -0800}: clone: from /Users/ben/src/libgit2/tests/reso
346 */
347
348
349 /*
350 * $ git reflog -1 "master@{2012-04-30 17:22:42 +0000}"
351 * warning: Log for 'master' only goes back to Mon, 30 Apr 2012 09:22:43 -0800.
352 */
1decf88b 353 test_object("master@{2012-04-30 17:22:42 +0000}", NULL);
354 test_object("master@{2012-04-30 09:22:42 -0800}", NULL);
494ae940 355
356 /*
357 * $ git reflog -1 "master@{2012-04-30 17:22:43 +0000}"
358 * be3563a master@{Mon Apr 30 09:22:43 2012 -0800}: clone: from /Users/ben/src/libg
359 */
360 test_object("master@{2012-04-30 17:22:43 +0000}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
361 test_object("master@{2012-04-30 09:22:43 -0800}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
362
363 /*
364 * $ git reflog -1 "master@{2012-4-30 09:23:27 -0800}"
365 * a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
366 */
367 test_object("master@{2012-4-30 09:23:27 -0800}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
368
369 /*
370 * $ git reflog -1 master@{2012-05-03}
371 * a65fedf master@{Mon Apr 30 09:23:23 2012 -0800}: commit: checking in
372 */
373 test_object("master@{2012-05-03}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
374
375 /*
376 * $ git reflog -1 "master@{1335806603}"
377 * a65fedf
378 *
379 * $ git reflog -1 "master@{1335806602}"
380 * be3563a
381 */
382 test_object("master@{1335806603}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
383 test_object("master@{1335806602}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
023c6f69 384}
244d2f6b
BS
385
386void test_refs_revparse__colon(void)
387{
cc146626 388 assert_invalid_spec(":/");
389 assert_invalid_spec("point_to_blob:readme.txt");
390 cl_git_fail(git_revparse_single(&g_obj, g_repo, ":2:README")); /* Not implemented */
e28dd29b 391
1decf88b 392 test_object(":/not found in any commit", NULL);
393 test_object("subtrees:ab/42.txt", NULL);
394 test_object("subtrees:ab/4.txt/nope", NULL);
395 test_object("subtrees:nope", NULL);
396 test_object("test/master^1:branch_file.txt", NULL);
5b68ba7e 397
bb89cf94 398 /* From tags */
399 test_object("test:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
400 test_object("tags/test:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
401 test_object("e90810b:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
402 test_object("tags/e90810b:readme.txt", "0266163a49e280c4f5ed1e08facd36a2bd716bcf");
403
404 /* From commits */
405 test_object("a65f:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
406
407 /* From trees */
408 test_object("a65f^{tree}:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
409 test_object("944c:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
410
411 /* Retrieving trees */
faaa7c51 412 test_object("master:", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
413 test_object("subtrees:", "ae90f12eea699729ed24555e40b9fd669da12a12");
414 test_object("subtrees:ab", "f1425cef211cc08caa31e7b545ffb232acb098c3");
bb89cf94 415 test_object("subtrees:ab/", "f1425cef211cc08caa31e7b545ffb232acb098c3");
faaa7c51 416
bb89cf94 417 /* Retrieving blobs */
e28dd29b 418 test_object("subtrees:ab/4.txt", "d6c93164c249c8000205dd4ec5cbca1b516d487f");
419 test_object("subtrees:ab/de/fgh/1.txt", "1f67fc4386b2d171e0d21be1c447e12660561f9b");
420 test_object("master:README", "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
421 test_object("master:new.txt", "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
422 test_object(":/Merge", "a4a7dce85cf63874e984719f4fdd239f5145052f");
423 test_object(":/one", "c47800c7266a2be04c571c04d5a6614691ea99bd");
424 test_object(":/packed commit t", "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9");
0d23c62c 425 test_object("test/master^2:branch_file.txt", "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
d448392e 426 test_object("test/master@{1}:branch_file.txt", "3697d64be941a53d4ae8f6a271e4e3fa56b022cc");
244d2f6b 427}
d1b7921a 428
429void test_refs_revparse__disambiguation(void)
430{
431 /*
432 * $ git show e90810b
433 * tag e90810b
434 * Tagger: Vicent Marti <tanoku@gmail.com>
435 * Date: Thu Aug 12 03:59:17 2010 +0200
436 *
437 * This is a very simple tag.
438 *
439 * commit e90810b8df3e80c413d903f631643c716887138d
440 * Author: Vicent Marti <tanoku@gmail.com>
441 * Date: Thu Aug 5 18:42:20 2010 +0200
442 *
443 * Test commit 2
444 *
445 * diff --git a/readme.txt b/readme.txt
446 * index 6336846..0266163 100644
447 * --- a/readme.txt
448 * +++ b/readme.txt
449 * @@ -1 +1,2 @@
450 * Testing a readme.txt
451 * +Now we add a single line here
452 *
453 * $ git show-ref e90810b
454 * 7b4384978d2493e851f9cca7858815fac9b10980 refs/tags/e90810b
455 *
456 */
457 test_object("e90810b", "7b4384978d2493e851f9cca7858815fac9b10980");
458
459 /*
460 * $ git show e90810
461 * commit e90810b8df3e80c413d903f631643c716887138d
462 * Author: Vicent Marti <tanoku@gmail.com>
463 * Date: Thu Aug 5 18:42:20 2010 +0200
464 *
465 * Test commit 2
466 *
467 * diff --git a/readme.txt b/readme.txt
468 * index 6336846..0266163 100644
469 * --- a/readme.txt
470 * +++ b/readme.txt
471 * @@ -1 +1,2 @@
472 * Testing a readme.txt
473 * +Now we add a single line here
474 */
475 test_object("e90810", "e90810b8df3e80c413d903f631643c716887138d");
476}
c9de8611
BS
477
478void test_refs_revparse__a_too_short_objectid_returns_EAMBIGUOUS(void)
479{
cc146626 480 cl_assert_equal_i(
481 GIT_EAMBIGUOUS, git_revparse_single(&g_obj, g_repo, "e90"));
c9de8611 482}
5912d74c 483
484void test_refs_revparse__issue_994(void)
485{
486 git_repository *repo;
487 git_reference *head, *with_at;
488 git_object *target;
489
490 repo = cl_git_sandbox_init("testrepo.git");
491
492 cl_assert_equal_i(GIT_ENOTFOUND,
493 git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
494
495 cl_assert_equal_i(GIT_ENOTFOUND,
496 git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
497
498
499 cl_git_pass(git_repository_head(&head, repo));
2508cc66 500 cl_git_pass(git_reference_create(
5912d74c 501 &with_at,
502 repo,
503 "refs/remotes/origin/bim_with_3d@11296",
2508cc66 504 git_reference_target(head),
5912d74c 505 0));
506
507 cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296"));
508 git_object_free(target);
509
510 cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296"));
511 git_object_free(target);
512
513 git_reference_free(with_at);
514 git_reference_free(head);
515 cl_git_sandbox_cleanup();
516}
545b479a 517
518/**
519 * $ git rev-parse blah-7-gc47800c
520 * c47800c7266a2be04c571c04d5a6614691ea99bd
521 *
522 * $ git rev-parse HEAD~3
523 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
524 *
525 * $ git branch blah-7-gc47800c HEAD~3
526 *
527 * $ git rev-parse blah-7-gc47800c
528 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
529 */
530void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
531{
532 git_repository *repo;
533 git_reference *branch;
534 git_object *target;
535 char sha[GIT_OID_HEXSZ + 1];
536
537 repo = cl_git_sandbox_init("testrepo.git");
538
539 test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
540
541 cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
542 cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0));
543
544 git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
545
546 test_object_inrepo("blah-7-gc47800c", sha, repo);
547
548 git_reference_free(branch);
549 git_object_free(target);
550 cl_git_sandbox_cleanup();
551}
0e8e5a61 552
553/**
554 * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
555 * a65fedf39aefe402d3bb6e24df4d4f5fe4547750
556 *
557 * $ git rev-parse HEAD~3
558 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
559 *
560 * $ git branch a65fedf39aefe402d3bb6e24df4d4f5fe4547750 HEAD~3
561 *
562 * $ git rev-parse a65fedf39aefe402d3bb6e24df4d4f5fe4547750
563 * a65fedf39aefe402d3bb6e24df4d4f5fe4547750
564 *
565 * $ git rev-parse heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750
566 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
567 */
568void test_refs_revparse__try_to_retrieve_sha_before_branch(void)
569{
570 git_repository *repo;
571 git_reference *branch;
572 git_object *target;
573 char sha[GIT_OID_HEXSZ + 1];
574
575 repo = cl_git_sandbox_init("testrepo.git");
576
577 test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
578
579 cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
580 cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0));
581
582 git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
583
584 test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
585 test_object_inrepo("heads/a65fedf39aefe402d3bb6e24df4d4f5fe4547750", sha, repo);
586
587 git_reference_free(branch);
588 git_object_free(target);
589 cl_git_sandbox_cleanup();
590}
591
592/**
593 * $ git rev-parse c47800
594 * c47800c7266a2be04c571c04d5a6614691ea99bd
595 *
596 * $ git rev-parse HEAD~3
597 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
598 *
599 * $ git branch c47800 HEAD~3
600 *
601 * $ git rev-parse c47800
602 * 4a202b346bb0fb0db7eff3cffeb3c70babbd2045
603 */
604void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
605{
606 git_repository *repo;
607 git_reference *branch;
608 git_object *target;
609 char sha[GIT_OID_HEXSZ + 1];
610
611 repo = cl_git_sandbox_init("testrepo.git");
612
613 test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
614
615 cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
616 cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0));
617
618 git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
619
620 test_object_inrepo("c47800", sha, repo);
621
622 git_reference_free(branch);
623 git_object_free(target);
624 cl_git_sandbox_cleanup();
625}
b208d900
GP
626
627
628void test_refs_revparse__range(void)
629{
630 test_rangelike("be3563a^1..be3563a",
631 "9fd738e8f7967c078dceed8190330fc8648ee56a",
632 "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
633 0);
634
635 test_rangelike("be3563a^1...be3563a",
636 "9fd738e8f7967c078dceed8190330fc8648ee56a",
637 "be3563ae3f795b2b4353bcce3a527ad0a4f7f644",
638 1);
639
640 test_rangelike("be3563a^1.be3563a", NULL, NULL, 0);
641}