lib/rim/sync_helper.rb
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 = "refs/heads/#{branch}"
        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
        @logger.debug("Folder for temporary git repositories: #{@rim_path}")
        tmpdir = clone_or_fetch_repository(remote_url, module_tmp_git_path(".ws"), "Cloning workspace git...")
        RIM::git_session(tmpdir) do |tmp_session|
          tmp_session.execute("git reset --hard")
          tmp_session.execute("git clean -xdf")
          # use -f here to prevent git checkout from checking for untracked files which might be overwritten. 
          # this is safe since we removed any untracked files before.
          # this is a workaround for a name case problem on windows:
          # if a file's name changes case between the current head and the checkout target,
          # git checkout will report the file with the new name as untracked and will fail
          tmp_session.execute("git checkout -B #{rim_branch} -f remotes/origin/#{rim_branch}")
          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 !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
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 = "refs/heads/#{branch}"
        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
        @logger.debug("Folder for temporary git repositories: #{@rim_path}")
        tmpdir = clone_or_fetch_repository(remote_url, module_tmp_git_path(".ws"), "Cloning workspace git...")
        RIM::git_session(tmpdir) do |tmp_session|
          tmp_session.execute("git reset --hard")
          tmp_session.execute("git clean -xdf")
          # use -f here to prevent git checkout from checking for untracked files which might be overwritten. 
          # this is safe since we removed any untracked files before.
          # this is a workaround for a name case problem on windows:
          # if a file's name changes case between the current head and the checkout target,
          # git checkout will report the file with the new name as untracked and will fail
          tmp_session.execute("git checkout -B #{rim_branch} -f remotes/origin/#{rim_branch}")
          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 !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
sync all module changes into rim branch