lib/gitolite/gitolite_admin.rb in gitolite-0.0.3.alpha vs lib/gitolite/gitolite_admin.rb in gitolite-1.0.0

- old
+ new

@@ -4,21 +4,25 @@ CONF = "gitolite.conf" CONFDIR = "conf" KEYDIR = "keydir" + #Gitolite gem's default git commit message + DEFAULT_COMMIT_MSG = "Committed by the gitolite gem" + # Intialize with the path to # the gitolite-admin repository def initialize(path, options = {}) + @path = path @gl_admin = Grit::Repo.new(path) @conf = options[:conf] || CONF @confdir = options[:confdir] || CONFDIR @keydir = options[:keydir] || KEYDIR - @ssh_keys = load_keys(File.join(path, @keydir)) - @config = Config.new(File.join(path, @confdir, @conf)) + # Load the ssh keys and the configuration + load_data end # This method will bootstrap a gitolite-admin repo # at the given path. A typical gitolite-admin # repo will have the following tree: @@ -78,32 +82,63 @@ end end end end + # This method will destroy all local tracked changes, resetting the local gitolite + # git repo to HEAD and reloading the entire repository + # Note that this will also delete all untracked files + def reset! + Dir.chdir(@gl_admin.working_dir) do + @gl_admin.git.reset({:hard => true}, 'HEAD') + @gl_admin.git.clean({:d => true, :q => true, :f => true}) + end + reload! + end + + # This method will destroy the in-memory data structures and reload everything + # from the file system + def reload! + load_data + end + #commits all staged changes and pushes back #to origin # #TODO: generate a better commit message #TODO: add the ability to specify the remote and branch #TODO: detect existance of origin instead of just dying - def apply(commit_message = "Commit by gitolite gem") + def apply(commit_message = DEFAULT_COMMIT_MSG) @gl_admin.commit_index(commit_message) @gl_admin.git.push({}, "origin", "master") end - def save_and_apply + def save_and_apply(commit_message = DEFAULT_COMMIT_MSG) self.save - self.apply + self.apply(commit_message) end + # Updates the repo with changes from remote master + def update(options = {}) + options = {:reset => true, :rebase => false }.merge(options) + + reset! if options[:reset] + + Dir.chdir(@gl_admin.working_dir) do + @gl_admin.git.pull({:rebase => options[:rebase]}, "origin", "master") + end + + reload! + end + def add_key(key) raise "Key must be of type Gitolite::SSHKey!" unless key.instance_of? Gitolite::SSHKey @ssh_keys[key.owner] << key end def rm_key(key) + raise "Key must be of type Gitolite::SSHKey!" unless key.instance_of? Gitolite::SSHKey @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, @@ -122,9 +157,14 @@ File.exists?(File.join(dir, 'keydir')) && !Dir.glob(File.join(dir, 'conf', '*.conf')).empty? end private + def load_data + @ssh_keys = load_keys(File.join(@path, @keydir)) + @config = Config.new(File.join(@path, @confdir, @conf)) + end + #Loads all .pub files in the gitolite-admin #keydir directory def load_keys(path) keys = Hash.new {|k,v| k[v] = []}