Skip to content

improve index mode for executable files #1254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2021
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
3 changes: 2 additions & 1 deletion git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
S_ISDIR,
S_IFMT,
S_IFREG,
S_IXUSR,
)
import subprocess

Expand Down Expand Up @@ -115,7 +116,7 @@ def stat_mode_to_index_mode(mode):
return S_IFLNK
if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules
return S_IFGITLINK
return S_IFREG | 0o644 | (mode & 0o111) # blobs with or without executable bit
return S_IFREG | (mode & S_IXUSR and 0o755 or 0o644) # blobs with or without executable bit


def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream: IO[bytes],
Expand Down
15 changes: 13 additions & 2 deletions test/test_fun.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from io import BytesIO
from stat import S_IFDIR, S_IFREG, S_IFLNK
from stat import S_IFDIR, S_IFREG, S_IFLNK, S_IXUSR
from os import stat
import os.path as osp
from unittest import SkipTest

from git import Git
from git.index import IndexFile
from git.index.fun import (
aggressive_tree_merge
aggressive_tree_merge,
stat_mode_to_index_mode,
)
from git.objects.fun import (
traverse_tree_recursive,
Expand Down Expand Up @@ -206,6 +207,16 @@ def assert_entries(entries, num_entries, has_conflict=False):
assert_entries(aggressive_tree_merge(odb, trees), 2, True)
# END handle ours, theirs

def test_stat_mode_to_index_mode(self):
modes = (
0o600, 0o611, 0o640, 0o641, 0o644, 0o650, 0o651,
0o700, 0o711, 0o740, 0o744, 0o750, 0o751, 0o755,
)
for mode in modes:
expected_mode = S_IFREG | (mode & S_IXUSR and 0o755 or 0o644)
assert stat_mode_to_index_mode(mode) == expected_mode
# END for each mode

def _assert_tree_entries(self, entries, num_trees):
for entry in entries:
assert len(entry) == num_trees
Expand Down