示例#1
0
 def test_git_apply(self):
     patch_object = PatchObject(os.path.join(self.WORKING_DIR, self.PATCH_1), 1, None)
     GitPatchTool.apply_patch(self.git_helper, patch_object)
     GitPatchTool.commit_patch(self.git_helper, os.path.join(self.WORKING_DIR, self.PATCH_1))
     # Try catch is workaroung for Travis CI
     try:
         commit_message = self._parse_commit_log()
     except TypeError:
         commit_message = ['Patch: project-ChangeLog.patch', 'Initial Commit']
     assert commit_message == ['Patch: project-ChangeLog.patch', 'Initial Commit']
 def test__git_rebase(self, rebased_sources, old_sources, new_sources,
                      old_repo, new_repo, favor_on_conflict):
     GitPatchTool.cont = False
     GitPatchTool.non_interactive = True
     GitPatchTool.kwargs = dict(rebased_sources_dir=rebased_sources)
     GitPatchTool.old_sources = old_sources
     GitPatchTool.new_sources = new_sources
     GitPatchTool.old_repo = old_repo
     GitPatchTool.new_repo = new_repo
     GitPatchTool.favor_on_conflict = favor_on_conflict
     GitPatchTool.patches = [
         PatchObject(os.path.basename(getattr(self, 'PATCH{0}'.format(n))),
                     n, 1) for n in range(1, 5)
     ]
     patches = GitPatchTool._git_rebase()  # pylint: disable=protected-access
     assert patches['untouched'] == [os.path.basename(self.PATCH1)]
     if favor_on_conflict == 'upstream':
         assert patches['modified'] == [os.path.basename(self.PATCH2)]
         assert patches['deleted'] == [
             os.path.basename(self.PATCH3),
             os.path.basename(self.PATCH4)
         ]
         assert 'inapplicable' not in patches
     elif favor_on_conflict == 'downstream':
         assert patches['modified'] == [
             os.path.basename(self.PATCH2),
             os.path.basename(self.PATCH3)
         ]
         assert patches['deleted'] == [os.path.basename(self.PATCH4)]
         assert 'inapplicable' not in patches
     else:
         assert patches['modified'] == [os.path.basename(self.PATCH2)]
         assert patches['deleted'] == [os.path.basename(self.PATCH4)]
         assert patches['inapplicable'] == [os.path.basename(self.PATCH3)]
     with open(os.path.join(rebased_sources,
                            os.path.basename(self.PATCH2))) as f:
         content = f.read()
         assert 'From: {0} <{1}>\n'.format(self.USER, self.EMAIL) in content
         assert 'Subject: [PATCH] P2\n' in content
         assert GitPatchTool.decorate_patch_name(
             os.path.basename(self.PATCH2)) not in content
 def old_repo(self, old_sources):
     repo = git.Repo.init(old_sources)
     repo.git.config('user.name', self.USER, local=True)
     repo.git.config('user.email', self.EMAIL, local=True)
     shutil.copy(os.path.basename(self.LIPSUM_OLD),
                 os.path.join(old_sources, 'lipsum.txt'))
     repo.git.add(all=True)
     repo.index.commit('Initial commit', skip_hooks=True)
     for n in range(1, 5):
         patch_name = os.path.basename(getattr(self, 'PATCH{0}'.format(n)))
         repo.git.apply(os.path.join(os.getcwd(), patch_name))
         repo.git.add(all=True)
         repo.index.commit(GitPatchTool.insert_patch_name(
             'P{0}'.format(n), patch_name),
                           skip_hooks=True)
     return repo
示例#4
0
 def _init_git_repo(self, dirname):
     GitPatchTool.init_git(dirname)
示例#5
0
 def test_git_apply(self):
     GitPatchTool.apply_patch(self.git_helper, os.path.join(self.WORKING_DIR, self.PATCH_1))
     GitPatchTool.commit_patch(self.git_helper, os.path.join(self.WORKING_DIR, self.PATCH_1))
     commit_message = self._parse_commit_log()
     assert commit_message == ['Patch: project-ChangeLog.patch', 'Initial Commit']