Search code examples
rubygitgrit

Creating tags with Grit


I'm trying to create a tag in my git repository via Grit, but I'm not sure that the library supports referenced tags. It's easy to create a tag like this:

Grit::Tag.create_tag_object(repo, params, actor)

But that will only create a lightweight tag. To have a referenced tag I need to create a ref to the tag also, but the implementation of update_ref looks like this:

def update_ref(head, commit_sha)
  return nil if !commit_sha || (commit_sha.size != 40)
  self.git.fs_write("refs/heads/#{head}", commit_sha)
  commit_sha
end

... which means that I can only create head refs, not a tag ref. There is nothing in the Ref or Tag classes that does anything.

Does anyone have an idea on how to create a reference to a commit via Grit?


Solution

  • I've created a new Tag linking to a commit as follows:

    log = @repo.git.tag( { 'f' => true }, tag_name, commit_sha )
    

    And got:

    Updated tag 'new_tag' (was 0000000)
    $ git tag
    ...
    new_tag
    ...
    $ git show new_tag
    commit e74b99a0ff706993e200939ee00079182f75ec29
    ...