git: verify commit user is set (#5754)

This commit is contained in:
Peter Rowlands (변기호)
2021-04-01 17:04:45 +09:00
committed by GitHub
parent 17e5da7759
commit 66caa345b1
2 changed files with 24 additions and 3 deletions
+13 -1
View File
@@ -182,11 +182,16 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
def commit(self, msg: str, no_verify: bool = False):
from dulwich.errors import CommitError
from dulwich.porcelain import commit
from dulwich.repo import InvalidUserIdentity
try:
commit(self.root_dir, message=msg, no_verify=no_verify)
except CommitError as exc:
raise SCMError("Git commit failed") from exc
except InvalidUserIdentity as exc:
raise SCMError(
"Git username and email must be configured"
) from exc
def checkout(
self,
@@ -528,6 +533,8 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
message: Optional[str] = None,
include_untracked: Optional[bool] = False,
) -> Tuple[Optional[str], bool]:
from dulwich.repo import InvalidUserIdentity
from dvc.scm.git import Stash
if include_untracked or ref == Stash.DEFAULT_STASH:
@@ -537,7 +544,12 @@ class DulwichBackend(BaseGitBackend): # pylint:disable=abstract-method
stash = self._get_stash(ref)
message_b = message.encode("utf-8") if message else None
rev = stash.push(message=message_b)
try:
rev = stash.push(message=message_b)
except InvalidUserIdentity as exc:
raise SCMError(
"Git username and email must be configured"
) from exc
return os.fsdecode(rev), True
def _stash_apply(self, rev: str):
+11 -2
View File
@@ -80,6 +80,15 @@ class Pygit2Backend(BaseGitBackend): # pylint:disable=abstract-method
return RefdbFsBackend(self.repo)
@property
def default_signature(self):
try:
return self.repo.default_signature
except KeyError as exc:
raise SCMError(
"Git username and email must be configured"
) from exc
@staticmethod
def clone(
url: str,
@@ -328,7 +337,7 @@ class Pygit2Backend(BaseGitBackend): # pylint:disable=abstract-method
from dvc.scm.git import Stash
oid = self.repo.stash(
self.repo.default_signature,
self.default_signature,
message=message,
include_untracked=include_untracked,
)
@@ -503,7 +512,7 @@ class Pygit2Backend(BaseGitBackend): # pylint:disable=abstract-method
raise MergeConflictError("Merge contained conflicts")
if commit:
user = self.repo.default_signature
user = self.default_signature
tree = self.repo.index.write_tree()
merge_commit = self.repo.create_commit(
"HEAD", user, user, msg, tree, [self.repo.head.target, rev]