-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgit-info.sh
executable file
·54 lines (41 loc) · 1.99 KB
/
git-info.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
while [[ $# -gt 0 ]]; do
case "$1" in
*)
printf "\e[31mUnknown option: $1\e[0m\n"
exit 1
;;
esac
done
if ! command -v git &> /dev/null; then
printf "\e[31mError: 'git' is not installed. Please install it first.\e[0m\n"
exit 1
fi
git_repositories=$(find . -maxdepth 2 -type d -name '.git')
if [ -z "$git_repositories" ]; then
printf "\e[33mNo Git repositories found in the specified directory.\e[0m\n"
exit 0
fi
printf -- "──────────────────────────────────────────────────────────────────\n"
echo "$git_repositories" | while read git_dir; do
(
repo_name=$(dirname "$git_dir")
cd "$repo_name" || exit
if [ "$repo_name" = "." ]; then
printf "Repository: \e[1;32m${PWD##*/}\e[0m\n"
else
printf "Repository: \e[1;32m$(basename "$repo_name")\e[0m\n"
fi
branch_count=$(git branch -a | grep -v 'remotes' | wc -l | tr -d '[:space:]')
printf "Total branches: $branch_count\n"
printf "Branches: "
# git branch -a | grep -v 'remotes' | sed -n 's/^\* //p; 2,$s/^/ /p'
git branch -a | grep -v 'remotes' | awk '{sub(/^\* /, ""); if (NR==1) print $0; else printf "%-18s%s\n", "", $0}'
printf "Authors/committers: "
# git log --format='%an <%ae>' | sort -u | sed '1!s/^/ /' | sed '2,$s/^/ /'
git log --format='%an <%ae>' | sort -u | awk 'NR==1{print $0} NR>1{printf "%-20s%s\n", "", $0}'
commit_count=$(git rev-list --all --count)
printf "Total commits: $commit_count\n"
printf -- "──────────────────────────────────────────────────────────────────\n"
)
done