added git-unpushed script
This commit is contained in:
parent
dc75f8b062
commit
7f80be1f31
57
.local/share/scripts/git-unpushed.sh
Executable file
57
.local/share/scripts/git-unpushed.sh
Executable file
@ -0,0 +1,57 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
# Thanks ChatGPT
|
||||||
|
|
||||||
|
# Define your projects directory
|
||||||
|
PROJECTS_DIR="$HOME/projects/"
|
||||||
|
|
||||||
|
# Counter for total directories checked
|
||||||
|
total_dirs_checked=0
|
||||||
|
|
||||||
|
# Counter for projects with unpushed commits
|
||||||
|
unpushed_projects=0
|
||||||
|
|
||||||
|
# Change directory to your projects directory
|
||||||
|
cd "$PROJECTS_DIR" || { echo "Directory not found"; exit 1; }
|
||||||
|
|
||||||
|
# Loop through each subdirectory
|
||||||
|
for dir in */; do
|
||||||
|
# Increment the total directories counter
|
||||||
|
((total_dirs_checked++))
|
||||||
|
|
||||||
|
# Move into the project directory
|
||||||
|
cd "$dir" || continue
|
||||||
|
|
||||||
|
# Check if it's a git repository
|
||||||
|
if [ -d ".git" ]; then
|
||||||
|
# Get the name of the current branch, silencing errors
|
||||||
|
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
|
||||||
|
|
||||||
|
# Check if the command failed or if it's not a branch
|
||||||
|
if [ $? -ne 0 ] || [ -z "$current_branch" ]; then
|
||||||
|
cd ..
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Check if the branch has an upstream set
|
||||||
|
if [ -z "$(git rev-parse --abbrev-ref --symbolic-full-name "$current_branch@{u}" 2>/dev/null)" ]; then
|
||||||
|
#echo "No upstream set for $current_branch in $dir"
|
||||||
|
true # Hack cus i am lazy
|
||||||
|
else
|
||||||
|
# Check if there are unpushed commits
|
||||||
|
if [ "$(git rev-list --count HEAD..."$current_branch"@{u})" -gt 0 ]; then
|
||||||
|
echo "There are unpushed commits in $dir"
|
||||||
|
((unpushed_projects++))
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Move back to the parent directory
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
# Output the total number of directories checked
|
||||||
|
echo "Total directories checked: $total_dirs_checked"
|
||||||
|
|
||||||
|
# Output the number of projects with unpushed commits
|
||||||
|
echo "Projects with unpushed commits: $unpushed_projects"
|
Loading…
Reference in New Issue
Block a user