Refactor Satellite#clear and rename it to clear_and_update!
This commit is contained in:
parent
fba8ad5607
commit
0e9d4f30f4
2 changed files with 43 additions and 18 deletions
|
@ -50,10 +50,7 @@ module Gitlab
|
||||||
#
|
#
|
||||||
# Note: use this within #in_locked_and_timed_satellite
|
# Note: use this within #in_locked_and_timed_satellite
|
||||||
def prepare_satellite!(repo)
|
def prepare_satellite!(repo)
|
||||||
project.satellite.clear
|
project.satellite.clear_and_update!
|
||||||
|
|
||||||
repo.git.reset(hard: true)
|
|
||||||
repo.git.fetch({}, :origin)
|
|
||||||
|
|
||||||
repo.git.config({}, "user.name", user.name)
|
repo.git.config({}, "user.name", user.name)
|
||||||
repo.git.config({}, "user.email", user.email)
|
repo.git.config({}, "user.email", user.email)
|
||||||
|
|
|
@ -9,20 +9,10 @@ module Gitlab
|
||||||
@project = project
|
@project = project
|
||||||
end
|
end
|
||||||
|
|
||||||
#will be deleted all branches except PARKING_BRANCH
|
def clear_and_update!
|
||||||
def clear
|
delete_heads!
|
||||||
Dir.chdir(path) do
|
clear_working_dir!
|
||||||
heads = Grit::Repo.new(".").heads.map{|head| head.name}
|
update_from_source!
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
@ -36,6 +26,44 @@ module Gitlab
|
||||||
def path
|
def path
|
||||||
Rails.root.join("tmp", "repo_satellites", project.path)
|
Rails.root.join("tmp", "repo_satellites", project.path)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue