Commit 6bb74993125e9e9c7c8be801c8f033974c3f6191

Ben Straub 2012-03-30T07:11:13

Moved tag tests to object suite.

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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
diff --git a/tests-clar/object/tag/read.c b/tests-clar/object/tag/read.c
new file mode 100644
index 0000000..04d4d02
--- /dev/null
+++ b/tests-clar/object/tag/read.c
@@ -0,0 +1,128 @@
+#include "clar_libgit2.h"
+
+#include "tag.h"
+
+static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
+static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
+static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
+static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
+static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
+
+static git_repository *g_repo;
+
+
+// Helpers
+static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches)
+{
+   git_strarray tag_list;
+   int error = GIT_SUCCESS;
+
+   if ((error = git_tag_list_match(&tag_list, pattern, repo)) < GIT_SUCCESS)
+      goto exit;
+
+   if (tag_list.count != expected_matches)
+      error = GIT_ERROR;
+
+exit:
+   git_strarray_free(&tag_list);
+   return error;
+}
+
+
+// Fixture setup and teardown
+void test_object_tag_read__initialize(void)
+{
+   g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_object_tag_read__cleanup(void)
+{
+   cl_git_sandbox_cleanup();
+}
+
+
+void test_object_tag_read__parse(void)
+{
+   // read and parse a tag from the repository
+   git_tag *tag1, *tag2;
+   git_commit *commit;
+   git_oid id1, id2, id_commit;
+
+   git_oid_fromstr(&id1, tag1_id);
+   git_oid_fromstr(&id2, tag2_id);
+   git_oid_fromstr(&id_commit, tagged_commit);
+
+   cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
+
+   cl_assert(strcmp(git_tag_name(tag1), "test") == 0);
+   cl_assert(git_tag_type(tag1) == GIT_OBJ_TAG);
+
+   cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
+   cl_assert(tag2 != NULL);
+
+   cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
+
+   cl_git_pass(git_tag_target((git_object **)&commit, tag2));
+   cl_assert(commit != NULL);
+
+   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+
+   git_tag_free(tag1);
+   git_tag_free(tag2);
+   git_commit_free(commit);
+}
+
+void test_object_tag_read__list(void)
+{
+   // list all tag names from the repository
+   git_strarray tag_list;
+
+   cl_git_pass(git_tag_list(&tag_list, g_repo));
+
+   cl_assert(tag_list.count == 3);
+
+   git_strarray_free(&tag_list);
+}
+
+void test_object_tag_read__list_pattern(void)
+{
+   // list all tag names from the repository matching a specified pattern
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "", 3));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "*", 3));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "t*", 1));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "*b", 2));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "e", 0));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810b", 1));
+   cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810[ab]", 1));
+}
+
+void test_object_tag_read__parse_without_tagger(void)
+{
+   // read and parse a tag without a tagger field
+   git_repository *bad_tag_repo;
+   git_tag *bad_tag;
+   git_commit *commit;
+   git_oid id, id_commit;
+
+   // TODO: This is a little messy
+   cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
+
+   git_oid_fromstr(&id, bad_tag_id);
+   git_oid_fromstr(&id_commit, badly_tagged_commit);
+
+   cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
+   cl_assert(bad_tag != NULL);
+
+   cl_assert(strcmp(git_tag_name(bad_tag), "e90810b") == 0);
+   cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
+   cl_assert(bad_tag->tagger == NULL);
+
+   cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
+   cl_assert(commit != NULL);
+
+   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+
+   git_tag_free(bad_tag);
+   git_commit_free(commit);
+   git_repository_free(bad_tag_repo);
+}
diff --git a/tests-clar/object/tag/write.c b/tests-clar/object/tag/write.c
new file mode 100644
index 0000000..01e9d9c
--- /dev/null
+++ b/tests-clar/object/tag/write.c
@@ -0,0 +1,251 @@
+#include "clar_libgit2.h"
+
+static const char* tagger_name = "Vicent Marti";
+static const char* tagger_email = "vicent@github.com";
+static const char* tagger_message = "This is my tag.\n\nThere are many tags, but this one is mine\n";
+
+static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
+static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
+
+static git_repository *g_repo;
+
+
+// Helpers
+#ifndef GIT_WIN32
+#include "odb.h"
+
+static void locate_loose_object(const char *repository_folder, git_object *object, char **out, char **out_folder)
+{
+	static const char *objects_folder = "objects/";
+
+	char *ptr, *full_path, *top_folder;
+	int path_length, objects_length;
+
+	assert(repository_folder && object);
+
+	objects_length = strlen(objects_folder);
+	path_length = strlen(repository_folder);
+	ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3);
+
+	strcpy(ptr, repository_folder);
+	strcpy(ptr + path_length, objects_folder);
+
+	ptr = top_folder = ptr + path_length + objects_length;
+	*ptr++ = '/';
+	git_oid_pathfmt(ptr, git_object_id(object));
+	ptr += GIT_OID_HEXSZ + 1;
+	*ptr = 0;
+
+	*out = full_path;
+
+	if (out_folder)
+		*out_folder = top_folder;
+}
+
+static int loose_object_mode(const char *repository_folder, git_object *object)
+{
+	char *object_path;
+	struct stat st;
+
+	locate_loose_object(repository_folder, object, &object_path, NULL);
+	if (p_stat(object_path, &st) < 0)
+		return 0;
+	free(object_path);
+
+	return st.st_mode;
+}
+#endif
+
+
+
+// Fixture setup and teardown
+void test_object_tag_write__initialize(void)
+{
+   g_repo = cl_git_sandbox_init("testrepo");
+}
+
+void test_object_tag_write__cleanup(void)
+{
+   cl_git_sandbox_cleanup();
+}
+
+
+
+void test_object_tag_write__basic(void)
+{
+   // write a tag to the repository and read it again
+	git_tag *tag;
+	git_oid target_id, tag_id;
+	git_signature *tagger;
+	const git_signature *tagger1;
+	git_reference *ref_tag;
+	git_object *target;
+
+	git_oid_fromstr(&target_id, tagged_commit);
+	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+	/* create signature */
+	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
+
+	cl_git_pass(git_tag_create(
+                              &tag_id, /* out id */
+                              g_repo,
+                              "the-tag",
+                              target,
+                              tagger,
+                              tagger_message,
+                              0));
+
+	git_object_free(target);
+	git_signature_free(tagger);
+
+	cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
+	cl_assert(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0);
+
+	/* Check attributes were set correctly */
+	tagger1 = git_tag_tagger(tag);
+	cl_assert(tagger1 != NULL);
+	cl_assert(strcmp(tagger1->name, tagger_name) == 0);
+	cl_assert(strcmp(tagger1->email, tagger_email) == 0);
+	cl_assert(tagger1->when.time == 123456789);
+	cl_assert(tagger1->when.offset == 60);
+
+	cl_assert(strcmp(git_tag_message(tag), tagger_message) == 0);
+
+	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
+	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
+	cl_git_pass(git_reference_delete(ref_tag));
+#ifndef GIT_WIN32
+	// TODO: Get this to work on Linux
+	// cl_assert((loose_object_mode("testrepo", (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE);
+#endif
+
+	git_tag_free(tag);
+}
+
+void test_object_tag_write__overwrite(void)
+{
+   // Attempt to write a tag bearing the same name than an already existing tag
+	git_oid target_id, tag_id;
+	git_signature *tagger;
+	git_object *target;
+
+	git_oid_fromstr(&target_id, tagged_commit);
+	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+	/* create signature */
+	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
+
+	cl_git_fail(git_tag_create(
+                              &tag_id, /* out id */
+                              g_repo,
+                              "e90810b",
+                              target,
+                              tagger,
+                              tagger_message,
+                              0));
+
+	git_object_free(target);
+	git_signature_free(tagger);
+
+}
+
+void test_object_tag_write__replace(void)
+{
+   // Replace an already existing tag
+	git_oid target_id, tag_id, old_tag_id;
+	git_signature *tagger;
+	git_reference *ref_tag;
+	git_object *target;
+
+	git_oid_fromstr(&target_id, tagged_commit);
+	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
+	git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag));
+	git_reference_free(ref_tag);
+
+	/* create signature */
+	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
+
+	cl_git_pass(git_tag_create(
+                              &tag_id, /* out id */
+                              g_repo,
+                              "e90810b",
+                              target,
+                              tagger,
+                              tagger_message,
+                              1));
+
+	git_object_free(target);
+	git_signature_free(tagger);
+
+	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
+	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
+	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &old_tag_id) != 0);
+
+	git_reference_free(ref_tag);
+}
+
+void test_object_tag_write__lightweight(void)
+{
+   // write a lightweight tag to the repository and read it again
+	git_oid target_id, object_id;
+	git_reference *ref_tag;
+	git_object *target;
+
+	git_oid_fromstr(&target_id, tagged_commit);
+	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+	cl_git_pass(git_tag_create_lightweight(
+                                          &object_id,
+                                          g_repo,
+                                          "light-tag",
+                                          target,
+                                          0));
+
+	git_object_free(target);
+
+	cl_assert(git_oid_cmp(&object_id, &target_id) == 0);
+
+	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/light-tag"));
+	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &target_id) == 0);
+
+	cl_git_pass(git_tag_delete(g_repo, "light-tag"));
+
+	git_reference_free(ref_tag);
+}
+
+void test_object_tag_write__lightweight_over_existing(void)
+{
+   // Attempt to write a lightweight tag bearing the same name than an already existing tag
+	git_oid target_id, object_id, existing_object_id;
+	git_object *target;
+
+	git_oid_fromstr(&target_id, tagged_commit);
+	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
+
+	cl_git_fail(git_tag_create_lightweight(
+                                          &object_id,
+                                          g_repo,
+                                          "e90810b",
+                                          target,
+                                          0));
+
+	git_oid_fromstr(&existing_object_id, tag2_id);
+	cl_assert(git_oid_cmp(&object_id, &existing_object_id) == 0);
+
+	git_object_free(target);
+}
+
+void test_object_tag_write__delete(void)
+{
+   // Delete an already existing tag
+	git_reference *ref_tag;
+
+	cl_git_pass(git_tag_delete(g_repo, "e90810b"));
+
+	cl_git_fail(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
+
+	git_reference_free(ref_tag);
+}
diff --git a/tests-clar/tag/read.c b/tests-clar/tag/read.c
deleted file mode 100644
index de7feed..0000000
--- a/tests-clar/tag/read.c
+++ /dev/null
@@ -1,128 +0,0 @@
-#include "clar_libgit2.h"
-
-#include "tag.h"
-
-static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
-static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
-static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
-static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
-static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
-
-static git_repository *g_repo;
-
-
-// Helpers
-static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches)
-{
-   git_strarray tag_list;
-   int error = GIT_SUCCESS;
-
-   if ((error = git_tag_list_match(&tag_list, pattern, repo)) < GIT_SUCCESS)
-      goto exit;
-
-   if (tag_list.count != expected_matches)
-      error = GIT_ERROR;
-
-exit:
-   git_strarray_free(&tag_list);
-   return error;
-}
-
-
-// Fixture setup and teardown
-void test_tag_read__initialize(void)
-{
-   g_repo = cl_git_sandbox_init("testrepo");
-}
-
-void test_tag_read__cleanup(void)
-{
-   cl_git_sandbox_cleanup();
-}
-
-
-void test_tag_read__parse(void)
-{
-   // read and parse a tag from the repository
-   git_tag *tag1, *tag2;
-   git_commit *commit;
-   git_oid id1, id2, id_commit;
-
-   git_oid_fromstr(&id1, tag1_id);
-   git_oid_fromstr(&id2, tag2_id);
-   git_oid_fromstr(&id_commit, tagged_commit);
-
-   cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
-
-   cl_assert(strcmp(git_tag_name(tag1), "test") == 0);
-   cl_assert(git_tag_type(tag1) == GIT_OBJ_TAG);
-
-   cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
-   cl_assert(tag2 != NULL);
-
-   cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
-
-   cl_git_pass(git_tag_target((git_object **)&commit, tag2));
-   cl_assert(commit != NULL);
-
-   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
-
-   git_tag_free(tag1);
-   git_tag_free(tag2);
-   git_commit_free(commit);
-}
-
-void test_tag_read__list(void)
-{
-   // list all tag names from the repository
-   git_strarray tag_list;
-
-   cl_git_pass(git_tag_list(&tag_list, g_repo));
-
-   cl_assert(tag_list.count == 3);
-
-   git_strarray_free(&tag_list);
-}
-
-void test_tag_read__list_pattern(void)
-{
-   // list all tag names from the repository matching a specified pattern
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "", 3));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "*", 3));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "t*", 1));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "*b", 2));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "e", 0));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810b", 1));
-   cl_git_pass(ensure_tag_pattern_match(g_repo, "e90810[ab]", 1));
-}
-
-void test_tag_read__parse_without_tagger(void)
-{
-   // read and parse a tag without a tagger field
-   git_repository *bad_tag_repo;
-   git_tag *bad_tag;
-   git_commit *commit;
-   git_oid id, id_commit;
-
-   // TODO: This is a little messy
-   cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
-
-   git_oid_fromstr(&id, bad_tag_id);
-   git_oid_fromstr(&id_commit, badly_tagged_commit);
-
-   cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
-   cl_assert(bad_tag != NULL);
-
-   cl_assert(strcmp(git_tag_name(bad_tag), "e90810b") == 0);
-   cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
-   cl_assert(bad_tag->tagger == NULL);
-
-   cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
-   cl_assert(commit != NULL);
-
-   cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
-
-   git_tag_free(bad_tag);
-   git_commit_free(commit);
-   git_repository_free(bad_tag_repo);
-}
diff --git a/tests-clar/tag/write.c b/tests-clar/tag/write.c
deleted file mode 100644
index 38fc1c9..0000000
--- a/tests-clar/tag/write.c
+++ /dev/null
@@ -1,251 +0,0 @@
-#include "clar_libgit2.h"
-
-static const char* tagger_name = "Vicent Marti";
-static const char* tagger_email = "vicent@github.com";
-static const char* tagger_message = "This is my tag.\n\nThere are many tags, but this one is mine\n";
-
-static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
-static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
-
-static git_repository *g_repo;
-
-
-// Helpers
-#ifndef GIT_WIN32
-#include "odb.h"
-
-static void locate_loose_object(const char *repository_folder, git_object *object, char **out, char **out_folder)
-{
-	static const char *objects_folder = "objects/";
-
-	char *ptr, *full_path, *top_folder;
-	int path_length, objects_length;
-
-	assert(repository_folder && object);
-
-	objects_length = strlen(objects_folder);
-	path_length = strlen(repository_folder);
-	ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3);
-
-	strcpy(ptr, repository_folder);
-	strcpy(ptr + path_length, objects_folder);
-
-	ptr = top_folder = ptr + path_length + objects_length;
-	*ptr++ = '/';
-	git_oid_pathfmt(ptr, git_object_id(object));
-	ptr += GIT_OID_HEXSZ + 1;
-	*ptr = 0;
-
-	*out = full_path;
-
-	if (out_folder)
-		*out_folder = top_folder;
-}
-
-static int loose_object_mode(const char *repository_folder, git_object *object)
-{
-	char *object_path;
-	struct stat st;
-
-	locate_loose_object(repository_folder, object, &object_path, NULL);
-	if (p_stat(object_path, &st) < 0)
-		return 0;
-	free(object_path);
-
-	return st.st_mode;
-}
-#endif
-
-
-
-// Fixture setup and teardown
-void test_tag_write__initialize(void)
-{
-   g_repo = cl_git_sandbox_init("testrepo");
-}
-
-void test_tag_write__cleanup(void)
-{
-   cl_git_sandbox_cleanup();
-}
-
-
-
-void test_tag_write__basic(void)
-{
-   // write a tag to the repository and read it again
-	git_tag *tag;
-	git_oid target_id, tag_id;
-	git_signature *tagger;
-	const git_signature *tagger1;
-	git_reference *ref_tag;
-	git_object *target;
-
-	git_oid_fromstr(&target_id, tagged_commit);
-	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
-
-	/* create signature */
-	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
-
-	cl_git_pass(git_tag_create(
-                              &tag_id, /* out id */
-                              g_repo,
-                              "the-tag",
-                              target,
-                              tagger,
-                              tagger_message,
-                              0));
-
-	git_object_free(target);
-	git_signature_free(tagger);
-
-	cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
-	cl_assert(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0);
-
-	/* Check attributes were set correctly */
-	tagger1 = git_tag_tagger(tag);
-	cl_assert(tagger1 != NULL);
-	cl_assert(strcmp(tagger1->name, tagger_name) == 0);
-	cl_assert(strcmp(tagger1->email, tagger_email) == 0);
-	cl_assert(tagger1->when.time == 123456789);
-	cl_assert(tagger1->when.offset == 60);
-
-	cl_assert(strcmp(git_tag_message(tag), tagger_message) == 0);
-
-	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
-	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
-	cl_git_pass(git_reference_delete(ref_tag));
-#ifndef GIT_WIN32
-	// TODO: Get this to work on Linux
-	// cl_assert((loose_object_mode("testrepo", (git_object *)tag) & 0777) == GIT_OBJECT_FILE_MODE);
-#endif
-
-	git_tag_free(tag);
-}
-
-void test_tag_write__overwrite(void)
-{
-   // Attempt to write a tag bearing the same name than an already existing tag
-	git_oid target_id, tag_id;
-	git_signature *tagger;
-	git_object *target;
-
-	git_oid_fromstr(&target_id, tagged_commit);
-	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
-
-	/* create signature */
-	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
-
-	cl_git_fail(git_tag_create(
-                              &tag_id, /* out id */
-                              g_repo,
-                              "e90810b",
-                              target,
-                              tagger,
-                              tagger_message,
-                              0));
-
-	git_object_free(target);
-	git_signature_free(tagger);
-
-}
-
-void test_tag_write__replace(void)
-{
-   // Replace an already existing tag
-	git_oid target_id, tag_id, old_tag_id;
-	git_signature *tagger;
-	git_reference *ref_tag;
-	git_object *target;
-
-	git_oid_fromstr(&target_id, tagged_commit);
-	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
-
-	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
-	git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag));
-	git_reference_free(ref_tag);
-
-	/* create signature */
-	cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
-
-	cl_git_pass(git_tag_create(
-                              &tag_id, /* out id */
-                              g_repo,
-                              "e90810b",
-                              target,
-                              tagger,
-                              tagger_message,
-                              1));
-
-	git_object_free(target);
-	git_signature_free(tagger);
-
-	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
-	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0);
-	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &old_tag_id) != 0);
-
-	git_reference_free(ref_tag);
-}
-
-void test_tag_write__lightweight(void)
-{
-   // write a lightweight tag to the repository and read it again
-	git_oid target_id, object_id;
-	git_reference *ref_tag;
-	git_object *target;
-
-	git_oid_fromstr(&target_id, tagged_commit);
-	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
-
-	cl_git_pass(git_tag_create_lightweight(
-                                          &object_id,
-                                          g_repo,
-                                          "light-tag",
-                                          target,
-                                          0));
-
-	git_object_free(target);
-
-	cl_assert(git_oid_cmp(&object_id, &target_id) == 0);
-
-	cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/light-tag"));
-	cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &target_id) == 0);
-
-	cl_git_pass(git_tag_delete(g_repo, "light-tag"));
-
-	git_reference_free(ref_tag);
-}
-
-void test_tag_write__lightweight_over_existing(void)
-{
-   // Attempt to write a lightweight tag bearing the same name than an already existing tag
-	git_oid target_id, object_id, existing_object_id;
-	git_object *target;
-
-	git_oid_fromstr(&target_id, tagged_commit);
-	cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
-
-	cl_git_fail(git_tag_create_lightweight(
-                                          &object_id,
-                                          g_repo,
-                                          "e90810b",
-                                          target,
-                                          0));
-
-	git_oid_fromstr(&existing_object_id, tag2_id);
-	cl_assert(git_oid_cmp(&object_id, &existing_object_id) == 0);
-
-	git_object_free(target);
-}
-
-void test_tag_write__delete(void)
-{
-   // Delete an already existing tag
-	git_reference *ref_tag;
-
-	cl_git_pass(git_tag_delete(g_repo, "e90810b"));
-
-	cl_git_fail(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
-
-	git_reference_free(ref_tag);
-}