Search code examples
gitgithubchef-infrachef-solo

chef git :sync UnresolvableGitReference


I am facing a strange issue with git resource in chef. I am getting the UnresolvableGitReference error even though the repository and the tag exists.

compiled resource in the recipe: git("/opt/some-repo") do action [:sync] retries 0 retry_delay 2 default_guard_interpreter :default destination "/opt/some-repo" enable_checkout true revision "tags/v3.0.4" remote "origin" checkout_branch "deploy" declared_type :git cookbook_name :"some-cookbook" recipe_name "install" user "ubuntu" repository "[email protected]:someUser/some-repo.git" end

The instance can access the git repo and the reference.

git ls-remote '[email protected]:someUser/some-repo.git' 'tags/v3.0.4*' returns me the commit id.

The cookbook works fine in chef v11.8.2 however fails in chef v12.5.1


Solution

  • With the git resource you can use only the tag name 'v3.0.4'. If you need to specify that it is a tag, you can also use the full path: 'refs/tags/v3.0.4'.

    This worked before because Chef 11 checks against the reference sufix:

    found = refs.find { |m| m[1].end_with?(@new_resource.revision) }
    

    But this can be problematic as you might imagine. I think 'tags/v3.0.4' to work was never an expected behavior.

    Anyway, in Chef 12 the implementation has changed, and now searches by prefix, appending 'ref/tags/' and 'refs/heads/' to search for tags and branches respectively:

    def find_revision(refs, revision, suffix="")
      found = refs_search(refs, rev_match_pattern('refs/tags/', revision) + suffix)
      found = refs_search(refs, rev_match_pattern('refs/heads/', revision) + suffix) if found.empty?
      found = refs_search(refs, revision + suffix) if found.empty?
      found
    end
    
    def rev_match_pattern(prefix, revision)
      if revision.start_with?(prefix)
        revision
      else
        prefix + revision
      end
    end