コード例 #1
0
ファイル: gitpython.py プロジェクト: rpatil524/dvc
    def merge(
        self,
        rev: str,
        commit: bool = True,
        msg: Optional[str] = None,
        squash: bool = False,
    ) -> Optional[str]:
        from git.exc import GitCommandError

        if commit and squash:
            raise SCMError("Cannot merge with 'squash' and 'commit'")

        if commit and not msg:
            raise SCMError("Merge commit message is required")

        merge = partial(self.git.merge, rev)
        try:
            if commit:
                merge(m=msg)
                return self.get_rev()
            merge(no_commit=True, squash=True)
        except GitCommandError as exc:
            if "CONFLICT" in str(exc):
                raise MergeConflictError("Merge contained conflicts") from exc
            raise SCMError("Merge failed") from exc
        return None
コード例 #2
0
ファイル: pygit2.py プロジェクト: yyqgood/dvc
    def merge(
        self,
        rev: str,
        commit: bool = True,
        msg: Optional[str] = None,
        squash: bool = False,
    ) -> Optional[str]:
        from pygit2 import GIT_RESET_MIXED, GitError

        if commit and squash:
            raise SCMError("Cannot merge with 'squash' and 'commit'")

        if commit and not msg:
            raise SCMError("Merge commit message is required")

        try:
            self.repo.merge(rev)
        except GitError as exc:
            raise SCMError("Merge failed") from exc

        if self.repo.index.conflicts:
            raise MergeConflictError("Merge contained conflicts")

        if commit:
            user = self.repo.default_signature
            tree = self.repo.index.write_tree()
            merge_commit = self.repo.create_commit(
                "HEAD", user, user, msg, tree, [self.repo.head.target, rev])
            return str(merge_commit)
        if squash:
            self.repo.reset(self.repo.head.target, GIT_RESET_MIXED)
            self.repo.state_cleanup()
        return None
コード例 #3
0
 def _apply(index):
     try:
         self.repo.index.read(False)
         self.repo.stash_apply(index,
                               strategy=self._get_checkout_strategy())
     except GitError as exc:
         raise MergeConflictError(
             "Stash apply resulted in merge conflicts") from exc
コード例 #4
0
 def _apply(index):
     try:
         self.repo.index.read(False)
         self.repo.stash_apply(
             index,
             strategy=GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING,
         )
     except GitError as exc:
         raise MergeConflictError(
             "Stash apply resulted in merge conflicts") from exc
コード例 #5
0
    def _stash_apply(self, rev: str):
        from git.exc import GitCommandError

        try:
            self.git.stash("apply", rev)
        except GitCommandError as exc:
            if "CONFLICT" in str(exc):
                raise MergeConflictError(
                    "Stash apply resulted in merge conflicts") from exc
            raise SCMError("Could not apply stash") from exc