Class: Gitolite::Repo
- Inherits:
-
Object
show all
- Includes:
- Utils
- Defined in:
- lib/gitolite/repo.rb
Constant Summary
collapse
- GIOLITE_ALL_GROUP =
'@all'
- RepoConfTemplate =
We check if there are users in addition to tenant with line, (repo_conf.rights_hash.values.flatten.size > 1) In case no, we do not give permission to tenant even
::Erubis::Eruby.new <<-eos
include "groups-defs/*.conf"
repo <%= repo_conf.repo_name %>
<% if repo_conf.rights_hash.values.flatten.size > 1 %>
<% repo_conf.rights_hash.each do |k, v| %>
<% unless v.empty? %>
<%=k%> = <%=v.join(' ') %>
<% end %>
<% end %>
<% end %>
eos
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
#gitolite_friendly, #is_subset?, #raise_gitolite_error, #validate_gitolite_conf_file
Constructor Details
#initialize(repo_name, configuration_, logger_, gitolite_path, gitolite_branch = 'master') ⇒ Repo
Returns a new instance of Repo.
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/gitolite/repo.rb', line 57
def initialize(repo_name, configuration_, logger_, gitolite_path, gitolite_branch = 'master')
@rights_hash = { 'R' => [], 'W' => [], 'RW' => [], 'RW+' => []}
@repo_name = repo_name
@user_groups = []
@commit_messages = []
@repo_conf_file_path = configuration_.repo_path(repo_name)
@repo_dir_path = configuration_.bare_repo_path(repo_name)
@gitolite_admin_repo ||= Git::FileAccess.new(gitolite_path, gitolite_branch)
@logger = logger_
if exists?
load_repo()
end
end
|
Instance Attribute Details
#commit_messages ⇒ Object
Returns the value of attribute commit_messages.
26
27
28
|
# File 'lib/gitolite/repo.rb', line 26
def commit_messages
@commit_messages
end
|
#logger ⇒ Object
Returns the value of attribute logger.
26
27
28
|
# File 'lib/gitolite/repo.rb', line 26
def logger
@logger
end
|
#repo_dir_path ⇒ Object
Returns the value of attribute repo_dir_path.
27
28
29
|
# File 'lib/gitolite/repo.rb', line 27
def repo_dir_path
@repo_dir_path
end
|
#repo_name ⇒ Object
Returns the value of attribute repo_name.
26
27
28
|
# File 'lib/gitolite/repo.rb', line 26
def repo_name
@repo_name
end
|
#rights_hash ⇒ Object
Returns the value of attribute rights_hash.
26
27
28
|
# File 'lib/gitolite/repo.rb', line 26
def rights_hash
@rights_hash
end
|
#user_groups ⇒ Object
Returns the value of attribute user_groups.
26
27
28
|
# File 'lib/gitolite/repo.rb', line 26
def user_groups
@user_groups
end
|
Class Method Details
.get_repo_type(repo_name) ⇒ Object
51
52
53
|
# File 'lib/gitolite/repo.rb', line 51
def get_repo_type(repo_name)
repo_name.match(/\-\-cm\-\-/) ? 'component' : 'service'
end
|
Instance Method Details
#add_all_with_rights(access_rights) ⇒ Object
119
120
121
|
# File 'lib/gitolite/repo.rb', line 119
def add_all_with_rights(access_rights)
add_username_with_rights(GIOLITE_ALL_GROUP, access_rights)
end
|
#add_user_group_with_rights(group_name, access_rights) ⇒ Object
115
116
117
|
# File 'lib/gitolite/repo.rb', line 115
def add_user_group_with_rights(group_name, access_rights)
add_username_with_rights("@#{group_name}", access_rights)
end
|
#add_username_with_rights(username, access_rights) ⇒ Object
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/gitolite/repo.rb', line 95
def add_username_with_rights(username, access_rights)
if access_rights.nil?
return remove_username(username)
end
unless @rights_hash[access_rights.upcase].include?(username)
remove_username(username)
@rights_hash[access_rights.upcase] << username
@commit_messages << "Added access rights ('#{access_rights}') for user/group '#{username}', in repo '#{@repo_name}'"
if username.match(/^@/)
@user_groups << username
end
end
end
|
#any_changes? ⇒ Boolean
131
132
133
|
# File 'lib/gitolite/repo.rb', line 131
def any_changes?
!@commit_messages.empty?
end
|
#commit_changes(override_commit_message = nil) ⇒ Object
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/gitolite/repo.rb', line 135
def commit_changes(override_commit_message = nil)
unless @commit_messages.empty?
content = configuration_content()
validate_gitolite_conf_file(content)
commit_msg = override_commit_message || @commit_messages.join(', ')
@gitolite_admin_repo.add_file(@repo_conf_file_path,content)
@gitolite_admin_repo.commit(commit_msg)
@logger.info(commit_msg)
else
@logger.info("There has been no changes on repo '#{@repo_name}' skipping gitolite commit.")
end
end
|
#exists? ⇒ Boolean
127
128
129
|
# File 'lib/gitolite/repo.rb', line 127
def exists?
!@gitolite_admin_repo.file_content(@repo_conf_file_path).nil?
end
|
#file_content(path, branch = Git::Adapter::DEFAULT_BRANCH) ⇒ Object
151
152
153
|
# File 'lib/gitolite/repo.rb', line 151
def file_content(path, branch=Git::Adapter::DEFAULT_BRANCH)
Git::FileAccess.new(@repo_dir_path, branch).file_content(path)
end
|
#file_content_and_size(path, branch = Git::Adapter::DEFAULT_BRANCH) ⇒ Object
155
156
157
|
# File 'lib/gitolite/repo.rb', line 155
def file_content_and_size(path, branch=Git::Adapter::DEFAULT_BRANCH)
Git::FileAccess.new(@repo_dir_path, branch).file_content_and_size(path)
end
|
#file_list(depth = nil, branch = Git::Adapter::DEFAULT_BRANCH) ⇒ Object
159
160
161
|
# File 'lib/gitolite/repo.rb', line 159
def file_list(depth=nil, branch=Git::Adapter::DEFAULT_BRANCH)
Git::FileAccess.new(@repo_dir_path, branch).ls_r(depth)
end
|
#remove_group(group_name) ⇒ Object
91
92
93
|
# File 'lib/gitolite/repo.rb', line 91
def remove_group(group_name)
remove_username("@#{group_name}")
end
|
#remove_username(username) ⇒ Object
82
83
84
85
86
87
88
89
|
# File 'lib/gitolite/repo.rb', line 82
def remove_username(username)
@rights_hash.each do |k,v|
if v.include?(username)
v.delete(username)
@commit_messages << "Removed access rights ('#{k}') for user/group '#{username}'"
end
end
end
|
#rights_for_username(username) ⇒ Object
72
73
74
75
76
77
78
79
80
|
# File 'lib/gitolite/repo.rb', line 72
def rights_for_username(username)
@rights_hash.each do |k,v|
if v.include?(username)
return k
end
end
return nil
end
|