-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/tempo pattern compiler #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d40a7c9
starting point
magmacomputing 1aaba36
new content
magmacomputing 7e3928a
refactor: migrate regex compilation logic to PatternCompiler class fo…
magmacomputing 3b7a121
PR 1st review
magmacomputing 97c2f0c
PR 2nd review
magmacomputing 35b2dd3
PR 3rd review
magmacomputing 6d4f30f
rm parse/
magmacomputing 9f74183
PR 4th review
magmacomputing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| # Preventing Writes to the Main Branch Locally | ||
|
|
||
| To prevent accidental writes (commits and pushes) to the `main` branch on your local workstation, you can use **Git Hooks**. | ||
|
|
||
|
|
||
| ## Example: Local Hooks for Main Branch Protection | ||
| Set up local hooks to: | ||
| 1. **`pre-commit`**: Prevent direct commits to the `main` branch. | ||
| 2. **`pre-push`**: Prevent pushing changes to the remote `main` branch. | ||
|
|
||
| ### How to Override | ||
| If you genuinely need to write to `main` (e.g., for an urgent fix), you have two options: | ||
| - **Environment Variable**: Prepend the command with the override flag: | ||
| - `ALLOW_MAIN_COMMIT=true git commit -m "Urgent fix"` | ||
| - `ALLOW_MAIN_PUSH=true git push` | ||
| - **Skip Hooks**: Use the standard Git flag: | ||
| - `git commit --no-verify` | ||
| - `git push --no-verify` | ||
|
|
||
| --- | ||
|
|
||
| ## Applying This Globally (Recommended) | ||
| If you want this protection to apply to **every repository** on your workstation, you can configure a global hooks directory. | ||
|
|
||
| ### 1. Create a Global Hooks Directory | ||
| Choose a location (e.g., `~/.git-hooks`) and move the hook scripts there: | ||
|
|
||
| ```bash | ||
| mkdir -p ~/.git-hooks | ||
| # Copy the hooks from your repository (replace /path/to/repo with your repo root or use the command below) | ||
| # Example using git to find the repo root: | ||
| cp $(git rev-parse --show-toplevel)/.git/hooks/pre-commit ~/.git-hooks/ | ||
| cp $(git rev-parse --show-toplevel)/.git/hooks/pre-push ~/.git-hooks/ | ||
| chmod +x ~/.git-hooks/* | ||
| ``` | ||
|
|
||
|
|
||
| ### 2. Configure Git Globally (with Important Warning) | ||
| Run this command to tell Git to use your new global hooks directory: | ||
|
|
||
| ```bash | ||
| git config --global core.hooksPath ~/.git-hooks | ||
| ``` | ||
|
|
||
| **⚠️ Warning:** Setting `core.hooksPath` with the `--global` flag disables all per-repository `.git/hooks/*` scripts. This will break tools that rely on per-project hooks, such as Husky, lefthook, lint-staged, and others. Any hooks defined in individual repositories will be ignored as long as the global `core.hooksPath` is set. | ||
|
|
||
| #### Recommended Alternatives | ||
|
|
||
| - **Chain per-repo hooks from your global hook scripts:** | ||
| - Manually update your global hook scripts (in `~/.git-hooks/`) to call any existing hooks in each repository’s `.git/hooks/` directory, so you don’t lose project-specific logic. | ||
| - **Scope the setting to individual repositories:** | ||
| - Instead of using `--global`, set the hooks path only for the current repository: | ||
| ```bash | ||
| git config core.hooksPath ~/.git-hooks | ||
| ``` | ||
| - This way, only the current repo is affected, and other repos keep their own `.git/hooks/*` scripts. | ||
|
|
||
| For more details, see the [Git documentation on `core.hooksPath`](https://git-scm.com/docs/git-config#Documentation/git-config.txt-corehookspath). | ||
|
|
||
| --- | ||
|
|
||
| ## Hook Implementation Details | ||
|
|
||
| ### pre-commit | ||
| This script checks the current branch before every commit. | ||
|
|
||
| ```bash | ||
| #!/bin/bash | ||
| CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD) | ||
| if [ "$CURRENT_BRANCH" = "main" ]; then | ||
| if [ "$ALLOW_MAIN_COMMIT" != "true" ]; then | ||
| echo "❌ ERROR: Direct commit to 'main' branch is prohibited." | ||
| exit 1 | ||
| fi | ||
| fi | ||
| ``` | ||
|
|
||
| ### pre-push | ||
| This script checks the remote branch being pushed to. | ||
|
|
||
| ```bash | ||
| #!/bin/bash | ||
| while read local_ref local_sha remote_ref remote_sha | ||
| do | ||
| if [ "$remote_ref" = "refs/heads/main" ]; then | ||
| if [ "$ALLOW_MAIN_PUSH" != "true" ]; then | ||
| echo "❌ ERROR: Pushing to 'main' branch is prohibited." | ||
| exit 1 | ||
| fi | ||
| fi | ||
| done | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🆘 I'm on 'main' and have changes, what do I do? | ||
|
|
||
| If you've already made changes on `main` and the hook blocks your commit, **don't panic and don't drop your stash!** You can easily move your work to a new branch. | ||
|
|
||
| ### The "Magic" Command: Just Create a New Branch | ||
| Git allows you to create and switch to a new branch while keeping your uncommitted changes. | ||
|
|
||
| ```bash | ||
| # 1. Create and switch to a new branch | ||
| git checkout -b feature/my-cool-feature | ||
| # OR (modern syntax) | ||
| git switch -c feature/my-cool-feature | ||
|
|
||
| # 2. Now you can commit normally | ||
| git add . | ||
| git commit -m "My feature changes" | ||
| ``` | ||
|
|
||
| ### If you want to be extra safe (The Stash Method) | ||
| If you have a lot of complex changes and want to ensure `main` stays clean: | ||
|
|
||
| ```bash | ||
| # 1. Save your work temporarily | ||
| git stash | ||
|
|
||
| # 2. Create and switch to the new branch | ||
| git checkout -b feature/my-cool-feature | ||
|
|
||
| # 3. Bring your changes back | ||
| git stash pop | ||
|
|
||
| # 4. Commit | ||
| git commit -am "My feature changes" | ||
| ``` | ||
|
|
||
| ### "I accidentally committed before I added the hook!" | ||
| If you have local commits on `main` that you haven't pushed yet, you can move them to a new branch: | ||
|
|
||
| ```bash | ||
| # 1. Create a new branch at your current (accidental) commit | ||
| git branch feature/my-feature | ||
|
|
||
| # 2. Make sure your local reference to 'origin/main' is up-to-date | ||
| git fetch origin | ||
| # 3. Reset your local 'main' back to where it should be (the remote version) | ||
| # (Fetching first ensures you don't accidentally reset to a stale origin/main reference) | ||
| git reset --hard origin/main | ||
|
|
||
| # 4. Switch to your new branch to continue working | ||
| git checkout feature/my-feature | ||
| ``` | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.