Spot pain points in your code through git history
Track frequently changing files that might need attention
echo "\033[36m⚡ Finding most frequently changed files...\033[0m"
result=$(git log --since="6 months ago" --name-only --pretty="format:" | \
grep -v "^$" | \
sort | \
uniq -c | \
sort -rn | \
head -10 | \
awk '{printf " %d changes: %s\n", $1, $2}')
if [ -z "$result" ]; then
echo "\033[33mNo hotspots found matching your criteria\033[0m"
else
count=$(echo "$result" | wc -l | tr -d ' ')
echo "\033[32mFound $count hotspots:\033[0m"
echo "$result" | awk '{printf "%s%s%s\n", "\033[1m", $0, "\033[0m"}'
fi
Find files with high activity but few contributors
echo "\033[36m🏰 Initializing dungeon search...\033[0m"
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir')
trap 'rm -rf "$tmpdir"' EXIT
echo "\033[34m📊 Analyzing change patterns...\033[0m"
git log --since="6 months ago" --name-only --pretty="format:" | \
grep -v "^$" | \
sort | \
uniq -c | \
sort -rn | \
awk '$1 >= 5 {print $1, $2}' > "$tmpdir/files"
if [ ! -s "$tmpdir/files" ]; then
echo "\033[33mNo files found matching your criteria\033[0m"
exit 0
fi
echo "\033[34m👥 Analyzing author patterns...\033[0m"
found_dungeons=0
while IFS= read -r line; do
changes=$(echo "$line" | awk '{print $1}')
file=$(echo "$line" | awk '{print $2}')
[ ! -f "$file" ] && continue
author_count=$(git log --follow --since="6 months ago" --pretty="format:%an" -- "$file" | sort -u | \
sort | \
uniq | \
wc -l | \
tr -d '[:space:]')
if [ "$author_count" -le 2 ]; then
found_dungeons=$((found_dungeons + 1))
if [ "$found_dungeons" -le 10 ]; then
echo "\n\033[35mDungeon found: \033[1m$file\033[0m"
echo "\033[36mChanges in last 6 months: \033[1m$changes\033[0m"
echo "\033[36mAuthors:\033[0m"
git log --follow --since="6 months ago" --pretty="format:%an" -- "$file" | sort | uniq -c | sort -nr | \
awk '{
count=$1
author=$2
for(i=3;i<=NF;i++) author=author " " $i
printf " %s%s: %d changes%s\n", "\033[1m", author, count, "\033[0m"
}'
fi
fi
done < "$tmpdir/files"
if [ "$found_dungeons" -eq 0 ]; then
echo "\033[33mNo dungeons found matching your criteria\033[0m"
else
echo "\n\033[32mFound $found_dungeons dungeons in total\033[0m"
fi
Find files that frequently change together with other files
echo "\033[36m🧲 Initializing dependency analysis...\033[0m"
tmpdir=$(mktemp -d 2>/dev/null || mktemp -d -t 'tmpdir')
trap 'rm -rf "$tmpdir"' EXIT
get_related_files() {
local target_file="$1"
echo "\033[2mFinding commits for $target_file...\033[0m" >&2
local target_commits=$(git log --follow --since="6 months ago" --pretty="format:%H" -- "$target_file")
echo "\033[2mAnalyzing co-changes...\033[0m" >&2
echo "$target_commits" | while read -r commit; do
git diff-tree --no-commit-id --name-only -r $commit | grep -v "^$target_file$"
done | \
grep -v "^$" | \
sort | \
uniq -c | \
sort -rn | \
head -5 | \
tee "$tmpdir/cochanges_${target_file//\//_}" | \
awk '{printf " %s%d co-changes: %s%s\n", "\033[1m", $1, $2, "\033[0m"}'
}
get_total_cochanges() {
local file="$1"
awk '{sum += $1} END {print sum}' "$tmpdir/cochanges_${file//\//_}" 2>/dev/null || echo 0
}
echo "\033[34m🔍 Finding frequently coupled files...\033[0m"
git log --since="6 months ago" --name-only --pretty="format:" | \
grep -v "^$" | \
grep -v "^[a-f0-9]\{7,\}$" | \
sort | \
uniq -c | \
sort -rn | \
awk '$1 >= 3 {print $2}' > "$tmpdir/candidates"
if [ ! -s "$tmpdir/candidates" ]; then
echo "\033[33mNo dependency magnets found matching your criteria\033[0m"
exit 0
fi
echo "\033[34m📊 Analyzing dependencies...\033[0m"
# First pass: collect co-changes data
while IFS= read -r file; do
[ ! -f "$file" ] && continue
get_related_files "$file" >/dev/null
done < "$tmpdir/candidates"
echo "\033[34m🔍 Analyzing results...\033[0m"
found_magnets=0
while IFS= read -r file; do
[ ! -f "$file" ] && continue
total_cochanges=$(get_total_cochanges "$file")
echo "$total_cochanges $file"
done < "$tmpdir/candidates" | \
sort -rn | \
head -10 | \
while IFS= read -r line; do
file=$(echo "$line" | cut -d' ' -f2-)
total=$(echo "$line" | cut -d' ' -f1)
found_magnets=$((found_magnets + 1))
echo "\n\033[35mDependency Magnet: \033[1m$file\033[0m"
echo "\033[36mTotal co-changes: \033[1m$total\033[0m"
echo "\033[36mRelated files:\033[0m"
cat "$tmpdir/cochanges_${file//\//_}"
done
if [ "$found_magnets" -eq 0 ]; then
echo "\033[33mNo dependency magnets found matching your criteria\033[0m"
else
echo "\n\033[32mFound $found_magnets dependency magnets with highest coupling\033[0m"
fi