Skip to content
Merged
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
4 changes: 3 additions & 1 deletion git/objects/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ def mode_str_to_int(modestr: Union[bytes, str]) -> int:
module regarding the rwx permissions for user, group and other, special flags
and file system flags, such as whether it is a symlink.
"""
if isinstance(modestr, bytes):
# A byte is an int. int(b"4"[0]) is 52, so b"100644" became 0o6767524.
modestr = modestr.decode("ascii")
mode = 0
for iteration, char in enumerate(reversed(modestr[-6:])):
char = cast(Union[str, int], char)
mode += int(char) << iteration * 3
# END for each char
return mode
Expand Down
8 changes: 8 additions & 0 deletions test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from git.objects.util import (
altz_to_utctz_str,
from_timestamp,
mode_str_to_int,
parse_actor_and_date,
parse_date,
tzoffset,
Expand Down Expand Up @@ -760,3 +761,10 @@ def test_remove_password_from_command_line(self):
redacted_cmd_6 = remove_password_if_present(cmd_6)
assert authorization not in " ".join(redacted_cmd_6)
assert "http.extraHeader=Authorization: *****" in redacted_cmd_6


def test_mode_str_to_int_accepts_bytes():
assert mode_str_to_int("100644") == 0o100644
assert mode_str_to_int(b"100644") == 0o100644
assert mode_str_to_int("644") == 0o644
assert mode_str_to_int(b"120000") == 0o120000
Loading