Is there a way to tag a remote git repository without having cloned it locally?
In order to correlate a code repository with a config repository, I want to
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)