Skip to content

Commit eb217db

Browse files
committed
improve index mode for executable files
The fix for gitpython-developers#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 gitpython-developers#1253 ¹ https://github.com/git/git/blob/v2.31.1/cache.h#L247
1 parent ea43def commit eb217db

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
@@ -10,6 +10,7 @@
1010
S_ISDIR,
1111
S_IFMT,
1212
S_IFREG,
13+
S_IXUSR,
1314
)
1415
import subprocess
1516

@@ -103,7 +104,7 @@ def stat_mode_to_index_mode(mode):
103104
return S_IFLNK
104105
if S_ISDIR(mode) or S_IFMT(mode) == S_IFGITLINK: # submodules
105106
return S_IFGITLINK
106-
return S_IFREG | 0o644 | (mode & 0o111) # blobs with or without executable bit
107+
return S_IFREG | (mode & S_IXUSR and 0o755 or 0o644) # blobs with or without executable bit
107108

108109

109110
def write_cache(entries, stream, extension_data=None, ShaStreamCls=IndexFileSHA1Writer):

0 commit comments

Comments
 (0)