Skip to content

Commit 6814f6e

Browse files
fix: guard post-commit hook against infinite amend loop using GITMIND_RUNNING env var
1 parent 198021e commit 6814f6e

3 files changed

Lines changed: 34 additions & 2 deletions

File tree

hooks/install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ echo "Installing dependencies..."
3434
HOOK_PATH="$TARGET_REPO/.git/hooks/post-commit"
3535
cat > "$HOOK_PATH" << 'EOF'
3636
#!/bin/bash
37+
if [ -n "$GITMIND_RUNNING" ]; then exit 0; fi
38+
export GITMIND_RUNNING=1
3739
GITMIND_DIR="$(git rev-parse --show-toplevel)/.gitmind"
3840
if [ ! -d "$GITMIND_DIR" ]; then exit 0; fi
3941
VENV="$GITMIND_DIR/venv"

hooks/post-commit

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#!/bin/bash
22

3+
# Guard against re-entry: the amend below would trigger this hook again
4+
# without this check, causing an infinite loop.
5+
if [ -n "$GITMIND_RUNNING" ]; then
6+
exit 0
7+
fi
8+
export GITMIND_RUNNING=1
9+
310
GITMIND_DIR="$(git rev-parse --show-toplevel)/.gitmind"
411

512
if [ ! -d "$GITMIND_DIR" ]; then
@@ -15,8 +22,7 @@ else
1522
python3 "$ENGINE"
1623
fi
1724

18-
# Amend the commit to include updated metadata.json.
19-
# --no-verify prevents this hook from firing again on the amend.
25+
# Amend the commit to include the updated metadata.json.
2026
REPO_ROOT="$(git rev-parse --show-toplevel)"
2127
if [ -f "$REPO_ROOT/metadata.json" ]; then
2228
git add "$REPO_ROOT/metadata.json"

metadata.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,17 @@
861861
"last_built_upon": "2026-04-10T22:19:36.411670",
862862
"is_new_feature": false,
863863
"commit_count": 1
864+
},
865+
"snake_case_name_here_using_snake_cases": {
866+
"introduced": "2026-04-10T22:26:01.702419",
867+
"files_touched": [
868+
"hooks/install.sh",
869+
"hooks/post-commit"
870+
],
871+
"still_active": true,
872+
"last_built_upon": "2026-04-10T22:26:01.702419",
873+
"is_new_feature": false,
874+
"commit_count": 1
864875
}
865876
},
866877
"history": [
@@ -2746,6 +2757,19 @@
27462757
"hooks/install.sh",
27472758
"metadata.py"
27482759
]
2760+
},
2761+
{
2762+
"commit_hash": "88d19c8c54f72839fb787bba6c7a0ed8177438cf",
2763+
"timestamp": "2026-04-10T22:26:01.702419",
2764+
"what_changed": "The commit message 'fix' guard post-commit hook against infinite amend loop using GITMIND_RUNNING env var.",
2765+
"why_it_likely_changed": "One sentence string describing the likely reason why this change was made. This field should not be an array of file names, but a plain text description",
2766+
"feature_name": "snake_case_name_here_using_snake_cases",
2767+
"is_new_feature": false,
2768+
"impact": "One sentence string explaining what happened after making changes such as fixing bugs/additions.",
2769+
"files_touched": [
2770+
"hooks/install.sh",
2771+
"hooks/post-commit"
2772+
]
27492773
}
27502774
]
27512775
}

0 commit comments

Comments
 (0)