mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 19:21:08 +00:00
Merge pull request #9233 from davidhorstmann-arm/make-code-style-work-in-commit-hook
Allow `code_style.py` to work from a git hook
This commit is contained in:
commit
4ac0182cae
@ -75,8 +75,24 @@ def get_src_files(since: Optional[str]) -> List[str]:
|
|||||||
output = subprocess.check_output(["git", "ls-files"] + file_patterns,
|
output = subprocess.check_output(["git", "ls-files"] + file_patterns,
|
||||||
universal_newlines=True)
|
universal_newlines=True)
|
||||||
src_files = output.split()
|
src_files = output.split()
|
||||||
|
|
||||||
|
# When this script is called from a git hook, some environment variables
|
||||||
|
# are set by default which force all git commands to use the main repository
|
||||||
|
# (i.e. prevent us from performing commands on the framework repo).
|
||||||
|
# Create an environment without these variables for running commands on the
|
||||||
|
# framework repo.
|
||||||
|
framework_env = os.environ.copy()
|
||||||
|
# Get a list of environment vars that git sets
|
||||||
|
git_env_vars = subprocess.check_output(["git", "rev-parse", "--local-env-vars"],
|
||||||
|
universal_newlines=True)
|
||||||
|
# Remove the vars from the environment
|
||||||
|
for var in git_env_vars.split():
|
||||||
|
framework_env.pop(var, None)
|
||||||
|
|
||||||
output = subprocess.check_output(["git", "-C", "framework", "ls-files"]
|
output = subprocess.check_output(["git", "-C", "framework", "ls-files"]
|
||||||
+ file_patterns, universal_newlines=True)
|
+ file_patterns,
|
||||||
|
universal_newlines=True,
|
||||||
|
env=framework_env)
|
||||||
framework_src_files = output.split()
|
framework_src_files = output.split()
|
||||||
|
|
||||||
if since:
|
if since:
|
||||||
@ -89,7 +105,8 @@ def get_src_files(since: Optional[str]) -> List[str]:
|
|||||||
# ... the framework submodule
|
# ... the framework submodule
|
||||||
cmd = ["git", "-C", "framework", "log", since + "..HEAD",
|
cmd = ["git", "-C", "framework", "log", since + "..HEAD",
|
||||||
"--name-only", "--pretty=", "--"] + framework_src_files
|
"--name-only", "--pretty=", "--"] + framework_src_files
|
||||||
output = subprocess.check_output(cmd, universal_newlines=True)
|
output = subprocess.check_output(cmd, universal_newlines=True,
|
||||||
|
env=framework_env)
|
||||||
committed_changed_files += ["framework/" + s for s in output.split()]
|
committed_changed_files += ["framework/" + s for s in output.split()]
|
||||||
|
|
||||||
# and also get all files with uncommitted changes in ...
|
# and also get all files with uncommitted changes in ...
|
||||||
@ -100,7 +117,8 @@ def get_src_files(since: Optional[str]) -> List[str]:
|
|||||||
# ... the framework submodule
|
# ... the framework submodule
|
||||||
cmd = ["git", "-C", "framework", "diff", "--name-only", "--"] + \
|
cmd = ["git", "-C", "framework", "diff", "--name-only", "--"] + \
|
||||||
framework_src_files
|
framework_src_files
|
||||||
output = subprocess.check_output(cmd, universal_newlines=True)
|
output = subprocess.check_output(cmd, universal_newlines=True,
|
||||||
|
env=framework_env)
|
||||||
uncommitted_changed_files += ["framework/" + s for s in output.split()]
|
uncommitted_changed_files += ["framework/" + s for s in output.split()]
|
||||||
|
|
||||||
src_files = committed_changed_files + uncommitted_changed_files
|
src_files = committed_changed_files + uncommitted_changed_files
|
||||||
|
Loading…
x
Reference in New Issue
Block a user