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
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
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
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
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