Skip to content
Draft
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
33 changes: 33 additions & 0 deletions .githooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Git Hooks

This directory contains git hooks for the repository.

## Setup

To enable the git hooks, run:

```bash
python3 .githooks/setup.py
```

Or on Windows:
```cmd
python .githooks\setup.py
```

This configures git to use hooks from this directory instead of the default `.git/hooks`.

**Note:** The hooks are written in Python for cross-platform compatibility (Linux, macOS, Windows).

## Available Hooks

### pre-commit

Automatically updates copyright years in files being committed. The hook:
- Runs `scripts/update_copyright.py` on modified files
- Updates copyright year ranges (e.g., 2019-2024 → 2019-2025)
- Adds single years where missing (e.g., 2019 → 2019-2025)
- Automatically stages the copyright changes
- Works across Linux, macOS, and Windows

The hook only modifies files already staged for commit and will not cause the commit to fail.
59 changes: 59 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
"""
Pre-commit hook to update copyright years in modified files.
This script is cross-platform compatible (Linux, macOS, Windows).
"""

import subprocess
import sys
from pathlib import Path

def main():
"""Run the copyright update script and stage changes."""
try:
# Get the root directory of the repo
result = subprocess.run(
['git', 'rev-parse', '--show-toplevel'],
capture_output=True,
text=True,
check=True
)
repo_root = Path(result.stdout.strip())

# Run the update copyright script
copyright_script = repo_root / 'scripts' / 'update_copyright.py'

if not copyright_script.exists():
# Fallback to bash script if Python version doesn't exist
copyright_script = repo_root / 'scripts' / 'update_copyright.sh'
if copyright_script.exists():
subprocess.run(['bash', str(copyright_script)], check=True)
else:
print("Warning: Copyright update script not found", file=sys.stderr)
return 0
else:
# Run in interactive mode (will show preview and ask for confirmation)
result = subprocess.run([sys.executable, str(copyright_script)])

# Check if there were any changes applied
result = subprocess.run(
['git', 'diff', '--quiet'],
capture_output=True
)

if result.returncode != 0:
# There are changes, stage them
print("\nStaging copyright updates...")
subprocess.run(['git', 'add', '-u'], check=True)

return 0

except subprocess.CalledProcessError as e:
print(f"Error running copyright update: {e}", file=sys.stderr)
return 0 # Don't fail the commit
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
return 0 # Don't fail the commit

if __name__ == '__main__':
sys.exit(main())
49 changes: 49 additions & 0 deletions .githooks/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#! /usr/bin/env python3
"""
Copyright (C) 2025-2026 Intel Corporation

SPDX-License-Identifier: MIT

"""
"""
Setup script to configure git hooks for this repository.
This script is cross-platform compatible (Linux, macOS, Windows).
"""

import subprocess
import sys
from pathlib import Path

def main():
"""Configure git to use the .githooks directory."""
try:
# Get the root directory of the repo
result = subprocess.run(
['git', 'rev-parse', '--show-toplevel'],
capture_output=True,
text=True,
check=True
)
repo_root = Path(result.stdout.strip())
githooks_dir = repo_root / '.githooks'

# Configure git to use .githooks directory
subprocess.run(
['git', 'config', 'core.hooksPath', str(githooks_dir)],
check=True
)

print("Git hooks configured successfully!")
print("The pre-commit hook will now automatically update copyright years.")

return 0

except subprocess.CalledProcessError as e:
print(f"Error configuring git hooks: {e}", file=sys.stderr)
return 1
except Exception as e:
print(f"Unexpected error: {e}", file=sys.stderr)
return 1

if __name__ == '__main__':
sys.exit(main())
15 changes: 15 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ We encourage anyone who wants to contribute to submit
review these for proper alignment with the
[Level Zero Specification](https://oneapi-src.github.io/level-zero-spec/level-zero/latest/index.html).

## Git Hooks Setup

To enable automatic copyright year updates and other git hooks, run:

```bash
python3 .githooks/setup.py
```

Or on Windows:
```cmd
python .githooks\setup.py
```

This configures your local repository to use the shared git hooks. The pre-commit hook will automatically update copyright years in modified files before each commit.

## C++ Coding Standards

* C++14 maximum support
Expand Down
Loading