Commit 23123151e035f3565f7c9c93c1bbdb56c7cd6914

David Glesser 2011-05-30T09:03:55

Set the oid when a tag already exists. When a tag already exists, it can be useful to directly have the oid of the existed tag, just after trying to add it.

diff --git a/include/git2/tag.h b/include/git2/tag.h
index 3fc6b44..086e4a6 100644
--- a/include/git2/tag.h
+++ b/include/git2/tag.h
@@ -135,7 +135,9 @@ GIT_EXTERN(const char *) git_tag_message(git_tag *t);
  * Create a new tag in the repository from an OID
  *
  * @param oid Pointer where to store the OID of the
- *	newly created tag
+ *	newly created tag. If the tag already exists, this parameter
+ * will be the oid of the existed tag, and the function will
+ * return a GIT_EEXISTS error code.
  *
  * @param repo Repository where to store the tag
  *
diff --git a/src/tag.c b/src/tag.c
index 4132eef..6ae51b6 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -205,8 +205,10 @@ static int tag_create(
 
 	switch (error) {
 	case GIT_SUCCESS:
-		if (!allow_ref_overwrite)
+		if (!allow_ref_overwrite) {
+			git_oid_cpy(oid, git_reference_oid(new_ref));
 			return git__throw(GIT_EEXISTS, "Tag already exists");
+		}
 		should_update_ref = 1;
 		
 		/* Fall trough */