Class: RIM::SyncHelper
- Inherits:
-
CommandHelper
- Object
- Processor
- CommandHelper
- RIM::SyncHelper
- Defined in:
- lib/rim/sync_helper.rb
Constant Summary
Constants inherited from Processor
Processor::GerritServer, Processor::MaxThreads
Instance Method Summary collapse
-
#add_module_info(module_info) ⇒ Object
called to add a module info.
-
#initialize(workspace_root, logger, module_infos = nil) ⇒ SyncHelper
constructor
A new instance of SyncHelper.
-
#sync(message = nil, rebase = nil, split = true) ⇒ Object
sync all module changes into rim branch.
Methods inherited from CommandHelper
#add_unique_module_info, #all_module_paths_from_path, #check_arguments, #check_ready, #create_module_info, #find_file_dir_in_workspace, #get_remote_branch_format, #module_from_path, #module_paths, #modules_from_manifest, #modules_from_paths
Methods included from Manifest
#parse_manifest, #read_manifest
Methods inherited from Processor
#clone_or_fetch_repository, #commit, #each_module_parallel, #get_absolute_remote_url, #get_relative_path, #local_changes?, #module_git_path, #module_tmp_git_path, #remote_path
Constructor Details
#initialize(workspace_root, logger, module_infos = nil) ⇒ SyncHelper
Returns a new instance of SyncHelper.
11 12 13 14 |
# File 'lib/rim/sync_helper.rb', line 11 def initialize(workspace_root, logger, module_infos = nil) @module_infos = [] super(workspace_root, logger, module_infos) end |
Instance Method Details
#add_module_info(module_info) ⇒ Object
called to add a module info
17 18 19 |
# File 'lib/rim/sync_helper.rb', line 17 def add_module_info(module_info) @module_infos.push(module_info) end |
#sync(message = nil, rebase = nil, split = true) ⇒ Object
sync all module changes into rim branch
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rim/sync_helper.rb', line 22 def sync( = nil, rebase = nil, split = true) # get the name of the current workspace branch RIM::git_session(@ws_root) do |s| branch = s.current_branch rim_branch = "rim/" + branch branch_sha1 = nil changed_modules = nil if branch.empty? raise RimException.new("Not on a git branch.") elsif branch.start_with?("rim/") raise RimException.new("The current git branch '#{branch}' is a rim integration branch. Please switch to a non rim branch to proceed.") else branch_sha1 = s.rev_sha1(rim_branch) remote_rev = get_latest_remote_revision(s, branch) rev = get_latest_clean_path_revision(s, branch, remote_rev) if !s.has_branch?(rim_branch) || has_ancestor?(s, branch, s.rev_sha1(rim_branch)) || !has_ancestor?(s, rim_branch, remote_rev) s.execute("git branch -f #{rim_branch} #{rev}") branch_sha1 = s.rev_sha1(rim_branch) end remote_url = "file://" + @ws_root tmpdir = clone_or_fetch_repository(remote_url, module_tmp_git_path(".ws"), "Cloning workspace git...") RIM::git_session(tmpdir) do |tmp_session| if tmp_session.current_branch() == rim_branch tmp_session.execute("git reset --hard remotes/origin/#{rim_branch}") tmp_session.execute("git clean -xdf") else tmp_session.execute("git reset --hard") tmp_session.execute("git clean -xdf") tmp_session.execute("git checkout #{rim_branch}") end changed_modules = sync_modules(tmp_session, ) if !split tmp_session.execute("git reset --soft #{branch_sha1}") commit(tmp_session, ? : (changed_modules)) if tmp_session.uncommited_changes? end tmp_session.execute("git push #{remote_url} #{rim_branch}:#{rim_branch}") end end if !changed_modules.empty? if rebase s.execute("git rebase #{rim_branch}") @logger.info("Changes have been commited to branch #{rim_branch} and workspace has been rebased successfully.") else @logger.info("Changes have been commited to branch #{rim_branch}. Rebase to apply changes to workspace.") end else @logger.info("No changes.") end end end |