Skip to content

Instantly share code, notes, and snippets.

@glarizza
Last active December 30, 2015 12:39
Show Gist options
  • Save glarizza/7830246 to your computer and use it in GitHub Desktop.
Save glarizza/7830246 to your computer and use it in GitHub Desktop.
Puppet::Type.type(:rcsrepo).provide(:git) do
desc "A Git provider for the Rcsrepo type"
confine :has_git => true
commands :git => 'git'
def exists?
File.directory?("#{resource[:path]}/.git")
end
def create
if resource[:source]
FileUtils.rm_rf(resource[:path]) if File.directory?(resource[:path])
git(['clone', resource[:source], resource[:path]])
git_lazy(['checkout', resource[:revision], '-f']) if resource[:revision] != 'HEAD'
else
FileUtils.mkdir_p(resource[:path]) unless File.directory?(resource[:path])
git(['init', resource[:path]])
end
end
def destroy
FileUtils.rm_rf(resource[:path])
end
def revision
git_lazy(['rev-parse', 'HEAD']).chomp
end
def revision=(value)
git_lazy(['fetch', 'origin'])
git_lazy(['checkout', value, '-f'])
end
def git_lazy(*args)
git(['--git-dir', File.join(resource[:path], '.git'), '--work-tree', resource[:path], *args])
end
end
## From Sydney, 2/14/2014
Puppet::Type.type(:rcsrepo).provide(:git) do
desc "The git provider for the rcsrepo type"
confine :has_git => :true
commands :git => 'git'
def check_for_directory(path)
File.directory?(path)
end
def prep_file_path(path)
FileUtils.rm_rf(path) if File.directory?(path)
end
def create_directory(path)
FileUtils.mkdir_p(path) unless File.directory?(path)
end
def git_lazy(*args)
git(['--work-tree', resource[:path], '--git-dir', File.join(resource[:path], '.git'), *args])
end
def exists?
check_for_directory("#{resource[:path]}/.git")
end
def create
if resource[:source]
prep_file_path(resource[:path])
git(['clone', resource[:source], resource[:path]])
else
create_directory(resource[:path])
git(['init', resource[:path]])
end
self.revision=(resource[:revision]) if resource[:revision] != 'HEAD'
end
def destroy
prep_file_path(resource[:path])
end
def revision
git_lazy(['rev-parse', 'HEAD']).chomp
end
def revision=(should)
git_lazy(['fetch', 'origin'])
git_lazy(['checkout', should, '-f'])
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment