Skip to content

Commit 14dd881

Browse files
committed
improve index mode for executable files
The fix for #430 in bebc4f5 (Use correct mode for executable files, 2016-05-19) is incomplete. It fails (in most cases) when files have modes which are not exactly 0644 or 0755. As git only cares about executable or or not in this case, ensure the mode we set for the index is either 100644 or 100755. Do this similarly to how upstream git does it in cache.h¹. Fixes #1253 ¹ https://github.com/git/git/blob/v2.31.1/cache.h#L247
1 parent eae0e37 commit 14dd881

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

git/index/fun.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
S_ISDIR,
1212
S_IFMT,
1313
S_IFREG,
14+
S_IXUSR,
1415
)
1516
import subprocess
1617

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

120121

121122
def write_cache(entries: Sequence[Union[BaseIndexEntry, 'IndexEntry']], stream: IO[bytes],

0 commit comments

Comments
 (0)