lorem
lorem

Reputation: 1199

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

Upvotes: 0

Views: 192

Answers (2)

zuazo
zuazo

Reputation: 5748

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

Upvotes: 2

lorem
lorem

Reputation: 1199

So, I played around a bit and found out the issue. the tag of a git repo for property revision need not be preceded by tags/. I don't know in which version of chef it changed but, I confirm that it worked in chef version 11.8.2.

Therefore revision "tags/v3.0.4" changes to revision "v3.0.4"

Upvotes: 0

Related Questions