Skip to content

Commit 8d1c5db

Browse files
committed
Don't git fetch if sha revision is up-to-date
If you're using a sha as your revision parameter and the current HEAD is already pointing at that sha, there's no need to do a git fetch. Making this change should significantly reduce the number of calls made to the remote Git server; since the catalog hasn't changed, you'll be up-to-date and not do the fetch call.
1 parent f2b106f commit 8d1c5db

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/puppet/provider/vcsrepo/git.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,11 @@ def latest_revision
503503
# @return [String] Returns the tag/branch of the current repo if it's up to
504504
# date; otherwise returns the sha of the requested revision.
505505
def get_revision(rev = 'HEAD')
506+
current = at_path { git_with_identity('rev-parse', rev).strip }
507+
if @resource.value(:revision) == current
508+
# if already pointed at desired revision, it must be a SHA, so just return it
509+
return current
510+
end
506511
if @resource.value(:source)
507512
update_references
508513
else
@@ -514,7 +519,6 @@ def get_revision(rev = 'HEAD')
514519
return branch
515520
end
516521
end
517-
current = at_path { git_with_identity('rev-parse', rev).strip }
518522
if @resource.value(:revision)
519523
canonical = if tag_revision?
520524
# git-rev-parse will give you the hash of the tag object itself rather

spec/unit/puppet/provider/vcsrepo/git_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,8 @@ def branch_a_list(include_branch = nil?)
298298
it 'returns the current SHA' do
299299
resource[:revision] = 'currentsha'
300300
provider.stubs(:git).with('branch', '-a').returns(branch_a_list)
301-
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).returns('currentsha')
302-
provider.expects(:update_references)
301+
provider.expects(:git).with('rev-parse', '--revs-only', resource.value(:revision)).never
302+
provider.expects(:update_references).never
303303
expect(provider.revision).to eq(resource.value(:revision))
304304
end
305305
end

0 commit comments

Comments
 (0)