Merge commit 'master' into discussions

Conflicts:
	app/assets/stylesheets/sections/notes.scss
	app/contexts/notes/load_context.rb
	app/models/project.rb
	app/observers/note_observer.rb
	app/roles/votes.rb
	app/views/commit/show.html.haml
	app/views/merge_requests/_show.html.haml
	app/views/merge_requests/diffs.js.haml
	app/views/merge_requests/show.js.haml
	app/views/notes/_note.html.haml
	features/steps/project/project_merge_requests.rb
	spec/models/note_spec.rb
This commit is contained in:
Riyad Preukschas 2013-01-15 00:52:25 +01:00
commit 3022786948
930 changed files with 80374 additions and 103682 deletions

View file

@ -78,6 +78,7 @@ module Gitlab
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :closed]
attrs[:label_list] = params[:labels] if params[:labels].present?
IssueObserver.current_user = current_user
if @issue.update_attributes attrs
present @issue, with: Entities::Issue
else

View file

@ -13,7 +13,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes
get ":id/notes" do
@notes = user_project.common_notes
@notes = user_project.notes.common
present paginate(@notes), with: Entities::Note
end
@ -25,7 +25,7 @@ module Gitlab
# Example Request:
# GET /projects/:id/notes/:note_id
get ":id/notes/:note_id" do
@note = user_project.common_notes.find(params[:note_id])
@note = user_project.notes.common.find(params[:note_id])
present @note, with: Entities::Note
end

View file

@ -9,7 +9,7 @@ module Gitlab
# Example Request:
# GET /projects
get do
@projects = paginate current_user.projects
@projects = paginate current_user.authorized_projects
present @projects, with: Entities::Project
end
@ -257,7 +257,7 @@ module Gitlab
per_page = params[:per_page] || 20
ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
commits = user_project.commits(ref, nil, per_page, page * per_page)
commits = user_project.repository.commits(ref, nil, per_page, page * per_page)
present CommitDecorator.decorate(commits), with: Entities::RepoCommit
end
@ -375,10 +375,10 @@ module Gitlab
ref = params[:sha]
commit = user_project.commit ref
commit = user_project.repository.commit ref
not_found! "Commit" unless commit
tree = Tree.new commit.tree, user_project, ref, params[:filepath]
tree = Tree.new commit.tree, ref, params[:filepath]
not_found! "File" unless tree.try(:tree)
content_type tree.mime_type

View file

@ -33,6 +33,9 @@ module ExtractsPath
# extract_ref("v2.0.0/README.md")
# # => ['v2.0.0', 'README.md']
#
# extract_ref('/gitlab/vagrant/tree/master/app/models/project.rb')
# # => ['master', 'app/models/project.rb']
#
# extract_ref('issues/1234/app/models/project.rb')
# # => ['issues/1234', 'app/models/project.rb']
#
@ -47,6 +50,13 @@ module ExtractsPath
return pair unless @project
# Remove project, actions and all other staff from path
input.gsub!(/^\/#{Regexp.escape(@project.path_with_namespace)}/, "")
input.gsub!(/^\/(tree|commits|blame|blob|refs)\//, "") # remove actions
input.gsub!(/\?.*$/, "") # remove stamps suffix
input.gsub!(/.atom$/, "") # remove rss feed
input.gsub!(/\/edit$/, "") # remove edit route part
if input.match(/^([[:alnum:]]{40})(.+)/)
# If the ref appears to be a SHA, we're done, just split the string
pair = $~.captures
@ -58,7 +68,7 @@ module ExtractsPath
id = input
id += '/' unless id.ends_with?('/')
valid_refs = @project.ref_names
valid_refs = @project.repository.ref_names
valid_refs.select! { |v| id.start_with?("#{v}/") }
if valid_refs.length != 1
@ -98,13 +108,15 @@ module ExtractsPath
request.format = :atom
end
@ref, @path = extract_ref(params[:id])
path = CGI::unescape(request.fullpath.dup)
@ref, @path = extract_ref(path)
@id = File.join(@ref, @path)
@commit = CommitDecorator.decorate(@project.commit(@ref))
@commit = CommitDecorator.decorate(@project.repository.commit(@ref))
@tree = Tree.new(@commit.tree, @project, @ref, @path)
@tree = Tree.new(@commit.tree, @ref, @path)
@tree = TreeDecorator.new(@tree)
raise InvalidPathError if @tree.invalid?

View file

@ -82,7 +82,7 @@ module Gitlab
end
def destroy_project(project)
FileUtils.rm_rf(project.path_to_repo)
FileUtils.rm_rf(project.repository.path_to_repo)
conf.rm_repo(project.path_with_namespace)
end
@ -138,9 +138,9 @@ module Gitlab
::Gitolite::Config::Repo.new(repo_name)
end
name_readers = project.repository_readers
name_writers = project.repository_writers
name_masters = project.repository_masters
name_readers = project.team.repository_readers
name_writers = project.team.repository_writers
name_masters = project.team.repository_masters
pr_br = project.protected_branches.map(&:name).join("$ ")

View file

@ -17,10 +17,6 @@ module Grack
# Pass Gitolite update hook
ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
# Need this patch due to the rails mount
@env['PATH_INFO'] = @request.path
@env['SCRIPT_NAME'] = ""
# Find project by PATH_INFO from env
if m = /^\/([\w\.\/-]+)\.git/.match(@request.path_info).to_a
self.project = Project.find_with_namespace(m.last)

View file

@ -22,14 +22,16 @@ module Gitlab
h[:parents] = self.parents.collect do |p|
[p.id,0,0]
end
h[:author] = author.name
h[:author] = {
name: author.name,
email: author.email
}
h[:time] = time
h[:space] = space
h[:refs] = refs.collect{|r|r.name}.join(" ") unless refs.nil?
h[:id] = sha
h[:date] = date
h[:message] = message
h[:login] = author.email
h
end

View file

@ -17,14 +17,14 @@ module Gitlab
@commits = collect_commits
@days = index_commits
end
def to_json(*args)
{
days: @days.compact.map { |d| [d.day, d.strftime("%b")] },
commits: @commits.map(&:to_graph_hash)
}.to_json(*args)
end
protected
# Get commits from repository
@ -97,7 +97,7 @@ module Gitlab
if leaves.empty?
return
end
space = find_free_space(leaves.last.time..leaves.first.time)
space = find_free_space(leaves, map)
leaves.each{|l| l.space = space}
# and mark it as reserved
min_time = leaves.last.time
@ -119,7 +119,7 @@ module Gitlab
# Visit branching chains
leaves.each do |l|
parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space == 0}
parents = l.parents.collect.select{|p| map.include? p.id and map[p.id].space.zero?}
for p in parents
place_chain(map[p.id], map, l.time)
end
@ -132,18 +132,29 @@ module Gitlab
end
end
def find_free_space(time_range)
def find_free_space(leaves, map)
time_range = leaves.last.time..leaves.first.time
reserved = []
for day in time_range
reserved += @_reserved[day]
end
space = 1
space = base_space(leaves, map)
while reserved.include? space do
space += 1
end
space
end
def base_space(leaves, map)
parents = []
leaves.each do |l|
parents.concat l.parents.collect.select{|p| map.include? p.id and map[p.id].space.nonzero?}
end
space = parents.map{|p| map[p.id].space}.max || 0
space += 1
end
# Takes most left subtree branch of commits
# which don't have space mark yet.
#
@ -156,13 +167,13 @@ module Gitlab
leaves.push(commit) if commit.space.zero?
while true
parent = commit.parents.collect.select do |p|
map.include? p.id and map[p.id].space == 0
end
return leaves if commit.parents.count.zero?
return leaves unless map.include? commit.parents.first.id
return leaves if parent.count.zero?
commit = map[commit.parents.first.id]
return leaves unless commit.space.zero?
commit = map[parent.first.id]
leaves.push(commit)
end
end

View file

@ -170,7 +170,7 @@ module Gitlab
end
def reference_commit(identifier)
if @project.valid_repo? && commit = @project.commit(identifier)
if @project.valid_repo? && commit = @project.repository.commit(identifier)
link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}"))
end
end

View file

@ -16,7 +16,7 @@ module Gitlab
def execute
# Create new dir if missing
new_dir_path = File.join(Gitlab.config.gitolite.repos_path, new_dir)
system("mkdir -m 770 #{new_dir_path}") unless File.exists?(new_dir_path)
FileUtils.mkdir( new_dir_path, mode: 0770 ) unless File.exists?(new_dir_path)
old_path = File.join(Gitlab.config.gitolite.repos_path, old_dir, "#{project.path}.git")
new_path = File.join(new_dir_path, "#{project.path}.git")
@ -25,17 +25,18 @@ module Gitlab
raise ProjectMoveError.new("Destination #{new_path} already exists")
end
if system("mv #{old_path} #{new_path}")
begin
FileUtils.mv( old_path, new_path )
log_info "Project #{project.name} was moved from #{old_path} to #{new_path}"
true
else
rescue Exception => e
message = "Project #{project.name} cannot be moved from #{old_path} to #{new_path}"
log_info "Error! #{message}"
log_info "Error! #{message} (#{e.message})"
raise ProjectMoveError.new(message)
end
end
protected
protected
def log_info message
Gitlab::AppLogger.info message

View file

@ -6,6 +6,10 @@ module Gitlab
default_regex
end
def project_name_regex
/\A[a-zA-Z][a-zA-Z0-9_\-\. ]*\z/
end
def path_regex
default_regex
end

View file

@ -31,7 +31,7 @@ module Gitlab
merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch)
# remove source branch
if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch)
if merge_request.should_remove_source_branch && !project.repository.root_ref?(merge_request.source_branch)
# will raise CommandFailed when push fails
merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}")
end

View file

@ -1,4 +1,6 @@
module Gitlab
class SatelliteNotExistError < StandardError; end
module Satellite
class Satellite
PARKING_BRANCH = "__parking_branch"
@ -9,8 +11,12 @@ module Gitlab
@project = project
end
def raise_no_satellite
raise SatelliteNotExistError.new("Satellite doesn't exist")
end
def clear_and_update!
raise "Satellite doesn't exist" unless exists?
raise_no_satellite unless exists?
delete_heads!
clear_working_dir!
@ -18,7 +24,13 @@ module Gitlab
end
def create
`git clone #{project.url_to_repo} #{path}`
create_cmd = "git clone #{project.url_to_repo} #{path}"
if system(create_cmd)
true
else
Gitlab::GitLogger.error("Failed to create satellite for #{project.name_with_namespace}")
false
end
end
def exists?
@ -29,7 +41,7 @@ module Gitlab
# * Changes the current directory to the satellite's working dir
# * Yields
def lock
raise "Satellite doesn't exist" unless exists?
raise_no_satellite unless exists?
File.open(lock_file, "w+") do |f|
f.flock(File::LOCK_EX)
@ -49,7 +61,7 @@ module Gitlab
end
def repo
raise "Satellite doesn't exist" unless exists?
raise_no_satellite unless exists?
@repo ||= Grit::Repo.new(path)
end

11
lib/gitolited.rb Normal file
View file

@ -0,0 +1,11 @@
# == Gitolited mixin
#
# Provide a shortcut to Gitlab::Gitolite instance by gitolite
#
# Used by Project, UsersProject, etc
#
module Gitolited
def gitolite
Gitlab::Gitolite.new
end
end

View file

@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Version 4.1
# This file was placed here by GitLab. It makes sure that your pushed commits
# will be processed properly.

47
lib/static_model.rb Normal file
View file

@ -0,0 +1,47 @@
# Provides an ActiveRecord-like interface to a model whose data is not persisted to a database.
module StaticModel
extend ActiveSupport::Concern
module ClassMethods
# Used by ActiveRecord's polymorphic association to set object_id
def primary_key
'id'
end
# Used by ActiveRecord's polymorphic association to set object_type
def base_class
self
end
end
# Used by AR for fetching attributes
#
# Pass it along if we respond to it.
def [](key)
send(key) if respond_to?(key)
end
def to_param
id
end
def new_record?
false
end
def persisted?
false
end
def destroyed?
false
end
def ==(other)
if other.is_a? ::StaticModel
id == other.id
else
super
end
end
end

View file

@ -11,9 +11,22 @@ do
continue
fi
project_hook="$src/$dir/hooks/post-receive"
gitolite_hook="/home/git/.gitolite/hooks/common/post-receive"
if [[ "$dir" =~ ^.*.git$ ]]
then
project_hook="$src/$dir/hooks/post-receive"
gitolite_hook="/home/git/.gitolite/hooks/common/post-receive"
ln -s -f $gitolite_hook $project_hook
ln -s -f $gitolite_hook $project_hook
else
for subdir in `ls "$src/$dir/"`
do
if [ -d "$src/$dir/$subdir" ] && [[ "$subdir" =~ ^.*.git$ ]]; then
project_hook="$src/$dir/$subdir/hooks/post-receive"
gitolite_hook="/home/git/.gitolite/hooks/common/post-receive"
ln -s -f $gitolite_hook $project_hook
fi
done
fi
fi
done

View file

@ -0,0 +1,11 @@
#!/bin/bash
echo "Danger!!! Data Loss"
while true; do
read -p "Do you wish to all directories except gitolite-admin.git from /home/git/repositories/ (y/n) ?: " yn
case $yn in
[Yy]* ) sh -c "find /home/git/repositories/. -maxdepth 1 -not -name 'gitolite-admin.git' -not -name '.' | xargs sudo rm -rf"; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done

View file

@ -5,6 +5,8 @@ namespace :gitlab do
# Create backup of GitLab system
desc "GITLAB | Create a backup of the GitLab system"
task :create => :environment do
warn_user_is_not_gitlab
Rake::Task["gitlab:backup:db:create"].invoke
Rake::Task["gitlab:backup:repo:create"].invoke
@ -22,23 +24,23 @@ namespace :gitlab do
end
# create archive
print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar "
print "Creating backup archive: #{Time.now.to_i}_gitlab_backup.tar ... "
if Kernel.system("tar -cf #{Time.now.to_i}_gitlab_backup.tar repositories/ db/ backup_information.yml")
puts "[DONE]".green
puts "done".green
else
puts "[FAILED]".red
puts "failed".red
end
# cleanup: remove tmp files
print "Deleting tmp directories..."
print "Deleting tmp directories ... "
if Kernel.system("rm -rf repositories/ db/ backup_information.yml")
puts "[DONE]".green
puts "done".green
else
puts "[FAILED]".red
puts "failed".red
end
# delete backups
print "Deleting old backups... "
print "Deleting old backups ... "
if Gitlab.config.backup.keep_time > 0
file_list = Dir.glob("*_gitlab_backup.tar").map { |f| f.split(/_/).first.to_i }
file_list.sort.each do |timestamp|
@ -46,15 +48,17 @@ namespace :gitlab do
%x{rm #{timestamp}_gitlab_backup.tar}
end
end
puts "[DONE]".green
puts "done".green
else
puts "[SKIPPING]".yellow
puts "skipping".yellow
end
end
# Restore backup of GitLab system
desc "GITLAB | Restore a previously created backup"
task :restore => :environment do
warn_user_is_not_gitlab
Dir.chdir(Gitlab.config.backup.path)
# check for existing backups in the backup dir
@ -63,22 +67,22 @@ namespace :gitlab do
if file_list.count > 1 && ENV["BACKUP"].nil?
puts "Found more than one backup, please specify which one you want to restore:"
puts "rake gitlab:backup:restore BACKUP=timestamp_of_backup"
exit 1;
exit 1
end
tar_file = ENV["BACKUP"].nil? ? File.join("#{file_list.first}_gitlab_backup.tar") : File.join(ENV["BACKUP"] + "_gitlab_backup.tar")
unless File.exists?(tar_file)
puts "The specified backup doesn't exist!"
exit 1;
exit 1
end
print "Unpacking backup... "
print "Unpacking backup ... "
unless Kernel.system("tar -xf #{tar_file}")
puts "[FAILED]".red
puts "failed".red
exit 1
else
puts "[DONE]".green
puts "done".green
end
settings = YAML.load_file("backup_information.yml")
@ -86,7 +90,7 @@ namespace :gitlab do
# restoring mismatching backups can lead to unexpected problems
if settings[:gitlab_version] != %x{git rev-parse HEAD}.gsub(/\n/,"")
puts "gitlab_version mismatch:".red
puts "GitLab version mismatch:".red
puts " Your current HEAD differs from the HEAD in the backup!".red
puts " Please switch to the following revision and try again:".red
puts " revision: #{settings[:gitlab_version]}".red
@ -97,11 +101,11 @@ namespace :gitlab do
Rake::Task["gitlab:backup:repo:restore"].invoke
# cleanup: remove tmp files
print "Deleting tmp directories..."
print "Deleting tmp directories ... "
if Kernel.system("rm -rf repositories/ db/ backup_information.yml")
puts "[DONE]".green
puts "done".green
else
puts "[FAILED]".red
puts "failed".red
end
end
@ -114,12 +118,23 @@ namespace :gitlab do
task :create => :environment do
backup_path_repo = File.join(Gitlab.config.backup.path, "repositories")
FileUtils.mkdir_p(backup_path_repo) until Dir.exists?(backup_path_repo)
puts "Dumping repositories:"
project = Project.all.map { |n| [n.path, n.path_to_repo] }
project << ["gitolite-admin.git", File.join(Gitlab.config.git_base_path, "gitolite-admin.git")]
project.each do |project|
print "- Dumping repository #{project.first}... "
if Kernel.system("cd #{project.second} > /dev/null 2>&1 && git bundle create #{backup_path_repo}/#{project.first}.bundle --all > /dev/null 2>&1")
puts "Dumping repositories ...".blue
Project.find_each(:batch_size => 1000) do |project|
print " * #{project.path_with_namespace} ... "
if project.empty_repo?
puts "[SKIPPED]".cyan
next
end
# Create namespace dir if missing
FileUtils.mkdir_p(File.join(backup_path_repo, project.namespace.path)) if project.namespace
# Build a destination path for backup
path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle")
if Kernel.system("cd #{project.repository.path_to_repo} > /dev/null 2>&1 && git bundle create #{path_to_bundle} --all > /dev/null 2>&1")
puts "[DONE]".green
else
puts "[FAILED]".red
@ -129,18 +144,21 @@ namespace :gitlab do
task :restore => :environment do
backup_path_repo = File.join(Gitlab.config.backup.path, "repositories")
puts "Restoring repositories:"
project = Project.all.map { |n| [n.path, n.path_to_repo] }
project << ["gitolite-admin.git", File.join(File.dirname(project.first.second), "gitolite-admin.git")]
project.each do |project|
print "- Restoring repository #{project.first}... "
FileUtils.rm_rf(project.second) if File.dirname(project.second) # delete old stuff
if Kernel.system("cd #{File.dirname(project.second)} > /dev/null 2>&1 && git clone --bare #{backup_path_repo}/#{project.first}.bundle #{project.first}.git > /dev/null 2>&1")
permission_commands = [
"sudo chmod -R g+rwX #{Gitlab.config.git_base_path}",
"sudo chown -R #{Gitlab.config.ssh_user}:#{Gitlab.config.ssh_user} #{Gitlab.config.git_base_path}"
]
permission_commands.each { |command| Kernel.system(command) }
repos_path = Gitlab.config.gitolite.repos_path
puts "Restoring repositories ... "
Project.find_each(:batch_size => 1000) do |project|
print "#{project.path_with_namespace} ... "
if project.namespace
project.namespace.ensure_dir_exist
end
# Build a backup path
path_to_bundle = File.join(backup_path_repo, project.path_with_namespace + ".bundle")
if Kernel.system("git clone --bare #{path_to_bundle} #{project.repository.path_to_repo} > /dev/null 2>&1")
puts "[DONE]".green
else
puts "[FAILED]".red
@ -156,9 +174,9 @@ namespace :gitlab do
backup_path_db = File.join(Gitlab.config.backup.path, "db")
FileUtils.mkdir_p(backup_path_db) unless Dir.exists?(backup_path_db)
puts "Dumping database tables:"
puts "Dumping database tables ... ".blue
ActiveRecord::Base.connection.tables.each do |tbl|
print "- Dumping table #{tbl}... "
print " * #{tbl.yellow} ... "
count = 1
File.open(File.join(backup_path_db, tbl + ".yml"), "w+") do |file|
ActiveRecord::Base.connection.select_all("SELECT * FROM `#{tbl}`").each do |line|
@ -167,25 +185,25 @@ namespace :gitlab do
file << output.to_yaml.gsub(/^---\n/,'') + "\n"
count += 1
end
puts "[DONE]".green
puts "done".green
end
end
end
task :restore=> :environment do
task :restore => :environment do
backup_path_db = File.join(Gitlab.config.backup.path, "db")
puts "Restoring database tables:"
puts "Restoring database tables (loading fixtures) ... "
Rake::Task["db:reset"].invoke
Dir.glob(File.join(backup_path_db, "*.yml") ).each do |dir|
fixture_file = File.basename(dir, ".*" )
print "- Loading fixture #{fixture_file}..."
print "#{fixture_file.yellow} ... "
if File.size(dir) > 0
ActiveRecord::Fixtures.create_fixtures(backup_path_db, fixture_file)
puts "[DONE]".green
puts "done".green
else
puts "[SKIPPING]".yellow
puts "skipping".yellow
end
end
end

View file

@ -48,24 +48,24 @@ namespace :gitlab do
see_database_guide,
"http://guides.rubyonrails.org/getting_started.html#configuring-a-database"
)
check_failed
fix_and_rerun
end
end
def check_database_is_not_sqlite
print "Database is not SQLite ... "
print "Database is SQLite ... "
database_config_file = Rails.root.join("config", "database.yml")
unless File.read(database_config_file) =~ /sqlite/
puts "yes".green
unless File.read(database_config_file) =~ /adapter:\s+sqlite/
puts "no".green
else
puts "no".red
puts "yes".red
for_more_information(
"https://github.com/gitlabhq/gitlabhq/wiki/Migrate-from-SQLite-to-MySQL",
see_database_guide
)
check_failed
fix_and_rerun
end
end
@ -85,7 +85,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
check_failed
fix_and_rerun
end
end
@ -98,7 +98,7 @@ namespace :gitlab do
end
# omniauth or ldap could have been deleted from the file
unless Gitlab.config.pre_40_config
unless Gitlab.config['git_host']
puts "no".green
else
puts "yes".red
@ -110,7 +110,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
check_failed
fix_and_rerun
end
end
@ -129,7 +129,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Install Init Script"
)
check_failed
fix_and_rerun
end
end
@ -155,7 +155,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Install Init Script"
)
check_failed
fix_and_rerun
end
end
@ -171,7 +171,7 @@ namespace :gitlab do
try_fixing_it(
"sudo -u gitlab -H bundle exec rake db:migrate"
)
check_failed
fix_and_rerun
end
end
@ -189,6 +189,8 @@ namespace :gitlab do
if project.satellite.exists?
puts "yes".green
elsif project.empty_repo?
puts "can't create, repository is empty".magenta
else
puts "no".red
try_fixing_it(
@ -199,7 +201,7 @@ namespace :gitlab do
for_more_information(
"doc/raketasks/maintenance.md "
)
check_failed
fix_and_rerun
end
end
end
@ -220,7 +222,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
check_failed
fix_and_rerun
end
end
@ -240,7 +242,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
check_failed
fix_and_rerun
end
end
end
@ -254,7 +256,7 @@ namespace :gitlab do
start_checking "Environment"
check_gitlab_in_git_group
check_issue_1056_shell_profile_error
check_issue_1059_shell_profile_error
check_gitlab_git_config
check_python2_exists
check_python2_version
@ -288,7 +290,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "GitLab"
)
check_failed
fix_and_rerun
end
end
@ -306,16 +308,16 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "System Users"
)
check_failed
fix_and_rerun
end
end
# see https://github.com/gitlabhq/gitlabhq/issues/1059
def check_issue_1056_shell_profile_error
def check_issue_1059_shell_profile_error
gitolite_ssh_user = Gitlab.config.gitolite.ssh_user
print "Has no \"-e\" in ~#{gitolite_ssh_user}/.profile ... "
profile_file = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.profile")
profile_file = File.join(gitolite_home, ".profile")
unless File.read(profile_file) =~ /^-e PATH/
puts "yes".green
@ -330,7 +332,7 @@ namespace :gitlab do
see_installation_guide_section("Gitolite"),
"https://github.com/gitlabhq/gitlabhq/issues/1059"
)
check_failed
fix_and_rerun
end
end
@ -350,7 +352,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Packages / Dependencies"
)
check_failed
fix_and_rerun
end
end
@ -376,7 +378,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Packages / Dependencies"
)
check_failed
fix_and_rerun
end
end
end
@ -396,6 +398,7 @@ namespace :gitlab do
check_dot_gitolite_user_and_group
check_dot_gitolite_permissions
check_repo_base_exists
check_repo_base_is_not_symlink
check_repo_base_user_and_group
check_repo_base_permissions
check_can_clone_gitolite_admin
@ -432,7 +435,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
# assumes #check_can_clone_gitolite_admin has been run before
@ -464,7 +467,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
ensure
FileUtils.rm_rf("/tmp/gitolite_gitlab_test")
end
@ -472,7 +475,7 @@ namespace :gitlab do
def check_dot_gitolite_exists
print "Config directory exists? ... "
gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite")
gitolite_config_path = File.join(gitolite_home, ".gitolite")
if File.directory?(gitolite_config_path)
puts "yes".green
@ -486,14 +489,14 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
def check_dot_gitolite_permissions
print "Config directory access is drwxr-x---? ... "
gitolite_config_path = File.expand_path("~#{Gitlab.config.gitolite.ssh_user}/.gitolite")
gitolite_config_path = File.join(gitolite_home, ".gitolite")
unless File.exists?(gitolite_config_path)
puts "can't check because of previous errors".magenta
return
@ -503,14 +506,13 @@ namespace :gitlab do
puts "yes".green
else
puts "no".red
puts "#{gitolite_config_path} is not writable".red
try_fixing_it(
"sudo chmod 750 #{gitolite_config_path}"
)
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
@ -518,7 +520,7 @@ namespace :gitlab do
gitolite_ssh_user = Gitlab.config.gitolite.ssh_user
print "Config directory owned by #{gitolite_ssh_user}:#{gitolite_ssh_user} ... "
gitolite_config_path = File.expand_path("~#{gitolite_ssh_user}/.gitolite")
gitolite_config_path = File.join(gitolite_home, ".gitolite")
unless File.exists?(gitolite_config_path)
puts "can't check because of previous errors".magenta
return
@ -536,13 +538,13 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
def check_gitolite_is_up_to_date
print "Using recommended version ... "
if gitolite_version.try(:start_with?, "v3.04")
if gitolite_version.try(:start_with?, "v3.2")
puts "yes".green
else
puts "no".red
@ -581,7 +583,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
@ -610,7 +612,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
@ -634,7 +636,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Setup GitLab Hooks"
)
check_failed
fix_and_rerun
end
end
@ -644,7 +646,6 @@ namespace :gitlab do
hook_file = "post-receive"
gitolite_hooks_path = File.join(Gitlab.config.gitolite.hooks_path, "common")
gitolite_hook_file = File.join(gitolite_hooks_path, hook_file)
gitolite_hook_content = File.read(gitolite_hook_file)
gitolite_ssh_user = Gitlab.config.gitolite.ssh_user
unless File.exists?(gitolite_hook_file)
@ -652,6 +653,7 @@ namespace :gitlab do
return
end
gitolite_hook_content = File.read(gitolite_hook_file)
gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file)
gitlab_hook_content = File.read(gitlab_hook_file)
@ -665,7 +667,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Setup GitLab Hooks"
)
check_failed
fix_and_rerun
end
end
@ -687,7 +689,27 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
def check_repo_base_is_not_symlink
print "Repo base directory is a symlink? ... "
repo_base_path = Gitlab.config.gitolite.repos_path
unless File.exists?(repo_base_path)
puts "can't check because of previous errors".magenta
return
end
unless File.symlink?(repo_base_path)
puts "no".green
else
puts "yes".red
try_fixing_it(
"Make sure it's set to the real directory in config/gitlab.yml"
)
fix_and_rerun
end
end
@ -711,7 +733,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
@ -737,7 +759,7 @@ namespace :gitlab do
for_more_information(
see_installation_guide_section "Gitolite"
)
check_failed
fix_and_rerun
end
end
@ -758,7 +780,7 @@ namespace :gitlab do
print "#{project.name_with_namespace.yellow} ... "
correct_options = options.map do |name, value|
run("git --git-dir=\"#{project.path_to_repo}\" config --get #{name}").try(:chomp) == value
run("git --git-dir=\"#{project.repository.path_to_repo}\" config --get #{name}").try(:chomp) == value
end
if correct_options.all?
@ -771,7 +793,7 @@ namespace :gitlab do
for_more_information(
"doc/raketasks/maintenance.md"
)
check_failed
fix_and_rerun
end
end
end
@ -797,7 +819,7 @@ namespace :gitlab do
Project.find_each(batch_size: 100) do |project|
print "#{project.name_with_namespace.yellow} ... "
project_hook_file = File.join(project.path_to_repo, "hooks", hook_file)
project_hook_file = File.join(project.repository.path_to_repo, "hooks", hook_file)
unless File.exists?(project_hook_file)
puts "missing".red
@ -807,7 +829,7 @@ namespace :gitlab do
for_more_information(
"lib/support/rewrite-hooks.sh"
)
check_failed
fix_and_rerun
next
end
@ -821,7 +843,7 @@ namespace :gitlab do
for_more_information(
"lib/support/rewrite-hooks.sh"
)
check_failed
fix_and_rerun
end
end
end
@ -849,7 +871,7 @@ namespace :gitlab do
namespace :resque do
desc "GITLAB | Check the configuration of Resque"
desc "GITLAB | Check the configuration of Sidekiq"
task check: :environment do
warn_user_is_not_gitlab
start_checking "Resque"
@ -866,7 +888,7 @@ namespace :gitlab do
def check_resque_running
print "Running? ... "
if run_and_match("ps aux | grep -i resque", /resque-[\d\.]+:.+$/)
if run_and_match("ps aux | grep -i sidekiq", /sidekiq \d\.\d\.\d.+$/)
puts "yes".green
else
puts "no".red
@ -877,9 +899,9 @@ namespace :gitlab do
)
for_more_information(
see_installation_guide_section("Install Init Script"),
"see log/resque.log for possible errors"
"see log/sidekiq.log for possible errors"
)
check_failed
fix_and_rerun
end
end
end
@ -888,7 +910,7 @@ namespace :gitlab do
# Helper methods
##########################
def check_failed
def fix_and_rerun
puts " Please #{"fix the error above"} and rerun the checks.".red
end
@ -907,29 +929,6 @@ namespace :gitlab do
puts ""
end
# Runs the given command
#
# Returns nil if the command was not found
# Returns the output of the command otherwise
#
# see also #run_and_match
def run(command)
unless `#{command} 2>/dev/null`.blank?
`#{command}`
end
end
# Runs the given command and matches the output agains the given pattern
#
# Returns nil if nothing matched
# Retunrs the MatchData if the pattern matched
#
# see also #run
# see also String#match
def run_and_match(command, pattern)
run(command).try(:match, pattern)
end
def see_database_guide
"doc/install/databases.md"
end
@ -951,18 +950,4 @@ namespace :gitlab do
puts " #{step}"
end
end
def warn_user_is_not_gitlab
unless @warned_user_not_gitlab
current_user = run("whoami").chomp
unless current_user == "gitlab"
puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
puts " Some tests may pass\/fail for the wrong reason."
puts " For meaningful results you should run this as user #{"gitlab".magenta}."
puts ""
end
@warned_user_not_gitlab = true
end
end
end

View file

@ -0,0 +1,128 @@
namespace :gitlab do
namespace :cleanup do
desc "GITLAB | Cleanup | Clean gitolite config"
task :config => :environment do
warn_user_is_not_gitlab
real_repos = Project.all.map(&:path_with_namespace)
real_repos << "gitolite-admin"
real_repos << "@all"
remove_flag = ENV['REMOVE']
puts "Looking for repositories to remove... "
Gitlab::GitoliteConfig.new.apply do |config|
all_repos = []
garbage_repos = []
all_repos = config.conf.repos.keys
garbage_repos = all_repos - real_repos
garbage_repos.each do |repo_name|
if remove_flag
config.conf.rm_repo(repo_name)
print "to remove...".red
end
puts repo_name.red
end
end
unless remove_flag
puts "To cleanup repositories run this command with REMOVE=true".yellow
end
end
desc "GITLAB | Cleanup | Clean namespaces"
task :dirs => :environment do
warn_user_is_not_gitlab
remove_flag = ENV['REMOVE']
namespaces = Namespace.pluck(:path)
git_base_path = Gitlab.config.gitolite.repos_path
all_dirs = Dir.glob(git_base_path + '/*')
puts git_base_path.yellow
puts "Looking for directories to remove... "
all_dirs.reject! do |dir|
# skip if git repo
dir =~ /.git$/
end
all_dirs.reject! do |dir|
dir_name = File.basename dir
# skip if namespace present
namespaces.include?(dir_name)
end
all_dirs.each do |dir_path|
if remove_flag
if FileUtils.rm_rf dir_path
puts "Removed...#{dir_path}".red
else
puts "Cannot remove #{dir_path}".red
end
else
puts "Can be removed: #{dir_path}".red
end
end
unless remove_flag
puts "To cleanup this directories run this command with REMOVE=true".yellow
end
end
desc "GITLAB | Cleanup | Clean respositories"
task :repos => :environment do
warn_user_is_not_gitlab
remove_flag = ENV['REMOVE']
git_base_path = Gitlab.config.gitolite.repos_path
all_dirs = Dir.glob(git_base_path + '/*')
global_projects = Project.where(namespace_id: nil).pluck(:path)
puts git_base_path.yellow
puts "Looking for global repos to remove... "
# skip non git repo
all_dirs.select! do |dir|
dir =~ /.git$/
end
# skip existing repos
all_dirs.reject! do |dir|
repo_name = File.basename dir
path = repo_name.gsub(/\.git$/, "")
global_projects.include?(path)
end
# skip gitolite admin
all_dirs.reject! do |dir|
repo_name = File.basename dir
repo_name == 'gitolite-admin.git'
end
all_dirs.each do |dir_path|
if remove_flag
if FileUtils.rm_rf dir_path
puts "Removed...#{dir_path}".red
else
puts "Cannot remove #{dir_path}".red
end
else
puts "Can be removed: #{dir_path}".red
end
end
unless remove_flag
puts "To cleanup this directories run this command with REMOVE=true".yellow
end
end
end
end

View file

@ -1,16 +1,42 @@
namespace :gitlab do
desc "GITLAB | Enable auto merge"
task :enable_automerge => :environment do
Gitlab::Gitolite.new.enable_automerge
warn_user_is_not_gitlab
Project.find_each do |project|
if project.repo_exists? && !project.satellite.exists?
puts "Creating satellite for #{project.name}...".green
puts "Updating repo permissions ..."
Gitlab::Gitolite.new.enable_automerge
puts "... #{"done".green}"
puts ""
print "Creating satellites for ..."
unless Project.count > 0
puts "skipping, because you have no projects".magenta
next
end
puts ""
Project.find_each(batch_size: 100) do |project|
print "#{project.name_with_namespace.yellow} ... "
unless project.repo_exists?
puts "skipping, because the repo is empty".magenta
next
end
if project.satellite.exists?
puts "exists already".green
else
puts ""
project.satellite.create
print "... "
if $?.success?
puts "created".green
else
puts "error".red
end
end
end
puts "Done!".green
end
namespace :satellites do

View file

@ -1,67 +1,116 @@
namespace :gitlab do
desc "GITLAB | Enable usernames and namespaces for user projects"
task enable_namespaces: :environment do
print "\nUsernames for users:".yellow
warn_user_is_not_gitlab
migrate_user_namespaces
migrate_groups
migrate_projects
puts "Rebuild Gitolite ... "
gitolite = Gitlab::Gitolite.new
gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))
puts "... #{"done".green}"
end
def migrate_user_namespaces
puts "\nGenerate usernames for users without one: ".blue
User.find_each(batch_size: 500) do |user|
next if user.namespace
User.transaction do
username = user.email.match(/^[^@]*/)[0]
if user.update_attributes!(username: username)
print '.'.green
else
print 'F'.red
end
if user.namespace
print '-'.cyan
next
end
end
print "\n\nDirs for groups:".yellow
username = if user.username.present?
# if user already has username filled
user.username
else
build_username(user)
end
Group.find_each(batch_size: 500) do |group|
if group.ensure_dir_exist
print '.'.green
else
begin
User.transaction do
user.update_attributes!(username: username)
print '.'.green
end
rescue
print 'F'.red
end
end
puts "\nDone"
end
print "\n\nMove projects from groups under groups dirs:".yellow
def build_username(user)
username = nil
# generate username
username = user.email.match(/^[^@]*/)[0]
username.gsub!("+", ".")
# return username if no mathes
return username unless User.find_by_username(username)
# look for same username
(1..10).each do |i|
suffixed_username = "#{username}#{i}"
return suffixed_username unless User.find_by_username(suffixed_username)
end
end
def migrate_groups
puts "\nCreate directories for groups: ".blue
Group.find_each(batch_size: 500) do |group|
begin
if group.dir_exists?
print '-'.cyan
else
if group.ensure_dir_exist
print '.'.green
else
print 'F'.red
end
end
rescue
print 'F'.red
end
end
puts "\nDone"
end
def migrate_projects
git_path = Gitlab.config.gitolite.repos_path
puts "\nMove projects in groups into respective directories ... ".blue
Project.where('namespace_id IS NOT NULL').find_each(batch_size: 500) do |project|
next unless project.group
group = project.group
puts "\n"
print " * #{project.name}: "
print "#{project.name_with_namespace.yellow} ... "
new_path = File.join(git_path, project.path_with_namespace + '.git')
if File.exists?(new_path)
print "ok. already at #{new_path}".cyan
puts "already at #{new_path}".green
next
end
old_path = File.join(git_path, project.path + '.git')
unless File.exists?(old_path)
print "missing. not found at #{old_path}".red
puts "couldn't find it at #{old_path}".red
next
end
begin
Gitlab::ProjectMover.new(project, '', group.path).execute
print "ok. Moved to #{new_path}".green
puts "moved to #{new_path}".green
rescue
print "Failed moving to #{new_path}".red
puts "failed moving to #{new_path}".red
end
end
print "\n\nRebuild gitolite:".yellow
gitolite = Gitlab::Gitolite.new
gitolite.update_repositories(Project.where('namespace_id IS NOT NULL'))
puts "\n"
puts "\nDone"
end
end

View file

@ -0,0 +1,7 @@
namespace :gitlab do
desc "GITLAB | Generate sdocs for project"
task generate_docs: :environment do
system("bundle exec sdoc -o doc/code app lib")
end
end

View file

@ -1,24 +1,27 @@
namespace :gitlab do
namespace :gitolite do
desc "GITLAB | Rebuild each project at gitolite config"
desc "GITLAB | Rebuild each project in Gitolite config"
task :update_repos => :environment do
puts "Starting Projects"
warn_user_is_not_gitlab
puts "Rebuilding projects ... "
Project.find_each(:batch_size => 100) do |project|
puts "\n=== #{project.name}"
puts "#{project.name_with_namespace.yellow} ... "
project.update_repository
puts
puts "... #{"done".green}"
end
puts "Done with projects"
end
desc "GITLAB | Rebuild each key at gitolite config"
desc "GITLAB | Rebuild each user key in Gitolite config"
task :update_keys => :environment do
puts "Starting Key"
warn_user_is_not_gitlab
puts "Rebuilding keys ... "
Key.find_each(:batch_size => 100) do |key|
puts "#{key.identifier.yellow} ... "
Gitlab::Gitolite.new.set_key(key.identifier, key.key, key.projects)
print '.'
puts "... #{"done".green}"
end
puts "Done with keys"
end
end
end

View file

@ -15,15 +15,23 @@ namespace :gitlab do
git_base_path = Gitlab.config.gitolite.repos_path
repos_to_import = Dir.glob(git_base_path + '/*')
namespaces = Namespace.pluck(:path)
repos_to_import.each do |repo_path|
repo_name = File.basename repo_path
# Skip if group or user
next if namespaces.include?(repo_name)
# skip if not git repo
next unless repo_name =~ /.git$/
# skip gitolite admin
next if repo_name == 'gitolite-admin.git'
path = repo_name.sub(/\.git$/, '')
project = Project.find_by_path(path)
project = Project.find_with_namespace(path)
puts "Processing #{repo_name}".yellow
@ -34,8 +42,6 @@ namespace :gitlab do
project_params = {
:name => path,
:code => path,
:path => path,
}
project = Project.create_by_user(project_params, user)

View file

@ -12,7 +12,10 @@ namespace :gitlab do
debian_version = File.read('/etc/debian_version')
"Debian #{debian_version}"
end
os_name.squish!
os_name ||= if File.readable?('/etc/SuSE-release')
File.read('/etc/SuSE-release')
end
os_name.try(:squish!)
# check if there is an RVM environment
rvm_version = run_and_match("rvm --version", /[\d\.]+/).try(:to_s)
@ -80,31 +83,5 @@ namespace :gitlab do
puts "Git:\t\t#{Gitlab.config.git.bin_path}"
end
# Helper methods
# Runs the given command and matches the output agains the given pattern
#
# Returns nil if nothing matched
# Retunrs the MatchData if the pattern matched
#
# see also #run
# see also String#match
def run_and_match(command, regexp)
run(command).try(:match, regexp)
end
# Runs the given command
#
# Returns nil if the command was not found
# Returns the output of the command otherwise
#
# see also #run_and_match
def run(command)
unless `#{command} 2>/dev/null`.blank?
`#{command}`
end
end
end
end

View file

@ -0,0 +1,39 @@
namespace :gitlab do
# Runs the given command and matches the output agains the given pattern
#
# Returns nil if nothing matched
# Retunrs the MatchData if the pattern matched
#
# see also #run
# see also String#match
def run_and_match(command, regexp)
run(command).try(:match, regexp)
end
# Runs the given command
#
# Returns nil if the command was not found
# Returns the output of the command otherwise
#
# see also #run_and_match
def run(command)
unless `#{command} 2>/dev/null`.blank?
`#{command}`
end
end
def warn_user_is_not_gitlab
unless @warned_user_not_gitlab
current_user = run("whoami").chomp
unless current_user == "gitlab"
puts "#{Colored.color(:black)+Colored.color(:on_yellow)} Warning #{Colored.extra(:clear)}"
puts " You are running as user #{current_user.magenta}, we hope you know what you are doing."
puts " Things may work\/fail for the wrong reasons."
puts " For correct results you should run this as user #{"gitlab".magenta}."
puts ""
end
@warned_user_not_gitlab = true
end
end
end

View file

@ -1,10 +0,0 @@
require 'resque/tasks'
task "resque:setup" => :environment do
Resque.after_fork do
Resque.redis.client.reconnect
end
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"

23
lib/tasks/sidekiq.rake Normal file
View file

@ -0,0 +1,23 @@
namespace :sidekiq do
desc "GITLAB | Stop sidekiq"
task :stop do
run "bundle exec sidekiqctl stop #{pidfile}"
end
desc "GITLAB | Start sidekiq"
task :start do
run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,common,default -e #{rails_env} -P #{pidfile} >> #{root_path}/log/sidekiq.log 2>&1 &"
end
def root_path
@root_path ||= File.join(File.expand_path(File.dirname(__FILE__)), "../..")
end
def pidfile
"#{root_path}/tmp/pids/sidekiq.pid"
end
def rails_env
ENV['RAILS_ENV'] || "production"
end
end

View file

@ -1,7 +1,5 @@
task :travis do
["rake spinach", "rake spec"].each do |cmd|
puts "Starting to run #{cmd}..."
system("export DISPLAY=:99.0 && bundle exec #{cmd}")
raise "#{cmd} failed!" unless $?.exitstatus == 0
end
end
desc "Travis run tests"
task :travis => [
:spinach,
:spec
]