Commits

Erik van Zijst committed 8ccdce9

tags: Fixed the tag parser to correctly treat the message field as optional.

Comments (0)

Files changed (11)

 		}
 	}
 
-	if( *buffer != '\n' )
-		return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. No new line before message");
+  tag->message = NULL;
+  if (buffer < buffer_end) {
+    if( *buffer != '\n' )
+      return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. No new line before message");
 
-	text_len = buffer_end - ++buffer;
+    text_len = buffer_end - ++buffer;
 
-	tag->message = git__malloc(text_len + 1);
-	if (tag->message == NULL)
-		return GIT_ENOMEM;
+    tag->message = git__malloc(text_len + 1);
+    if (tag->message == NULL)
+      return GIT_ENOMEM;
 
-	memcpy(tag->message, buffer, text_len);
-	tag->message[text_len] = '\0';
+    memcpy(tag->message, buffer, text_len);
+    tag->message[text_len] = '\0';
+  }
 
 	return GIT_SUCCESS;
 }

tests/resources/short_tag.git/HEAD

+ref: refs/heads/master

tests/resources/short_tag.git/config

+[core]
+	repositoryformatversion = 0
+	filemode = true
+	bare = true
+	logallrefupdates = true

tests/resources/short_tag.git/index

Binary file added.

tests/resources/short_tag.git/objects/4a/5ed60bafcf4638b7c8356bd4ce1916bfede93c

Binary file added.

tests/resources/short_tag.git/objects/4d/5fcadc293a348e88f777dc0920f11e7d71441c

Binary file added.

tests/resources/short_tag.git/objects/5d/a7760512a953e3c7c4e47e4392c7a4338fb729

+x�M�0@aלb. i�%1ƍ�pc��@������-��-

tests/resources/short_tag.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391

Binary file added.

tests/resources/short_tag.git/refs/heads/master

+4a5ed60bafcf4638b7c8356bd4ce1916bfede93c

tests/resources/short_tag.git/refs/tags/no_description

+5da7760512a953e3c7c4e47e4392c7a4338fb729
 static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
 static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
 static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
+static const char *short_tag_id = "5da7760512a953e3c7c4e47e4392c7a4338fb729";
+static const char *short_tagged_commit = "4a5ed60bafcf4638b7c8356bd4ce1916bfede93c";
 
 BEGIN_TEST(read0, "read and parse a tag from the repository")
 	git_repository *repo;
 	git_repository_free(repo);
 END_TEST
 
+#define SHORT_TAG_REPOSITORY_FOLDER TEST_RESOURCES "/short_tag.git/"
+
+BEGIN_TEST(read4, "read and parse a tag lacking a description")
+	git_repository *repo;
+	git_tag *short_tag;
+	git_commit *commit;
+	git_oid id, id_commit;
+
+	must_pass(git_repository_open(&repo, SHORT_TAG_REPOSITORY_FOLDER));
+
+	git_oid_fromstr(&id, short_tag_id);
+	git_oid_fromstr(&id_commit, short_tagged_commit);
+
+	must_pass(git_tag_lookup(&short_tag, repo, &id));
+	must_be_true(short_tag != NULL);
+
+	must_be_true(strcmp(git_tag_name(short_tag), "no_description") == 0);
+	must_be_true(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
+	must_be_true(short_tag->message == NULL);
+
+	must_pass(git_tag_target((git_object **)&commit, short_tag));
+	must_be_true(commit != NULL);
+
+	must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
+
+	git_tag_close(short_tag);
+	git_commit_close(commit);
+
+	git_repository_free(repo);
+END_TEST
 
 #define TAGGER_NAME "Vicent Marti"
 #define TAGGER_EMAIL "vicent@github.com"
 	ADD_TEST(read1);
 	ADD_TEST(read2);
 	ADD_TEST(read3);
+	ADD_TEST(read4);
 
 	ADD_TEST(write0);
 	ADD_TEST(write2);