Commit 3272620f724737f4dbb5e8c02f1610946435cd29
1 parent
8ceb9408
Exists in
master
and in
4 other branches
lib/ refactoring. Module Gitlabhq renamed to Gitlab
Showing
25 changed files
with
326 additions
and
324 deletions
Show diff stats
app/controllers/application_controller.rb
... | ... | @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base |
5 | 5 | protect_from_forgery |
6 | 6 | helper_method :abilities, :can? |
7 | 7 | |
8 | - rescue_from Gitlabhq::Gitolite::AccessDenied do |exception| | |
8 | + rescue_from Gitlab::Gitolite::AccessDenied do |exception| | |
9 | 9 | render "errors/gitolite", :layout => "error" |
10 | 10 | end |
11 | 11 | ... | ... |
app/controllers/projects_controller.rb
... | ... | @@ -45,7 +45,7 @@ class ProjectsController < ApplicationController |
45 | 45 | format.js |
46 | 46 | end |
47 | 47 | end |
48 | - rescue Gitlabhq::Gitolite::AccessDenied | |
48 | + rescue Gitlab::Gitolite::AccessDenied | |
49 | 49 | render :js => "location.href = '#{errors_githost_path}'" and return |
50 | 50 | rescue StandardError => ex |
51 | 51 | @project.errors.add(:base, "Cant save project. Please try again later") | ... | ... |
app/helpers/application_helper.rb
app/models/commit.rb
app/models/key.rb
... | ... | @@ -38,14 +38,14 @@ class Key < ActiveRecord::Base |
38 | 38 | end |
39 | 39 | |
40 | 40 | def update_repository |
41 | - Gitlabhq::GitHost.system.new.configure do |c| | |
41 | + Gitlab::GitHost.system.new.configure do |c| | |
42 | 42 | c.update_keys(identifier, key) |
43 | 43 | c.update_projects(projects) |
44 | 44 | end |
45 | 45 | end |
46 | 46 | |
47 | 47 | def repository_delete_key |
48 | - Gitlabhq::GitHost.system.new.configure do |c| | |
48 | + Gitlab::GitHost.system.new.configure do |c| | |
49 | 49 | #delete key file is there is no identically deploy keys |
50 | 50 | if !is_deploy_key || Key.where(:identifier => identifier).count() == 0 |
51 | 51 | c.delete_key(identifier) | ... | ... |
app/models/merge_request.rb
... | ... | @@ -82,7 +82,7 @@ class MergeRequest < ActiveRecord::Base |
82 | 82 | end |
83 | 83 | |
84 | 84 | def check_if_can_be_merged |
85 | - self.state = if GitlabMerge.new(self, self.author).can_be_merged? | |
85 | + self.state = if Gitlab::Merge.new(self, self.author).can_be_merged? | |
86 | 86 | CAN_BE_MERGED |
87 | 87 | else |
88 | 88 | CANNOT_BE_MERGED |
... | ... | @@ -184,7 +184,7 @@ class MergeRequest < ActiveRecord::Base |
184 | 184 | end |
185 | 185 | |
186 | 186 | def automerge!(current_user) |
187 | - if GitlabMerge.new(self, current_user).merge | |
187 | + if Gitlab::Merge.new(self, current_user).merge | |
188 | 188 | self.merge!(current_user.id) |
189 | 189 | true |
190 | 190 | end | ... | ... |
app/models/project/repository_trait.rb
... | ... | @@ -38,7 +38,7 @@ module Project::RepositoryTrait |
38 | 38 | end |
39 | 39 | |
40 | 40 | def satellite |
41 | - @satellite ||= Gitlabhq::Satellite.new(self) | |
41 | + @satellite ||= Gitlab::Satellite.new(self) | |
42 | 42 | end |
43 | 43 | |
44 | 44 | def write_hook(name, content) |
... | ... | @@ -65,7 +65,7 @@ module Project::RepositoryTrait |
65 | 65 | end |
66 | 66 | |
67 | 67 | def url_to_repo |
68 | - Gitlabhq::GitHost.url_to_repo(path) | |
68 | + Gitlab::GitHost.url_to_repo(path) | |
69 | 69 | end |
70 | 70 | |
71 | 71 | def path_to_repo |
... | ... | @@ -73,13 +73,13 @@ module Project::RepositoryTrait |
73 | 73 | end |
74 | 74 | |
75 | 75 | def update_repository |
76 | - Gitlabhq::GitHost.system.update_project(path, self) | |
76 | + Gitlab::GitHost.system.update_project(path, self) | |
77 | 77 | |
78 | 78 | write_hooks if File.exists?(path_to_repo) |
79 | 79 | end |
80 | 80 | |
81 | 81 | def destroy_repository |
82 | - Gitlabhq::GitHost.system.destroy_project(self) | |
82 | + Gitlab::GitHost.system.destroy_project(self) | |
83 | 83 | end |
84 | 84 | |
85 | 85 | def repo_exists? | ... | ... |
app/models/protected_branch.rb
... | ... | @@ -7,7 +7,7 @@ class ProtectedBranch < ActiveRecord::Base |
7 | 7 | after_destroy :update_repository |
8 | 8 | |
9 | 9 | def update_repository |
10 | - Gitlabhq::GitHost.system.update_project(project.path, project) | |
10 | + Gitlab::GitHost.system.update_project(project.path, project) | |
11 | 11 | end |
12 | 12 | |
13 | 13 | def commit | ... | ... |
app/models/users_project.rb
config/environment.rb
config/initializers/gitlabhq/20_grit_ext.rb
... | ... | @@ -0,0 +1,20 @@ |
1 | +module Gitlab | |
2 | + module Encode | |
3 | + extend self | |
4 | + | |
5 | + def utf8 message | |
6 | + return nil unless message | |
7 | + | |
8 | + hash = CharlockHolmes::EncodingDetector.detect(message) rescue {} | |
9 | + if hash[:encoding] | |
10 | + CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8') | |
11 | + else | |
12 | + message | |
13 | + end.force_encoding("utf-8") | |
14 | + # Prevent app from crash cause of | |
15 | + # encoding errors | |
16 | + rescue | |
17 | + "" | |
18 | + end | |
19 | + end | |
20 | +end | ... | ... |
... | ... | @@ -0,0 +1,21 @@ |
1 | +require File.join(Rails.root, "lib", "gitlab", "gitolite") | |
2 | + | |
3 | +module Gitlab | |
4 | + class GitHost | |
5 | + def self.system | |
6 | + Gitlab::Gitolite | |
7 | + end | |
8 | + | |
9 | + def self.admin_uri | |
10 | + GIT_HOST["admin_uri"] | |
11 | + end | |
12 | + | |
13 | + def self.url_to_repo(path) | |
14 | + if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | |
15 | + "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | |
16 | + else | |
17 | + "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | |
18 | + end | |
19 | + end | |
20 | + end | |
21 | +end | ... | ... |
... | ... | @@ -0,0 +1,157 @@ |
1 | +require 'gitolite' | |
2 | +require 'timeout' | |
3 | +require 'fileutils' | |
4 | + | |
5 | +module Gitlab | |
6 | + class Gitolite | |
7 | + class AccessDenied < StandardError; end | |
8 | + | |
9 | + def self.update_project(path, project) | |
10 | + self.new.configure { |git| git.update_project(path, project) } | |
11 | + end | |
12 | + | |
13 | + def self.destroy_project(project) | |
14 | + self.new.configure { |git| git.destroy_project(project) } | |
15 | + end | |
16 | + | |
17 | + def pull | |
18 | + # create tmp dir | |
19 | + @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") | |
20 | + Dir.mkdir @local_dir | |
21 | + | |
22 | + `git clone #{GitHost.admin_uri} #{@local_dir}/gitolite` | |
23 | + end | |
24 | + | |
25 | + def push | |
26 | + Dir.chdir(File.join(@local_dir, "gitolite")) | |
27 | + `git add -A` | |
28 | + `git commit -am "Gitlab"` | |
29 | + `git push` | |
30 | + Dir.chdir(Rails.root) | |
31 | + | |
32 | + FileUtils.rm_rf(@local_dir) | |
33 | + end | |
34 | + | |
35 | + def configure | |
36 | + status = Timeout::timeout(20) do | |
37 | + File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| | |
38 | + begin | |
39 | + f.flock(File::LOCK_EX) | |
40 | + pull | |
41 | + yield(self) | |
42 | + push | |
43 | + ensure | |
44 | + f.flock(File::LOCK_UN) | |
45 | + end | |
46 | + end | |
47 | + end | |
48 | + rescue Exception => ex | |
49 | + Gitlab::Logger.error(ex.message) | |
50 | + raise Gitolite::AccessDenied.new("gitolite timeout") | |
51 | + end | |
52 | + | |
53 | + def destroy_project(project) | |
54 | + FileUtils.rm_rf(project.path_to_repo) | |
55 | + | |
56 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
57 | + conf = ga_repo.config | |
58 | + conf.rm_repo(project.path) | |
59 | + ga_repo.save | |
60 | + end | |
61 | + | |
62 | + #update or create | |
63 | + def update_keys(user, key) | |
64 | + File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
65 | + end | |
66 | + | |
67 | + def delete_key(user) | |
68 | + File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub")) | |
69 | + `cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub` | |
70 | + end | |
71 | + | |
72 | + # update or create | |
73 | + def update_project(repo_name, project) | |
74 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
75 | + conf = ga_repo.config | |
76 | + repo = update_project_config(project, conf) | |
77 | + conf.add_repo(repo, true) | |
78 | + | |
79 | + ga_repo.save | |
80 | + end | |
81 | + | |
82 | + # Updates many projects and uses project.path as the repo path | |
83 | + # An order of magnitude faster than update_project | |
84 | + def update_projects(projects) | |
85 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
86 | + conf = ga_repo.config | |
87 | + | |
88 | + projects.each do |project| | |
89 | + repo = update_project_config(project, conf) | |
90 | + conf.add_repo(repo, true) | |
91 | + end | |
92 | + | |
93 | + ga_repo.save | |
94 | + end | |
95 | + | |
96 | + def update_project_config(project, conf) | |
97 | + repo_name = project.path | |
98 | + | |
99 | + repo = if conf.has_repo?(repo_name) | |
100 | + conf.get_repo(repo_name) | |
101 | + else | |
102 | + ::Gitolite::Config::Repo.new(repo_name) | |
103 | + end | |
104 | + | |
105 | + name_readers = project.repository_readers | |
106 | + name_writers = project.repository_writers | |
107 | + name_masters = project.repository_masters | |
108 | + | |
109 | + pr_br = project.protected_branches.map(&:name).join(" ") | |
110 | + | |
111 | + repo.clean_permissions | |
112 | + | |
113 | + # Deny access to protected branches for writers | |
114 | + unless name_writers.blank? || pr_br.blank? | |
115 | + repo.add_permission("-", pr_br, name_writers) | |
116 | + end | |
117 | + | |
118 | + # Add read permissions | |
119 | + repo.add_permission("R", "", name_readers) unless name_readers.blank? | |
120 | + | |
121 | + # Add write permissions | |
122 | + repo.add_permission("RW+", "", name_writers) unless name_writers.blank? | |
123 | + repo.add_permission("RW+", "", name_masters) unless name_masters.blank? | |
124 | + | |
125 | + repo | |
126 | + end | |
127 | + | |
128 | + def admin_all_repo | |
129 | + ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
130 | + conf = ga_repo.config | |
131 | + owner_name = "" | |
132 | + | |
133 | + # Read gitolite-admin user | |
134 | + # | |
135 | + begin | |
136 | + repo = conf.get_repo("gitolite-admin") | |
137 | + owner_name = repo.permissions[0]["RW+"][""][0] | |
138 | + raise StandardError if owner_name.blank? | |
139 | + rescue => ex | |
140 | + puts "Cant determine gitolite-admin owner".red | |
141 | + raise StandardError | |
142 | + end | |
143 | + | |
144 | + # @ALL repos premission for gitolite owner | |
145 | + repo_name = "@all" | |
146 | + repo = if conf.has_repo?(repo_name) | |
147 | + conf.get_repo(repo_name) | |
148 | + else | |
149 | + ::Gitolite::Config::Repo.new(repo_name) | |
150 | + end | |
151 | + | |
152 | + repo.add_permission("RW+", "", owner_name) | |
153 | + conf.add_repo(repo, true) | |
154 | + ga_repo.save | |
155 | + end | |
156 | + end | |
157 | +end | ... | ... |
... | ... | @@ -0,0 +1,60 @@ |
1 | +module Gitlab | |
2 | + class Merge | |
3 | + attr_accessor :project, :merge_request, :user | |
4 | + | |
5 | + def initialize(merge_request, user) | |
6 | + self.user = user | |
7 | + self.merge_request = merge_request | |
8 | + self.project = merge_request.project | |
9 | + end | |
10 | + | |
11 | + def can_be_merged? | |
12 | + result = false | |
13 | + process do |repo, output| | |
14 | + result = !(output =~ /CONFLICT/) | |
15 | + end | |
16 | + result | |
17 | + end | |
18 | + | |
19 | + def merge | |
20 | + process do |repo, output| | |
21 | + if output =~ /CONFLICT/ | |
22 | + false | |
23 | + else | |
24 | + repo.git.push({}, "origin", merge_request.target_branch) | |
25 | + true | |
26 | + end | |
27 | + end | |
28 | + end | |
29 | + | |
30 | + def process | |
31 | + Grit::Git.with_timeout(30.seconds) do | |
32 | + lock_file = File.join(Rails.root, "tmp", "merge_repo_#{project.path}.lock") | |
33 | + | |
34 | + File.open(lock_file, "w+") do |f| | |
35 | + f.flock(File::LOCK_EX) | |
36 | + | |
37 | + unless project.satellite.exists? | |
38 | + raise "You should run: rake gitlab:app:enable_automerge" | |
39 | + end | |
40 | + | |
41 | + project.satellite.clear | |
42 | + | |
43 | + Dir.chdir(project.satellite.path) do | |
44 | + merge_repo = Grit::Repo.new('.') | |
45 | + merge_repo.git.sh "git reset --hard" | |
46 | + merge_repo.git.sh "git fetch origin" | |
47 | + merge_repo.git.sh "git config user.name \"#{user.name}\"" | |
48 | + merge_repo.git.sh "git config user.email \"#{user.email}\"" | |
49 | + merge_repo.git.sh "git checkout -b #{merge_request.target_branch} origin/#{merge_request.target_branch}" | |
50 | + output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch) | |
51 | + yield(merge_repo, output) | |
52 | + end | |
53 | + end | |
54 | + end | |
55 | + | |
56 | + rescue Grit::Git::GitTimeout | |
57 | + return false | |
58 | + end | |
59 | + end | |
60 | +end | ... | ... |
... | ... | @@ -0,0 +1,41 @@ |
1 | +module Gitlab | |
2 | + class Satellite | |
3 | + | |
4 | + PARKING_BRANCH = "__parking_branch" | |
5 | + | |
6 | + attr_accessor :project | |
7 | + | |
8 | + def initialize project | |
9 | + self.project = project | |
10 | + end | |
11 | + | |
12 | + def create | |
13 | + `git clone #{project.url_to_repo} #{path}` | |
14 | + end | |
15 | + | |
16 | + def path | |
17 | + File.join(Rails.root, "tmp", "repo_satellites", project.path) | |
18 | + end | |
19 | + | |
20 | + def exists? | |
21 | + File.exists? path | |
22 | + end | |
23 | + | |
24 | + #will be deleted all branches except PARKING_BRANCH | |
25 | + def clear | |
26 | + Dir.chdir(path) do | |
27 | + heads = Grit::Repo.new(".").heads.map{|head| head.name} | |
28 | + if heads.include? PARKING_BRANCH | |
29 | + `git checkout #{PARKING_BRANCH}` | |
30 | + else | |
31 | + `git checkout -b #{PARKING_BRANCH}` | |
32 | + end | |
33 | + heads.delete(PARKING_BRANCH) | |
34 | + heads.each do |head| | |
35 | + `git branch -D #{head}` | |
36 | + end | |
37 | + end | |
38 | + end | |
39 | + | |
40 | + end | |
41 | +end | ... | ... |
lib/gitlab_merge.rb
... | ... | @@ -1,58 +0,0 @@ |
1 | -class GitlabMerge | |
2 | - attr_accessor :project, :merge_request, :user | |
3 | - | |
4 | - def initialize(merge_request, user) | |
5 | - self.user = user | |
6 | - self.merge_request = merge_request | |
7 | - self.project = merge_request.project | |
8 | - end | |
9 | - | |
10 | - def can_be_merged? | |
11 | - result = false | |
12 | - process do |repo, output| | |
13 | - result = !(output =~ /CONFLICT/) | |
14 | - end | |
15 | - result | |
16 | - end | |
17 | - | |
18 | - def merge | |
19 | - process do |repo, output| | |
20 | - if output =~ /CONFLICT/ | |
21 | - false | |
22 | - else | |
23 | - repo.git.push({}, "origin", merge_request.target_branch) | |
24 | - true | |
25 | - end | |
26 | - end | |
27 | - end | |
28 | - | |
29 | - def process | |
30 | - Grit::Git.with_timeout(30.seconds) do | |
31 | - lock_file = File.join(Rails.root, "tmp", "merge_repo_#{project.path}.lock") | |
32 | - | |
33 | - File.open(lock_file, "w+") do |f| | |
34 | - f.flock(File::LOCK_EX) | |
35 | - | |
36 | - unless project.satellite.exists? | |
37 | - raise "You should run: rake gitlab:app:enable_automerge" | |
38 | - end | |
39 | - | |
40 | - project.satellite.clear | |
41 | - | |
42 | - Dir.chdir(project.satellite.path) do | |
43 | - merge_repo = Grit::Repo.new('.') | |
44 | - merge_repo.git.sh "git reset --hard" | |
45 | - merge_repo.git.sh "git fetch origin" | |
46 | - merge_repo.git.sh "git config user.name \"#{user.name}\"" | |
47 | - merge_repo.git.sh "git config user.email \"#{user.email}\"" | |
48 | - merge_repo.git.sh "git checkout -b #{merge_request.target_branch} origin/#{merge_request.target_branch}" | |
49 | - output = merge_repo.git.pull({}, "--no-ff", "origin", merge_request.source_branch) | |
50 | - yield(merge_repo, output) | |
51 | - end | |
52 | - end | |
53 | - end | |
54 | - | |
55 | - rescue Grit::Git::GitTimeout | |
56 | - return false | |
57 | - end | |
58 | -end |
lib/gitlabhq/encode.rb
... | ... | @@ -1,20 +0,0 @@ |
1 | -module Gitlabhq | |
2 | - module Encode | |
3 | - extend self | |
4 | - | |
5 | - def utf8 message | |
6 | - return nil unless message | |
7 | - | |
8 | - hash = CharlockHolmes::EncodingDetector.detect(message) rescue {} | |
9 | - if hash[:encoding] | |
10 | - CharlockHolmes::Converter.convert(message, hash[:encoding], 'UTF-8') | |
11 | - else | |
12 | - message | |
13 | - end.force_encoding("utf-8") | |
14 | - # Prevent app from crash cause of | |
15 | - # encoding errors | |
16 | - rescue | |
17 | - "" | |
18 | - end | |
19 | - end | |
20 | -end |
lib/gitlabhq/git_host.rb
... | ... | @@ -1,21 +0,0 @@ |
1 | -require File.join(Rails.root, "lib", "gitlabhq", "gitolite") | |
2 | - | |
3 | -module Gitlabhq | |
4 | - class GitHost | |
5 | - def self.system | |
6 | - Gitlabhq::Gitolite | |
7 | - end | |
8 | - | |
9 | - def self.admin_uri | |
10 | - GIT_HOST["admin_uri"] | |
11 | - end | |
12 | - | |
13 | - def self.url_to_repo(path) | |
14 | - if !GIT_HOST["port"] or GIT_HOST["port"] == 22 | |
15 | - "#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{path}.git" | |
16 | - else | |
17 | - "ssh://#{GIT_HOST["git_user"]}@#{GIT_HOST["host"]}:#{GIT_HOST["port"]}/#{path}.git" | |
18 | - end | |
19 | - end | |
20 | - end | |
21 | -end |
lib/gitlabhq/gitolite.rb
... | ... | @@ -1,157 +0,0 @@ |
1 | -require 'gitolite' | |
2 | -require 'timeout' | |
3 | -require 'fileutils' | |
4 | - | |
5 | -module Gitlabhq | |
6 | - class Gitolite | |
7 | - class AccessDenied < StandardError; end | |
8 | - | |
9 | - def self.update_project(path, project) | |
10 | - self.new.configure { |git| git.update_project(path, project) } | |
11 | - end | |
12 | - | |
13 | - def self.destroy_project(project) | |
14 | - self.new.configure { |git| git.destroy_project(project) } | |
15 | - end | |
16 | - | |
17 | - def pull | |
18 | - # create tmp dir | |
19 | - @local_dir = File.join(Dir.tmpdir,"gitlabhq-gitolite-#{Time.now.to_i}") | |
20 | - Dir.mkdir @local_dir | |
21 | - | |
22 | - `git clone #{GitHost.admin_uri} #{@local_dir}/gitolite` | |
23 | - end | |
24 | - | |
25 | - def push | |
26 | - Dir.chdir(File.join(@local_dir, "gitolite")) | |
27 | - `git add -A` | |
28 | - `git commit -am "Gitlab"` | |
29 | - `git push` | |
30 | - Dir.chdir(Rails.root) | |
31 | - | |
32 | - FileUtils.rm_rf(@local_dir) | |
33 | - end | |
34 | - | |
35 | - def configure | |
36 | - status = Timeout::timeout(20) do | |
37 | - File.open(File.join(Dir.tmpdir,"gitlabhq-gitolite.lock"), "w+") do |f| | |
38 | - begin | |
39 | - f.flock(File::LOCK_EX) | |
40 | - pull | |
41 | - yield(self) | |
42 | - push | |
43 | - ensure | |
44 | - f.flock(File::LOCK_UN) | |
45 | - end | |
46 | - end | |
47 | - end | |
48 | - rescue Exception => ex | |
49 | - Gitlabhq::Logger.error(ex.message) | |
50 | - raise Gitolite::AccessDenied.new("gitolite timeout") | |
51 | - end | |
52 | - | |
53 | - def destroy_project(project) | |
54 | - FileUtils.rm_rf(project.path_to_repo) | |
55 | - | |
56 | - ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
57 | - conf = ga_repo.config | |
58 | - conf.rm_repo(project.path) | |
59 | - ga_repo.save | |
60 | - end | |
61 | - | |
62 | - #update or create | |
63 | - def update_keys(user, key) | |
64 | - File.open(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub"), 'w') {|f| f.write(key.gsub(/\n/,'')) } | |
65 | - end | |
66 | - | |
67 | - def delete_key(user) | |
68 | - File.unlink(File.join(@local_dir, 'gitolite/keydir',"#{user}.pub")) | |
69 | - `cd #{File.join(@local_dir,'gitolite')} ; git rm keydir/#{user}.pub` | |
70 | - end | |
71 | - | |
72 | - # update or create | |
73 | - def update_project(repo_name, project) | |
74 | - ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
75 | - conf = ga_repo.config | |
76 | - repo = update_project_config(project, conf) | |
77 | - conf.add_repo(repo, true) | |
78 | - | |
79 | - ga_repo.save | |
80 | - end | |
81 | - | |
82 | - # Updates many projects and uses project.path as the repo path | |
83 | - # An order of magnitude faster than update_project | |
84 | - def update_projects(projects) | |
85 | - ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
86 | - conf = ga_repo.config | |
87 | - | |
88 | - projects.each do |project| | |
89 | - repo = update_project_config(project, conf) | |
90 | - conf.add_repo(repo, true) | |
91 | - end | |
92 | - | |
93 | - ga_repo.save | |
94 | - end | |
95 | - | |
96 | - def update_project_config(project, conf) | |
97 | - repo_name = project.path | |
98 | - | |
99 | - repo = if conf.has_repo?(repo_name) | |
100 | - conf.get_repo(repo_name) | |
101 | - else | |
102 | - ::Gitolite::Config::Repo.new(repo_name) | |
103 | - end | |
104 | - | |
105 | - name_readers = project.repository_readers | |
106 | - name_writers = project.repository_writers | |
107 | - name_masters = project.repository_masters | |
108 | - | |
109 | - pr_br = project.protected_branches.map(&:name).join(" ") | |
110 | - | |
111 | - repo.clean_permissions | |
112 | - | |
113 | - # Deny access to protected branches for writers | |
114 | - unless name_writers.blank? || pr_br.blank? | |
115 | - repo.add_permission("-", pr_br, name_writers) | |
116 | - end | |
117 | - | |
118 | - # Add read permissions | |
119 | - repo.add_permission("R", "", name_readers) unless name_readers.blank? | |
120 | - | |
121 | - # Add write permissions | |
122 | - repo.add_permission("RW+", "", name_writers) unless name_writers.blank? | |
123 | - repo.add_permission("RW+", "", name_masters) unless name_masters.blank? | |
124 | - | |
125 | - repo | |
126 | - end | |
127 | - | |
128 | - def admin_all_repo | |
129 | - ga_repo = ::Gitolite::GitoliteAdmin.new(File.join(@local_dir,'gitolite')) | |
130 | - conf = ga_repo.config | |
131 | - owner_name = "" | |
132 | - | |
133 | - # Read gitolite-admin user | |
134 | - # | |
135 | - begin | |
136 | - repo = conf.get_repo("gitolite-admin") | |
137 | - owner_name = repo.permissions[0]["RW+"][""][0] | |
138 | - raise StandardError if owner_name.blank? | |
139 | - rescue => ex | |
140 | - puts "Cant determine gitolite-admin owner".red | |
141 | - raise StandardError | |
142 | - end | |
143 | - | |
144 | - # @ALL repos premission for gitolite owner | |
145 | - repo_name = "@all" | |
146 | - repo = if conf.has_repo?(repo_name) | |
147 | - conf.get_repo(repo_name) | |
148 | - else | |
149 | - ::Gitolite::Config::Repo.new(repo_name) | |
150 | - end | |
151 | - | |
152 | - repo.add_permission("RW+", "", owner_name) | |
153 | - conf.add_repo(repo, true) | |
154 | - ga_repo.save | |
155 | - end | |
156 | - end | |
157 | -end |
lib/gitlabhq/logger.rb
lib/gitlabhq/satellite.rb
... | ... | @@ -1,41 +0,0 @@ |
1 | -module Gitlabhq | |
2 | - class Satellite | |
3 | - | |
4 | - PARKING_BRANCH = "__parking_branch" | |
5 | - | |
6 | - attr_accessor :project | |
7 | - | |
8 | - def initialize project | |
9 | - self.project = project | |
10 | - end | |
11 | - | |
12 | - def create | |
13 | - `git clone #{project.url_to_repo} #{path}` | |
14 | - end | |
15 | - | |
16 | - def path | |
17 | - File.join(Rails.root, "tmp", "repo_satellites", project.path) | |
18 | - end | |
19 | - | |
20 | - def exists? | |
21 | - File.exists? path | |
22 | - end | |
23 | - | |
24 | - #will be deleted all branches except PARKING_BRANCH | |
25 | - def clear | |
26 | - Dir.chdir(path) do | |
27 | - heads = Grit::Repo.new(".").heads.map{|head| head.name} | |
28 | - if heads.include? PARKING_BRANCH | |
29 | - `git checkout #{PARKING_BRANCH}` | |
30 | - else | |
31 | - `git checkout -b #{PARKING_BRANCH}` | |
32 | - end | |
33 | - heads.delete(PARKING_BRANCH) | |
34 | - heads.each do |head| | |
35 | - `git branch -D #{head}` | |
36 | - end | |
37 | - end | |
38 | - end | |
39 | - | |
40 | - end | |
41 | -end |
lib/tasks/gitlab/enable_automerge.rake
spec/models/protected_branch_spec.rb
... | ... | @@ -43,7 +43,7 @@ describe ProtectedBranch do |
43 | 43 | subject { ProtectedBranch.new(:project => project) } |
44 | 44 | |
45 | 45 | it "updates the branch's project repo permissions" do |
46 | - Gitlabhq::GitHost.should_receive(:system).and_return(gitolite) | |
46 | + Gitlab::GitHost.should_receive(:system).and_return(gitolite) | |
47 | 47 | gitolite.should_receive(:update_project).with(project.path, project) |
48 | 48 | |
49 | 49 | subject.update_repository | ... | ... |