Commit 0e9d4f30 authored by Riyad Preukschas's avatar Riyad Preukschas

Refactor Satellite#clear and rename it to clear_and_update!

parent fba8ad56
......@@ -50,10 +50,7 @@ module Gitlab
#
# Note: use this within #in_locked_and_timed_satellite
def prepare_satellite!(repo)
project.satellite.clear
repo.git.reset(hard: true)
repo.git.fetch({}, :origin)
project.satellite.clear_and_update!
repo.git.config({}, "user.name", user.name)
repo.git.config({}, "user.email", user.email)
......
......@@ -9,20 +9,10 @@ module Gitlab
@project = project
end
#will be deleted all branches except PARKING_BRANCH
def clear
Dir.chdir(path) do
heads = Grit::Repo.new(".").heads.map{|head| head.name}
if heads.include? PARKING_BRANCH
`git checkout #{PARKING_BRANCH}`
else
`git checkout -b #{PARKING_BRANCH}`
end
heads.delete(PARKING_BRANCH)
heads.each do |head|
`git branch -D #{head}`
end
end
def clear_and_update!
delete_heads!
clear_working_dir!
update_from_source!
end
def create
......@@ -36,6 +26,44 @@ module Gitlab
def path
Rails.root.join("tmp", "repo_satellites", project.path)
end
private
# Clear the working directory
def clear_working_dir!
repo.git.reset(hard: true)
end
# Deletes all branches except the parking branch
#
# This ensures we have no name clashes or issues updating branches when
# working with the satellite.
def delete_heads!
heads = repo.heads.map{|head| head.name}
# update or create the parking branch
if heads.include? PARKING_BRANCH
repo.git.checkout({}, PARKING_BRANCH)
else
repo.git.checkout({b: true}, PARKING_BRANCH)
end
# remove the parking branch from the list of heads ...
heads.delete(PARKING_BRANCH)
# ... and delete all others
heads.each { |head| repo.git.branch({D: true}, head) }
end
def repo
@repo ||= Grit::Repo.new(path)
end
# Updates the satellite from Gitolite
#
# Note: this will only update remote branches (i.e. origin/*)
def update_from_source!
repo.git.fetch({}, :origin)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment