Tag a remote git repository without cloning it
Is there a way to tag a remote git repository without having cloned it locally?
In order to correlate a code repository with开发者_Go百科 a config repository, I want to (as a CI build step) tag whatever is the current head of the config repository with build-n (where N is the current build number provided by jenkins).
The config repository isn't used as part of the build, I simply want an easy way to fetch the config revision as it was when for example version 1234 was built, and tagging it as "build-1234" seems like the simplest way to achieve this.
To have this as an answer: there is at the moment no way to do remote tagging with git, but if you have access in some way to the remote (bare) repository, you may be able to tag on the remote location.
For example, if you access the git repository via SSH, you can login using SSH, go to the (bare) repository and execute the tag command (git tag build-1234 master
) in the (bare) repository.
(I am not completely sure about the tool mentioned by @ruslan-kabalin)
It's possible to tag the current commit at the tip of a branch remotely, but not (as far as I can tell) with git porcelain or plumbing. We'll have to speak to a remote git receive-pack
directly.
Here's some python that uses dulwich to do what we want:
#!/usr/bin/env python
from dulwich.client import get_transport_and_path
import sys
def tag_remote_branch(repo_url, branch, tag):
client, path = get_transport_and_path(repo_url)
def determine_wants(refs):
tag_ref_name = 'refs/tags/%s' % tag
branch_ref_name = 'refs/heads/%s' % branch
# try not to overwrite an existing tag
if tag_ref_name in refs:
assert refs[tag_ref_name] == refs[branch_ref_name]
refs[tag_ref_name] = refs[branch_ref_name]
return refs
# We know the other end already has the object referred to by our tag, so
# our pack should contain nothing.
def generate_pack_contents(have, want):
return []
client.send_pack(path, determine_wants, generate_pack_contents)
if __name__ == '__main__':
repo_url, branch, tag = sys.argv[1:]
tag_remote_branch(repo_url, branch, tag)
Gitlab has an API for it. Pretty confident other might have an endpoint for this. http://docs.gitlab.com/ce/api/tags.html
精彩评论