Permalink
Browse files

Check for an existing gitolite-admin repository on bootstrap

  • Loading branch information...
wingrunr21 committed Oct 23, 2011
1 parent 461f1c4 commit 36dabd226caa40ff052677719adaacbfe667b36c
Showing with 28 additions and 11 deletions.
  1. +28 −11 lib/gitolite/gitolite_admin.rb
@@ -27,9 +27,15 @@ def initialize(path, options = {})
# conf
# gitolite.conf
# keydir
- #
- # TODO: Make this method detect an existing gitolite-admin repo
def self.bootstrap(path, options = {})
+ if self.is_gitolite_admin_repo?(path)
+ if options[:overwrite]
+ FileUtils.rm_rf(File.join(path, '*'))
+ else
+ return self.new(path)
+ end
+ end
+
FileUtils.mkdir_p([File.join(path,"conf"), File.join(path,"keydir")])
options[:perm] ||= "RW+"
@@ -78,10 +84,9 @@ def save
#to origin
#
#TODO: generate a better commit message
- #TODO: add the ability to specify the message, remote, and branch
+ #TODO: add the ability to specify the remote and branch
#TODO: detect existance of origin instead of just dying
- def apply(commit_message = nil)
- commit_message ||= "Commit by gitolite gem"
+ def apply(commit_message = "Commit by gitolite gem")
@gl_admin.commit_index(commit_message)
@gl_admin.git.push({}, "origin", "master")
end
@@ -100,6 +105,24 @@ def rm_key(key)
@ssh_keys[key.owner].delete key
end
+ #Checks to see if the given path is a gitolite-admin repository
+ #A valid repository contains a conf folder, keydir folder,
+ #and a configuration file within the conf folder
+ def self.is_gitolite_admin_repo?(dir)
+ # First check if it is a git repository
+ begin
+ Grit::Repo.new(dir)
+ rescue Grit::InvalidGitRepositoryError
+ return false
+ end
+
+ # If we got here it is a valid git repo,
+ # now check directory structure
+ File.exists?(File.join(dir, 'conf')) &&
+ File.exists?(File.join(dir, 'keydir')) &&
+ !Dir.glob(File.join(dir, 'conf', '*.conf')).empty?
+ end
+
private
#Loads all .pub files in the gitolite-admin
#keydir directory
@@ -122,11 +145,5 @@ def list_keys(path)
keys
end
end
-
- #Checks to see if the given path is a gitolite-admin repository
- #A valid repository contains a conf folder, keydir folder,
- #and a configuration file within the conf folder
- def detect_gitolite_repository(dir)
- end
end
end

0 comments on commit 36dabd2

Please sign in to comment.