summaryrefslogtreecommitdiff
path: root/lib/chef/provider/git.rb
diff options
context:
space:
mode:
authorJames Bence <jbence@mdsol.com>2014-09-24 09:30:04 -0700
committerJames Bence <jbence@mdsol.com>2014-09-24 09:30:04 -0700
commit6d4bca71ff197319988f716f67b426fb73662c59 (patch)
tree42465abf78edbc98e368e9d5bbb661aa5d2871f9 /lib/chef/provider/git.rb
parente9f23a3dfbb7c9d6ca742af2438c888572b0c3b1 (diff)
downloadchef-6d4bca71ff197319988f716f67b426fb73662c59.tar.gz
Add fallback search for exact revision entered
Diffstat (limited to 'lib/chef/provider/git.rb')
-rw-r--r--lib/chef/provider/git.rb16
1 files changed, 9 insertions, 7 deletions
diff --git a/lib/chef/provider/git.rb b/lib/chef/provider/git.rb
index 11a6761e6d..efa7340d40 100644
--- a/lib/chef/provider/git.rb
+++ b/lib/chef/provider/git.rb
@@ -236,7 +236,6 @@ class Chef
# named 'HEAD'.
@resolved_reference = git_ls_remote(rev_search_pattern)
refs = @resolved_reference.split("\n").map { |line| line.split("\t") }
- found = []
# First try for ^{} indicating the commit pointed to by an
# annotated tag.
# It is possible for a user to create a tag named 'HEAD'.
@@ -244,18 +243,21 @@ class Chef
# confusing. We avoid the issue by disallowing the use of
# annotated tags named 'HEAD'.
if rev_search_pattern != 'HEAD'
- found = refs_search(refs, "#{rev_match_pattern('refs/tags/', @new_resource.revision)}^{}")
- found = refs_search(refs, "#{rev_match_pattern('refs/heads/', @new_resource.revision)}^{}") if found.empty?
+ found = find_revision(refs, @new_resource.revision, '^{}')
else
found = refs_search(refs, 'HEAD')
end
- if found.empty?
- found = refs_search(refs, rev_match_pattern('refs/tags/', @new_resource.revision))
- found = refs_search(refs, rev_match_pattern('refs/heads/', @new_resource.revision)) if found.empty?
- end
+ found = find_revision(refs, @new_resource.revision) if found.empty?
found.size == 1 ? found.first[0] : nil
end
+ 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