From 7f80be1f317d427cb8e3b09eb35eedd545066d34 Mon Sep 17 00:00:00 2001 From: Niklas Kapelle Date: Wed, 28 Feb 2024 23:28:06 +0100 Subject: [PATCH] added git-unpushed script --- .local/share/scripts/git-unpushed.sh | 57 ++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 .local/share/scripts/git-unpushed.sh diff --git a/.local/share/scripts/git-unpushed.sh b/.local/share/scripts/git-unpushed.sh new file mode 100755 index 0000000..6b3cdce --- /dev/null +++ b/.local/share/scripts/git-unpushed.sh @@ -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"