1+ #--
2+ # Copyright 2013 Red Hat, Inc.
3+ #
4+ # Licensed under the Apache License, Version 2.0 (the "License");
5+ # you may not use this file except in compliance with the License.
6+ # You may obtain a copy of the License at
7+ #
8+ # http://www.apache.org/licenses/LICENSE-2.0
9+ #
10+ # Unless required by applicable law or agreed to in writing, software
11+ # distributed under the License is distributed on an "AS IS" BASIS,
12+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ # See the License for the specific language governing permissions and
14+ # limitations under the License.
15+ #++
16+
17+ module Vagrant
18+ module Openshift
19+ module Action
20+ class SyncUpstreamRepository
21+ include CommandHelper
22+
23+ def initialize ( app , env )
24+ @app = app
25+ @env = env
26+ end
27+
28+ def call ( env )
29+ env [ :machine ] . env . ui . info ( "Sync'ing upstream sources\n " )
30+
31+ Constants . repos . each do |repo_name , url |
32+ sync_repo ( env [ :machine ] , repo_name , url )
33+ end
34+ env [ :machine ] . env . ui . info ( "Done" )
35+
36+ @app . call ( env )
37+ end
38+
39+ private
40+
41+ def sync_repo ( machine , repo_name , url , branch = "master" )
42+ bare_repo_name = repo_name + "-bare"
43+ bare_repo_wc_name = repo_name + "-bare-working_copy"
44+ bare_repo_path = Constants . build_dir + bare_repo_name
45+ bare_repo_wc_path = Constants . build_dir + bare_repo_wc_name
46+
47+ command = ""
48+ command += "export GIT_SSH=#{ Constants . git_ssh } ;\n " unless Constants . git_ssh . nil? or Constants . git_ssh . empty?
49+ command += %{
50+
51+ if [ ! -d #{ bare_repo_wc_path } ]; then
52+ git clone -l #{ bare_repo_path } #{ bare_repo_wc_path } ;
53+ fi;
54+
55+ cd #{ bare_repo_wc_path } ;
56+ git remote add upstream #{ url } ;
57+ git fetch upstream;
58+ git checkout master;
59+ git reset --hard upstream/#{ branch } ;
60+ git push origin master -f;
61+ }
62+ do_execute ( machine , command )
63+ end
64+ end
65+ end
66+ end
67+ end
0 commit comments