Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Groups are now stored internally without an @ sign in front

  • Loading branch information...
commit 0ec737eefe9a36cdf44cbb8f1756ebbceaa4a30c 1 parent ec66320
@wingrunr21 authored
View
13 lib/gitolite/config.rb
@@ -42,7 +42,7 @@ def get_repo(repo)
@repos[name]
end
- def add_group(group, owerwrite = false)
+ def add_group(group, overwrite = false)
raise ArgumentError, "Group must be of type Gitolite::Config::Group!" unless group.instance_of? Gitolite::Config::Group
@groups[group.name] = group
end
@@ -67,10 +67,8 @@ def to_file(path=".", filename=@filename)
new_conf = File.join(path, filename)
File.open(new_conf, "w") do |f|
- @groups.each do |k,v|
- members = v.users.join(' ')
- f.write "#{v.gl_name.ljust(20)}= #{members}\n"
- end
+ #Output groups
+ @groups.each_value {|group| f.write group.to_s }
gitweb_descs = []
@repos.each do |k, v|
@@ -138,7 +136,7 @@ def process_config(config)
@repos[c].set_git_config(key, value)
end
#group definition
- when /^@(\S+) = ?(.*)/
+ when /^#{Group::PREPEND_CHAR}(\S+) = ?(.*)/
group = $1
users = $2.split
@@ -174,7 +172,8 @@ def process_config(config)
end
end
- def normalize_name(context, constant)
+ # Normalizes the various different input objects to Strings
+ def normalize_name(context, constant = nil)
case context
when constant
context.name
View
9 lib/gitolite/config/group.rb
@@ -6,8 +6,12 @@ class Config
class Group
attr_accessor :name, :users
+ PREPEND_CHAR = '@'
+
def initialize(name)
- @name = name
+ # naively remove the prepend char
+ # I don't think you can have two of them in a group name
+ @name = name.gsub(PREPEND_CHAR, '')
@users = []
end
@@ -39,7 +43,8 @@ def size
def to_s
members = @users.join(' ')
- "#{@name.ljust(20)}= #{members}\n"
+ name = "#{PREPEND_CHAR}#{@name}"
+ "#{name.ljust(20)}= #{members}\n"
end
end
end
View
35 spec/config_spec.rb
@@ -217,6 +217,41 @@
r2.description.should == r.description
end
end
+ end
+
+ describe "group management" do
+ before :each do
+ @config = Gitolite::Config.new(File.join(conf_dir, 'complicated.conf'))
+ end
+
+ describe "#has_group?" do
+ it 'should find the staff group using a symbol' do
+ @config.has_group?(:staff).should be true
+ end
+
+ it 'should find the staff group using a string' do
+ @config.has_group?('staff').should be true
+ end
+
+ it 'should find the staff group using a Gitolite::Config::Group object' do
+ g = Gitolite::Config::Group.new("staff")
+ @config.has_group?(g).should be true
+ end
+ end
+
+ describe "#get_group" do
+ it 'should return the Gitolite::Config::Group object for the group name String' do
+ g = @config.get_group("staff")
+ g.is_a?(Gitolite::Config::Group).should be true
+ g.size.should == 6
+ end
+
+ it 'should return the Gitolite::Config::Group object for the group name Symbol' do
+ g = @config.get_group(:staff)
+ g.is_a?(Gitolite::Config::Group).should be true
+ g.size.should == 6
+ end
+ end
describe "#add_group" do
it 'should throw an ArgumentError for non-Gitolite::Config::Group objects passed in' do
View
14 spec/group_spec.rb
@@ -4,15 +4,21 @@
describe Gitolite::Config::Group do
describe "#new" do
it "should create a new group with an empty list of users" do
- group = Gitolite::Config::Group.new("@testgroup")
+ group = Gitolite::Config::Group.new("testgroup")
group.users.empty?.should be true
- group.name.should == "@testgroup"
+ group.name.should == "testgroup"
+ end
+
+ it "should create a new group with a name containing #{Gitolite::Config::Group::PREPEND_CHAR}" do
+ name = "#{Gitolite::Config::Group::PREPEND_CHAR}testgroup"
+ group = Gitolite::Config::Group.new(name)
+ group.name.should == "testgroup"
end
end
describe "users" do
before :each do
- @group = Gitolite::Config::Group.new('@testgroup')
+ @group = Gitolite::Config::Group.new('testgroup')
end
describe "#add_user" do
@@ -113,7 +119,7 @@
end
describe "#to_s" do
- group = Gitolite::Config::Group.new("@testgroup")
+ group = Gitolite::Config::Group.new("testgroup")
group.add_users("bob", "joe", "sam", "sue")
group.to_s.should == "@testgroup = bob joe sam sue\n" #10 spaces after @testgroup
end
Please sign in to comment.
Something went wrong with that request. Please try again.