lib/gitolite/gitolite_admin.rb in jbox-gitolite-1.1.2 vs lib/gitolite/gitolite_admin.rb in jbox-gitolite-1.1.3
- old
+ new
@@ -61,31 +61,35 @@
end
#Writes all changed aspects out to the file system
#will also stage all changes
def save
- Dir.chdir(@gl_admin.working_dir) do
- #Process config file (if loaded, i.e. may be modified)
- if @config
- new_conf = @config.to_file(@confdir)
- @gl_admin.add(new_conf)
- end
+ confdir = File.join(@gl_admin.working_dir, @confdir)
+ keydir = File.join(@gl_admin.working_dir, @keydir)
- #Process ssh keys (if loaded, i.e. may be modified)
- if @ssh_keys
- files = list_keys(@keydir).map{|f| File.basename f}
- keys = @ssh_keys.values.map{|f| f.map {|t| t.filename}}.flatten
+ #Process config file (if loaded, i.e. may be modified)
+ if @config
+ new_conf = @config.to_file(confdir).gsub(@gl_admin.working_dir + '/', '')
+ @gl_admin.git.native(:add, {:chdir => @gl_admin.working_dir}, new_conf)
+ end
- to_remove = (files - keys).map { |f| File.join(@keydir, f)}
- @gl_admin.remove(to_remove)
+ #Process ssh keys (if loaded, i.e. may be modified)
+ if @ssh_keys
+ files = list_keys(keydir).map{|f| File.basename f}
+ keys = @ssh_keys.values.map{|f| f.map {|t| t.filename}}.flatten
- @ssh_keys.each_value do |key|
- #Write only keys from sets that has been modified
- next if key.respond_to?(:dirty?) && !key.dirty?
- key.each do |k|
- @gl_admin.add(k.to_file(@keydir))
- end
+ to_remove = (files - keys).map { |f| File.join(@keydir, f) }
+ to_remove.each do |key|
+ @gl_admin.git.native(:rm, {:chdir => @gl_admin.working_dir}, key)
+ end
+
+ @ssh_keys.each_value do |key|
+ #Write only keys from sets that has been modified
+ next if key.respond_to?(:dirty?) && !key.dirty?
+ key.each do |k|
+ new_key = k.to_file(keydir).gsub(@gl_admin.working_dir + '/', '')
+ @gl_admin.git.native(:add, {:chdir => @gl_admin.working_dir}, new_key)
end
end
end
end
@@ -170,10 +174,14 @@
def config
@config ||= load_config
end
+ def config=(config)
+ @config = config
+ end
+
private
#Loads all .pub files in the gitolite-admin
#keydir directory
def load_keys(path = nil)
path ||= File.join(@path, @keydir)
@@ -195,12 +203,10 @@
path ||= File.join(@path, @confdir, @conf)
Config.new(path)
end
def list_keys(path)
- Dir.chdir(path) do
- keys = Dir.glob("**/*.pub")
- keys
- end
+ keys = %x[ find #{path} -name "\*.pub" -type f -exec basename {} \\; ].chomp.split("\n")
+ keys
end
end
end