Commit 0e9d4f30f4961cc7ee768995a37c5bf9a123c08a
1 parent
fba8ad56
Exists in
master
and in
4 other branches
Refactor Satellite#clear and rename it to clear_and_update!
Showing
2 changed files
with
43 additions
and
18 deletions
Show diff stats
lib/gitlab/satellite/action.rb
@@ -50,10 +50,7 @@ module Gitlab | @@ -50,10 +50,7 @@ module Gitlab | ||
50 | # | 50 | # |
51 | # Note: use this within #in_locked_and_timed_satellite | 51 | # Note: use this within #in_locked_and_timed_satellite |
52 | def prepare_satellite!(repo) | 52 | def prepare_satellite!(repo) |
53 | - project.satellite.clear | ||
54 | - | ||
55 | - repo.git.reset(hard: true) | ||
56 | - repo.git.fetch({}, :origin) | 53 | + project.satellite.clear_and_update! |
57 | 54 | ||
58 | repo.git.config({}, "user.name", user.name) | 55 | repo.git.config({}, "user.name", user.name) |
59 | repo.git.config({}, "user.email", user.email) | 56 | repo.git.config({}, "user.email", user.email) |
lib/gitlab/satellite/satellite.rb
@@ -9,20 +9,10 @@ module Gitlab | @@ -9,20 +9,10 @@ module Gitlab | ||
9 | @project = project | 9 | @project = project |
10 | end | 10 | end |
11 | 11 | ||
12 | - #will be deleted all branches except PARKING_BRANCH | ||
13 | - def clear | ||
14 | - Dir.chdir(path) do | ||
15 | - heads = Grit::Repo.new(".").heads.map{|head| head.name} | ||
16 | - if heads.include? PARKING_BRANCH | ||
17 | - `git checkout #{PARKING_BRANCH}` | ||
18 | - else | ||
19 | - `git checkout -b #{PARKING_BRANCH}` | ||
20 | - end | ||
21 | - heads.delete(PARKING_BRANCH) | ||
22 | - heads.each do |head| | ||
23 | - `git branch -D #{head}` | ||
24 | - end | ||
25 | - end | 12 | + def clear_and_update! |
13 | + delete_heads! | ||
14 | + clear_working_dir! | ||
15 | + update_from_source! | ||
26 | end | 16 | end |
27 | 17 | ||
28 | def create | 18 | def create |
@@ -36,6 +26,44 @@ module Gitlab | @@ -36,6 +26,44 @@ module Gitlab | ||
36 | def path | 26 | def path |
37 | Rails.root.join("tmp", "repo_satellites", project.path) | 27 | Rails.root.join("tmp", "repo_satellites", project.path) |
38 | end | 28 | end |
29 | + | ||
30 | + private | ||
31 | + | ||
32 | + # Clear the working directory | ||
33 | + def clear_working_dir! | ||
34 | + repo.git.reset(hard: true) | ||
35 | + end | ||
36 | + | ||
37 | + # Deletes all branches except the parking branch | ||
38 | + # | ||
39 | + # This ensures we have no name clashes or issues updating branches when | ||
40 | + # working with the satellite. | ||
41 | + def delete_heads! | ||
42 | + heads = repo.heads.map{|head| head.name} | ||
43 | + | ||
44 | + # update or create the parking branch | ||
45 | + if heads.include? PARKING_BRANCH | ||
46 | + repo.git.checkout({}, PARKING_BRANCH) | ||
47 | + else | ||
48 | + repo.git.checkout({b: true}, PARKING_BRANCH) | ||
49 | + end | ||
50 | + | ||
51 | + # remove the parking branch from the list of heads ... | ||
52 | + heads.delete(PARKING_BRANCH) | ||
53 | + # ... and delete all others | ||
54 | + heads.each { |head| repo.git.branch({D: true}, head) } | ||
55 | + end | ||
56 | + | ||
57 | + def repo | ||
58 | + @repo ||= Grit::Repo.new(path) | ||
59 | + end | ||
60 | + | ||
61 | + # Updates the satellite from Gitolite | ||
62 | + # | ||
63 | + # Note: this will only update remote branches (i.e. origin/*) | ||
64 | + def update_from_source! | ||
65 | + repo.git.fetch({}, :origin) | ||
66 | + end | ||
39 | end | 67 | end |
40 | end | 68 | end |
41 | end | 69 | end |