def tag_create(repo,
               tag,
               author=None,
               message=None,
               annotated=False,
               objectish="HEAD",
               tag_time=None,
               tag_timezone=None,
               sign=False):
    """Creates a tag in git via dulwich calls:

    Args:
      repo: Path to repository
      tag: tag string
      author: tag author (optional, if annotated is set)
      message: tag message (optional)
      annotated: whether to create an annotated tag
      objectish: object the tag should point at, defaults to HEAD
      tag_time: Optional time for annotated tag
      tag_timezone: Optional timezone for annotated tag
      sign: GPG Sign the tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity(r.get_config_stack())
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            if tag_time is None:
                tag_time = int(time.time())
            tag_obj.tag_time = tag_time
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            if sign:
                import gpg
                with gpg.Context(armor=True) as c:
                    tag_obj.signature, unused_result = c.sign(
                        tag_obj.as_raw_string())
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[_make_tag_ref(tag)] = tag_id
Example #2
0
    def test_serialize_simple(self):
        x = Tag()
        x.tagger = "Jelmer Vernooij <*****@*****.**>"
        x.name = "0.1"
        x.message = "Tag 0.1"
        x.object = (3, "d80c186a03f423a81b39df39dc87fd269736ca86")
        x.tag_time = 423423423
        x.tag_timezone = 0
        self.assertEquals("""object d80c186a03f423a81b39df39dc87fd269736ca86
type blob
tag 0.1
tagger Jelmer Vernooij <*****@*****.**> 423423423 +0000

Tag 0.1""", x.as_raw_string())
Example #3
0
def tag_create(
        repo, tag, author=None, message=None, annotated=False,
        objectish="HEAD", tag_time=None, tag_timezone=None,
        sign=False):
    """Creates a tag in git via dulwich calls:

    :param repo: Path to repository
    :param tag: tag string
    :param author: tag author (optional, if annotated is set)
    :param message: tag message (optional)
    :param annotated: whether to create an annotated tag
    :param objectish: object the tag should point at, defaults to HEAD
    :param tag_time: Optional time for annotated tag
    :param tag_timezone: Optional timezone for annotated tag
    :param sign: GPG Sign the tag
    """

    with open_repo_closing(repo) as r:
        object = parse_object(r, objectish)

        if annotated:
            # Create the tag object
            tag_obj = Tag()
            if author is None:
                # TODO(jelmer): Don't use repo private method.
                author = r._get_user_identity(r.get_config_stack())
            tag_obj.tagger = author
            tag_obj.message = message
            tag_obj.name = tag
            tag_obj.object = (type(object), object.id)
            if tag_time is None:
                tag_time = int(time.time())
            tag_obj.tag_time = tag_time
            if tag_timezone is None:
                # TODO(jelmer) Use current user timezone rather than UTC
                tag_timezone = 0
            elif isinstance(tag_timezone, str):
                tag_timezone = parse_timezone(tag_timezone)
            tag_obj.tag_timezone = tag_timezone
            if sign:
                import gpg
                with gpg.Context(armor=True) as c:
                    tag_obj.signature, unused_result = c.sign(
                        tag_obj.as_raw_string())
            r.object_store.add_object(tag_obj)
            tag_id = tag_obj.id
        else:
            tag_id = object.id

        r.refs[_make_tag_ref(tag)] = tag_id
Example #4
0
    def test_serialize_simple(self):
        x = Tag()
        x.tagger = "Jelmer Vernooij <*****@*****.**>"
        x.name = "0.1"
        x.message = "Tag 0.1"
        x.object = (3, "d80c186a03f423a81b39df39dc87fd269736ca86")
        x.tag_time = 423423423
        x.tag_timezone = 0
        self.assertEquals("""object d80c186a03f423a81b39df39dc87fd269736ca86
type blob
tag 0.1
tagger Jelmer Vernooij <*****@*****.**> 423423423 +0000

Tag 0.1""", x.as_raw_string())