Commit 81234673a1f7cd5d92f0dd5f03d1442ec1ed2d62

Carlos Martín Nieto 2011-04-05T16:53:32

tag: discover the target type if needed Don't blindly pass the target type to git_tag_type2string as it will give an empty string on GIT_OBJ_ANY which would cause us to create an invalid tag object. Signed-off-by: Carlos Martín Nieto <cmn@elego.de>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/src/tag.c b/src/tag.c
index ef58e09..994389c 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -209,6 +209,14 @@ static int tag_create(
 		return error;
 	}
 
+	/* Try to find out what the type is */
+	if (target_type == GIT_OBJ_ANY) {
+		size_t _unused;
+		error = git_odb_read_header(&_unused, &target_type, repo->db, target);
+		if (error < GIT_SUCCESS)
+			return error;
+	}
+
 	type_str = git_object_type2string(target_type);
 
 	tagger_str_len = git_signature__write(&tagger_str, "tagger", tagger);