lib/gitauth/repo.rb in brownbeagle-gitauth-0.0.4.1 vs lib/gitauth/repo.rb in brownbeagle-gitauth-0.0.4.2

- old
+ new

@@ -17,14 +17,16 @@ #++ require 'fileutils' module GitAuth class Repo < SaveableClass(:repositories) + include GitAuth::Loggable + NAME_RE = /^([\w\_\-\.\+]+(\.git)?)$/i def self.get(name) - GitAuth::Logger.debug "Getting Repo w/ name: '#{name}'" + logger.debug "Getting Repo w/ name: '#{name}'" (all || []).detect { |r| r.name == name } end def self.create(name, path = name) return false if name.nil? || path.nil? @@ -95,16 +97,32 @@ self.class.save! end def make_empty! tmp_path = "/tmp/gitauth-#{rand(100000)}-#{Time.now.to_i}" - FileUtils.mkdir(tmp_path) - system('git', 'clone', real_path, "#{tmp_path}/current-repo") + logger.info "Creating temporary dir at #{tmp_path}" + FileUtils.mkdir_p("#{tmp_path}/current-repo") + logger.info "Changing to new directory" Dir.chdir("#{tmp_path}/current-repo") do - IO.popen("touch .gitignore && git commit -am 'Initial Empty Repository' && git push origin master") { |f| f.close } + logger.info "Marking as git repo" + GitAuth.run "git init" + logger.info "Touching .gitignore" + GitAuth.run "touch .gitignore" + # Configure it + GitAuth.run "git config push.default current" + logger.info "Commiting" + GitAuth.run "git add ." + GitAuth.run "git commit -am 'Initialize Empty Repository'" + # Push the changes to the actual repository + logger.info "Adding origin #{self.real_path}" + GitAuth.run "git remote add origin '#{self.real_path}'" + logger.info "Pushing..." + GitAuth.run "git push origin master" end - FileUtils.rm_rf(tmp_path) + ensure + logger.info "Cleaning up old tmp file" + FileUtils.rm_rf(tmp_path) if File.directory?(tmp_path) end def execute_post_create_hook! script = File.expand_path("~/.gitauth/post-create") if File.executable?(script) @@ -122,10 +140,12 @@ @permissions[type] ||= [] @permissions[type] << whom.to_s @permissions[type].uniq! end - def has_permissions_for(whom, type) + def has_permissions_for(type, whom) + whom = GitAuth.get_user_or_group(whom) if whom.is_a?(String) + logger.info "Checking if #{whom.to_s} can #{type} #{self.name}" !(@permissions[type] || []).detect do |reader| reader = GitAuth.get_user_or_group(reader) reader == whom || (reader.is_a?(Group) && reader.member?(whom, true)) end.nil? end \ No newline at end of file