Beispiel #1
0
 def _prepare_git(cls, upstream_name):
     cls.git_helper.command_remote_add(upstream_name, cls.new_sources)
     cls.git_helper.command_fetch(upstream_name)
     cls.output_data = cls.git_helper.command_log(parameters='--pretty=oneline')
     logger.debug('Outputdata from git log %s', cls.output_data)
     number = 0
     if cls.prep_section:
         number = 1
     last_hash = GitHelper.get_commit_hash_log(cls.output_data, number=number)
     init_hash = GitHelper.get_commit_hash_log(cls.output_data, len(cls.output_data)-1)
     return init_hash, last_hash
Beispiel #2
0
 def _prepare_git(cls, upstream_name):
     cls.git_helper.command_remote_add(upstream_name, cls.new_sources)
     cls.git_helper.command_fetch(upstream_name)
     cls.output_data = cls.git_helper.command_log(
         parameters='--pretty=oneline')
     logger.debug('Outputdata from git log %s', cls.output_data)
     number = 0
     if cls.prep_section:
         number = 1
     last_hash = GitHelper.get_commit_hash_log(cls.output_data,
                                               number=number)
     init_hash = GitHelper.get_commit_hash_log(cls.output_data,
                                               len(cls.output_data) - 1)
     return init_hash, last_hash
Beispiel #3
0
 def _git_rebase(cls):
     """Function performs git rebase between old and new sources"""
     # in old_sources do.
     # 1) git remote add new_sources <path_to_new_sources>
     # 2) git fetch new_sources
     # 3 git rebase -i --onto new_sources/master <oldest_commit_old_source> <the_latest_commit_old_sourcese>
     if not cls.cont:
         logger.info('Git-rebase operation to %s is ongoing...', os.path.basename(cls.new_sources))
         upstream = 'new_upstream'
         init_hash, last_hash = cls._prepare_git(upstream)
         ret_code = cls.git_helper.command_rebase(parameters='--onto', upstream_name=upstream,
                                                  first_hash=init_hash, last_hash=last_hash)
     else:
         logger.info('Git-rebase operation continues...')
         ret_code = cls.git_helper.command_rebase(parameters='--skip')
     cls._get_git_helper_data()
     logger.debug(cls.output_data)
     patch_dictionary = {}
     modified_patches = []
     deleted_patches = []
     unapplied_patches = []
     while True:
         log = cls.git_helper.command_log(parameters='--pretty=oneline')
         for patch_name in cls.git_helper.get_automerged_patches(cls.output_data):
             index = [i for i, l in enumerate(log) if l.endswith(patch_name)]
             if index:
                 commit = GitHelper.get_commit_hash_log(log, number=index[0])
                 base_name = os.path.join(cls.kwargs['results_dir'], patch_name)
                 cls.git_helper.command_diff('{}~1'.format(commit), commit, output_file=base_name)
                 modified_patches.append(base_name)
         if int(ret_code) != 0:
             if not cls.non_interactive:
                 patch_name = cls.git_helper.get_unapplied_patch(cls.output_data)
                 logger.info("Git has problems with rebasing patch %s", patch_name)
                 cls.git_helper.command_mergetool()
             else:
                 # Take the patch which failed from .git/rebase-apply/next file
                 try:
                     with open(os.path.join(cls.old_sources, '.git', 'rebase-apply', 'next')) as f:
                         number = '\n'.join(f.readlines())
                 except IOError:
                     raise RuntimeError("Git rebase failed with unknown reason. Please check log file")
                 # Getting the patch which failed
                 unapplied_patches.append(cls.patches[int(number) - 1].get_patch_name())
                 ret_code = cls.git_helper.command_rebase('--skip')
                 cls._get_git_helper_data()
                 continue
             modified_files = cls.git_helper.command_diff_status()
             cls.git_helper.command_add_files(parameters=modified_files)
             base_name = os.path.join(cls.kwargs['results_dir'], patch_name)
             cls.git_helper.command_diff('HEAD', output_file=base_name)
             with open(base_name, "r") as f:
                 del_patches = f.readlines()
             if not del_patches:
                 deleted_patches.append(base_name)
             else:
                 logger.info('Following files were modified: %s', ','.join(modified_files))
                 cls.git_helper.command_commit(message=patch_name)
                 cls.git_helper.command_diff('HEAD~1', output_file=base_name)
                 modified_patches.append(base_name)
             if not cls.non_interactive:
                 if not ConsoleHelper.get_message('Do you want to continue with another patch'):
                     raise KeyboardInterrupt
             ret_code = cls.git_helper.command_rebase('--skip')
             cls._get_git_helper_data()
         else:
             break
     deleted_patches = cls._update_deleted_patches(deleted_patches)
     if deleted_patches:
         patch_dictionary['deleted'] = deleted_patches
     if modified_patches:
         patch_dictionary['modified'] = modified_patches
     if unapplied_patches:
         patch_dictionary['unapplied'] = unapplied_patches
     #TODO correct settings for merge tool in ~/.gitconfig
     # currently now meld is not started
     return patch_dictionary
Beispiel #4
0
 def _git_rebase(cls):
     """Function performs git rebase between old and new sources"""
     # in old_sources do.
     # 1) git remote add new_sources <path_to_new_sources>
     # 2) git fetch new_sources
     # 3 git rebase -i --onto new_sources/master <oldest_commit_old_source> <the_latest_commit_old_sourcese>
     if not cls.cont:
         logger.info('Git-rebase operation to %s is ongoing...',
                     os.path.basename(cls.new_sources))
         upstream = 'new_upstream'
         init_hash, last_hash = cls._prepare_git(upstream)
         ret_code = cls.git_helper.command_rebase(parameters='--onto',
                                                  upstream_name=upstream,
                                                  first_hash=init_hash,
                                                  last_hash=last_hash)
     else:
         logger.info('Git-rebase operation continues...')
         ret_code = cls.git_helper.command_rebase(parameters='--skip')
     cls._get_git_helper_data()
     logger.debug(cls.output_data)
     patch_dictionary = {}
     modified_patches = []
     deleted_patches = []
     unapplied_patches = []
     while True:
         log = cls.git_helper.command_log(parameters='--pretty=oneline')
         for patch_name in cls.git_helper.get_automerged_patches(
                 cls.output_data):
             index = [
                 i for i, l in enumerate(log) if l.endswith(patch_name)
             ]
             if index:
                 commit = GitHelper.get_commit_hash_log(log,
                                                        number=index[0])
                 base_name = os.path.join(cls.kwargs['results_dir'],
                                          patch_name)
                 cls.git_helper.command_diff('{}~1'.format(commit),
                                             commit,
                                             output_file=base_name)
                 modified_patches.append(base_name)
         if int(ret_code) != 0:
             if not cls.non_interactive:
                 patch_name = cls.git_helper.get_unapplied_patch(
                     cls.output_data)
                 logger.info("Git has problems with rebasing patch %s",
                             patch_name)
                 cls.git_helper.command_mergetool()
             else:
                 # Take the patch which failed from .git/rebase-apply/next file
                 try:
                     with open(
                             os.path.join(cls.old_sources, '.git',
                                          'rebase-apply', 'next')) as f:
                         number = '\n'.join(f.readlines())
                 except IOError:
                     raise RuntimeError(
                         "Git rebase failed with unknown reason. Please check log file"
                     )
                 # Getting the patch which failed
                 unapplied_patches.append(cls.patches[int(number) -
                                                      1].get_patch_name())
                 ret_code = cls.git_helper.command_rebase('--skip')
                 cls._get_git_helper_data()
                 continue
             modified_files = cls.git_helper.command_diff_status()
             cls.git_helper.command_add_files(parameters=modified_files)
             base_name = os.path.join(cls.kwargs['results_dir'], patch_name)
             cls.git_helper.command_diff('HEAD', output_file=base_name)
             with open(base_name, "r") as f:
                 del_patches = f.readlines()
             if not del_patches:
                 deleted_patches.append(base_name)
             else:
                 logger.info('Following files were modified: %s',
                             ','.join(modified_files))
                 cls.git_helper.command_commit(message=patch_name)
                 cls.git_helper.command_diff('HEAD~1',
                                             output_file=base_name)
                 modified_patches.append(base_name)
             if not cls.non_interactive:
                 if not ConsoleHelper.get_message(
                         'Do you want to continue with another patch'):
                     raise KeyboardInterrupt
             ret_code = cls.git_helper.command_rebase('--skip')
             cls._get_git_helper_data()
         else:
             break
     deleted_patches = cls._update_deleted_patches(deleted_patches,
                                                   unapplied_patches)
     if deleted_patches:
         patch_dictionary['deleted'] = deleted_patches
     if modified_patches:
         patch_dictionary['modified'] = modified_patches
     if unapplied_patches:
         patch_dictionary['unapplied'] = unapplied_patches
     #TODO correct settings for merge tool in ~/.gitconfig
     # currently now meld is not started
     return patch_dictionary