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.
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/gitolite/repo.rb', line 40
def initialize(repo_name, configuration_, logger_, gitolite_path, gitolite_branch="master")
@rights_hash = { 'R' => [], 'W' => [], 'RW' => ['@tenants'], '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.
9
10
11
|
# File 'lib/gitolite/repo.rb', line 9
def commit_messages
@commit_messages
end
|
#logger ⇒ Object
Returns the value of attribute logger.
9
10
11
|
# File 'lib/gitolite/repo.rb', line 9
def logger
@logger
end
|
#repo_name ⇒ Object
Returns the value of attribute repo_name.
9
10
11
|
# File 'lib/gitolite/repo.rb', line 9
def repo_name
@repo_name
end
|
#rights_hash ⇒ Object
Returns the value of attribute rights_hash.
9
10
11
|
# File 'lib/gitolite/repo.rb', line 9
def rights_hash
@rights_hash
end
|
#user_groups ⇒ Object
Returns the value of attribute user_groups.
9
10
11
|
# File 'lib/gitolite/repo.rb', line 9
def user_groups
@user_groups
end
|
Class Method Details
.get_repo_type(repo_name) ⇒ Object
34
35
36
|
# File 'lib/gitolite/repo.rb', line 34
def get_repo_type(repo_name)
repo_name.match(/\-\-cm\-\-/) ? 'component' : 'service'
end
|
Instance Method Details
#add_all_with_rights(access_rights) ⇒ Object
94
95
96
|
# File 'lib/gitolite/repo.rb', line 94
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
90
91
92
|
# File 'lib/gitolite/repo.rb', line 90
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
# File 'lib/gitolite/repo.rb', line 70
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
106
107
108
|
# File 'lib/gitolite/repo.rb', line 106
def any_changes?
!@commit_messages.empty?
end
|
#commit_changes(override_commit_message = nil) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/gitolite/repo.rb', line 110
def commit_changes(override_commit_message = nil)
unless @commit_messages.empty?
content = file_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
102
103
104
|
# File 'lib/gitolite/repo.rb', line 102
def exists?
!@gitolite_admin_repo.file_content(@repo_conf_file_path).nil?
end
|
#file_content ⇒ Object
126
127
128
|
# File 'lib/gitolite/repo.rb', line 126
def file_content()
RepoConfTemplate.result(:repo_conf => self)
end
|
#remove_group(group_name) ⇒ Object
66
67
68
|
# File 'lib/gitolite/repo.rb', line 66
def remove_group(group_name)
remove_username("@#{group_name}")
end
|
#remove_username(username) ⇒ Object
57
58
59
60
61
62
63
64
|
# File 'lib/gitolite/repo.rb', line 57
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
|