Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pygit2/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
from .remotes import RemoteCollection
from .submodules import SubmoduleCollection
from .transaction import ReferenceTransaction
from .utils import StrArray, to_bytes
from .utils import StrArray, maybe_string, to_bytes

if TYPE_CHECKING:
from pygit2._libgit2.ffi import (
Expand Down Expand Up @@ -1278,7 +1278,7 @@ def stash(
Example::

>>> repo = pygit2.Repository('.')
>>> repo.stash(repo.default_signature(), 'WIP: stashing')
>>> repo.stash(repo.default_signature, 'WIP: stashing')
"""

opts = ffi.new('git_stash_save_options *')
Expand Down Expand Up @@ -1347,7 +1347,7 @@ def stash_apply(
Example::

>>> repo = pygit2.Repository('.')
>>> repo.stash(repo.default_signature(), 'WIP: stashing')
>>> repo.stash(repo.default_signature, 'WIP: stashing')
>>> repo.stash_apply(strategy=CheckoutStrategy.ALLOW_CONFLICTS)
"""
with git_stash_apply_options(
Expand Down Expand Up @@ -1578,16 +1578,16 @@ def get_attr(
# Identity for reference operations
#
@property
def ident(self):
def ident(self) -> tuple[Optional[str], Optional[str]]:
cname = ffi.new('char **')
cemail = ffi.new('char **')

err = C.git_repository_ident(cname, cemail, self._repo)
check_error(err)

return (ffi.string(cname).decode('utf-8'), ffi.string(cemail).decode('utf-8'))
return (maybe_string(cname[0]), maybe_string(cemail[0]))

def set_ident(self, name: str, email: str) -> None:
def set_ident(self, name: Optional[str], email: Optional[str]) -> None:
"""Set the identity to be used for reference operations.

Updates to some references also append data to their
Expand Down
13 changes: 13 additions & 0 deletions test/test_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,19 @@ def test_default_signature(testrepo: Repository) -> None:
assert 'rjh@example.com' == sig.email


def test_ident_get_set(testrepo: Repository) -> None:
# By default, reflog identity should be unset.
assert testrepo.ident == (None, None)

cname = 'C O Mitter'
cemail = 'committer@example.com'
testrepo.set_ident(cname, cemail)
assert testrepo.ident == (cname, cemail)

testrepo.set_ident(None, None)
assert testrepo.ident == (None, None)


def test_new_repo(tmp_path: Path) -> None:
repo = init_repository(tmp_path, False)

Expand Down