-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from rupert648/rupert/symlink-pre-commit-fix
added pre-commit hook to commit actual files instead of symlinks
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,19 @@ | ||
#!/bin/bash | ||
# Save as .git/hooks/pre-commit and make executable | ||
|
||
# Find all symlinks that are tracked by git | ||
git ls-files -s | grep ^120000 | cut -f2 | while read -r file; do | ||
if [ -L "$file" ]; then | ||
target=$(readlink -f "$file") # -f follows the link recursively | ||
if [ -d "$target" ]; then | ||
# Handle directory | ||
rm "$file" | ||
cp -rL "$target" "$file" # -r for recursive, -L to follow symlinks | ||
else | ||
# Handle regular file | ||
rm "$file" | ||
cp -L "$target" "$file" | ||
fi | ||
git add "$file" | ||
fi | ||
done |