lib/rim/sync_helper.rb in esr-rim-1.1.5 vs lib/rim/sync_helper.rb in esr-rim-1.2.0

- old
+ new

@@ -17,26 +17,28 @@ def add_module_info(module_info) @module_infos.push(module_info) end # sync all module changes into rim branch - def sync(message = nil) + def sync(message = 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 @@ -45,17 +47,25 @@ else tmp_session.execute("git reset --hard") tmp_session.execute("git clean -xdf") tmp_session.execute("git checkout #{rim_branch}") end - @logger.info("Synchronizing modules...") - sync_modules(tmp_session, message) + changed_modules = sync_modules(tmp_session, message) + if !split + tmp_session.execute("git reset --soft #{branch_sha1}") + commit(tmp_session, message ? message : get_commit_message(changed_modules)) if tmp_session.uncommited_changes? + end tmp_session.execute("git push #{remote_url} #{rim_branch}:#{rim_branch}") end end - if s.rev_sha1(rim_branch) != branch_sha1 - @logger.info("Changes have been commited to branch #{rim_branch}. Rebase to apply changes to workspace.") + 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 @@ -65,13 +75,18 @@ def sync_modules(session, message) module_helpers = [] @module_infos.each do |module_info| module_helpers.push(SyncModuleHelper.new(session.execute_dir, @ws_root, module_info, @logger)) end + changed_modules = [] module_helpers.each do |m| - m.sync(message) + @logger.info("Synchronizing #{m.module_info.local_path}...") + if m.sync(message) + changed_modules << m.module_info + end end + changed_modules end # get latest revision from which all parent revisions are clean def get_latest_clean_path_revision(session, rev, remote_rev) # make sure we deal only with sha1s @@ -113,9 +128,21 @@ # get first parent node def get_parent(session, rev) parents = session.parent_revs(rev) !parents.empty? ? parents.first : nil end + + #create default commit message from array of changed modules + def get_commit_message(changed_modules) + StringIO.open do |s| + s.puts "rim sync." + s.puts + changed_modules.each do |m| + s.puts m.local_path + end + s.string + end + end end end