Skip to content
Merged
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
59 changes: 59 additions & 0 deletions .git-hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
#
# GLOBAL PRE-COMMIT HOOK with CHAINING to repo's own .git/hooks/pre-commit
#

# Detect repo root; empty if not in a Git repo
repo_root="$(git rev-parse --show-toplevel 2> /dev/null)"

if [[ -z "$repo_root" ]]; then
# Not a Git repo — do nothing
exit 0
fi

# Current branch
branch="$(git rev-parse --abbrev-ref HEAD 2> /dev/null || echo "")"

# If in detached HEAD (rebasing, etc.), do nothing
if [[ "$branch" == "HEAD" || -z "$branch" ]]; then
:
else
# Determine primary (default) branch of the repo dynamically
# Determine default remote, prefer origin
default_remote="$(git config --get core.defaultRemote)"
if [[ -z "$default_remote" ]]; then
default_remote="origin"
fi

# Try to find remote HEAD reference, e.g. refs/remotes/origin/main
remote_head_ref="$(git symbolic-ref -q "refs/remotes/$default_remote/HEAD" 2> /dev/null || true)"

if [[ -n "$remote_head_ref" ]]; then
# Extract branch name from refs/remotes/origin/main
default_branch="${remote_head_ref#refs/remotes/$default_remote/}"
else
# Fallback to init.defaultBranch or 'main'
default_branch="$(git config --get init.defaultBranch)"
if [[ -z "$default_branch" ]]; then
default_branch="main"
fi
fi

# Block commits on primary branch
if [[ "$branch" == "$default_branch" ]]; then
echo "🚫 Stop‼ Don't commit on the primary branch '$branch' - Use a feature branch!"
echo " Detected default remote '$default_remote' & primary branch '$default_branch'"
exit 1
fi
fi

# Chain to repo-specific pre-commit hook if it exists
local_hook="$repo_root/.git/hooks/pre-commit"

# Avoid infinite recursion: skip if this hook *is* the local hook
if [[ -x "$local_hook" && "$0" != "$local_hook" ]]; then
echo "🔗 Chaining to local pre-commit hook at '$local_hook'"
exec "$local_hook"
fi

exit 0
1 change: 1 addition & 0 deletions .gitconfig
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
# bdone = "!f() { git checkout ${1-master} && git up && git bclean ${1-master}; }; f"
[core]
excludesfile = /home/praco/.gitignore
hooksPath = /Users/racop/.git-hooks
[user]
name = Patrick Raco
email = patrick.raco@autodesk.com
Expand Down
26 changes: 13 additions & 13 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SRC_REPO="$HOME/repos/pataraco/dot_files"
# 1. Installs Homebrew
# 2. Installs the Homebrew packages in the Brewfile
# 3. Moves existing dot files in $HOME to $HOME/.orig
# 4. Set up symlinks from $HOME to the files in the $SRC_REPO
# 4. Set up symlinks from $HOME to the files/dirs in the $SRC_REPO
# (excluding this script, the .git directory and the README file, etc.)
#
# some other manual steps
Expand Down Expand Up @@ -70,23 +70,23 @@ fi

# get list of files to process and create symlinks
# shellcheck disable=SC2010
for file in $(ls -1d .[a-z]* | grep -wv .git); do
echo -n "processing: $file... "
if [ -f "$file" ]; then # source file is a regular file, create link
if [ -L "$HOME/$file" ]; then # existing symlink
for file_or_dir in $(ls -1d .[a-z]* | grep -wv ".git/"); do
echo -n "processing: $file_or_dir... "
if [[ -f "$file_or_dir" ]] || [[ -d $file_or_dir ]]; then # source is a regular file or directory
if [ -L "$HOME/$file_or_dir" ]; then # existing symlink
echo -n "removing existing symlink... "
rm -f "$HOME/$file"
elif [ -f "$HOME/$file" ]; then # existing file
echo -n "saving original file... "
mv "$HOME/$file" "$ORIG_DIR"
rm -f "$HOME/$file_or_dir"
elif [[ -f "$HOME/$file_or_dir" ]] || [[ -d "$HOME/$file_or_dir" ]]; then # existing file/dir
echo -n "saving original file/directory... "
mv "$HOME/$file_or_dir" "$ORIG_DIR"
files_saved=true
else # not found
echo -n "existing file/symlink not found..."
echo -n "existing file/directory/symlink not found..."
fi
echo -n "creating symlink... "
ln -s "$SRC_REPO/$file" "$HOME/$file"
else # source file is not a regular file, don't link
echo -n "not a regular file, not creating symlink... "
ln -s "$SRC_REPO/$file_or_dir" "$HOME/$file_or_dir"
else # source file/dir is not a regular file or directory, don't link
echo -n "not a regular file or directory, not creating symlink... "
fi
echo "done"
done
Expand Down
2 changes: 1 addition & 1 deletion starship.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ahead = "[⇡$count](bold fg:color_bright_green bg:color_indigo)"
behind = "[⇣$count](bold fg:color_bright_yellow bg:color_indigo)"
diverged = "[⇕$count](bold fg:color_bright_purple bg:color_indigo)"
untracked = "[?$count](bold fg:color_bright_orange bg:color_indigo)"
stashed = '[$\$count](bold fg:color_bright_blue bg:color_indigo)'
stashed = '[\$$count](bold fg:color_bright_blue bg:color_indigo)'
modified = "[!$count](bold fg:color_bright_yellow bg:color_indigo)"
staged = "[+$count](bold fg:color_bright_green bg:color_indigo)"
renamed = "[»$count](bold fg:color_bright_purple bg:color_indigo)"
Expand Down