mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-02 12:14:32 +02:00
pre-commit: recognize Windows excecutable files with git
This commit is contained in:
@@ -18,6 +18,8 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
from sys import exit
|
from sys import exit
|
||||||
|
|
||||||
|
from idf_ci_utils import is_executable
|
||||||
|
|
||||||
|
|
||||||
def _strip_each_item(iterable):
|
def _strip_each_item(iterable):
|
||||||
res = []
|
res = []
|
||||||
@@ -44,6 +46,8 @@ def check_executable_list():
|
|||||||
def check_executables(files):
|
def check_executables(files):
|
||||||
ret = 0
|
ret = 0
|
||||||
for fn in files:
|
for fn in files:
|
||||||
|
if not is_executable(fn):
|
||||||
|
continue
|
||||||
if fn not in known_executables:
|
if fn not in known_executables:
|
||||||
print('"{}" is not in {}'.format(fn, EXECUTABLE_LIST_FN))
|
print('"{}" is not in {}'.format(fn, EXECUTABLE_LIST_FN))
|
||||||
ret = 1
|
ret = 1
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
IDF_PATH = os.getenv('IDF_PATH', os.path.join(os.path.dirname(__file__), '..', '..'))
|
IDF_PATH = os.getenv('IDF_PATH', os.path.join(os.path.dirname(__file__), '..', '..'))
|
||||||
|
|
||||||
@@ -44,3 +45,27 @@ def get_submodule_dirs(full_path=False): # type: (bool) -> list
|
|||||||
logging.warning(str(e))
|
logging.warning(str(e))
|
||||||
|
|
||||||
return dirs
|
return dirs
|
||||||
|
|
||||||
|
|
||||||
|
def _check_git_filemode(full_path): # type: (str) -> bool
|
||||||
|
try:
|
||||||
|
stdout = subprocess.check_output(['git', 'ls-files', '--stage', full_path]).strip().decode('utf-8')
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return True
|
||||||
|
|
||||||
|
mode = stdout.split(' ', 1)[0] # e.g. 100644 for a rw-r--r--
|
||||||
|
if any([int(i, 8) & 1 for i in mode[-3:]]):
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def is_executable(full_path): # type: (str) -> bool
|
||||||
|
"""
|
||||||
|
os.X_OK will always return true on windows. Use git to check file mode.
|
||||||
|
:param full_path: file full path
|
||||||
|
:return: True is it's an executable file
|
||||||
|
"""
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
return _check_git_filemode(full_path)
|
||||||
|
else:
|
||||||
|
return os.access(full_path, os.X_OK)
|
||||||
|
Reference in New Issue
Block a user