diff --git a/git_repos_rebase_commit_push.sh b/git-work-safety-tools/git_repos_rebase_commit_push.sh similarity index 100% rename from git_repos_rebase_commit_push.sh rename to git-work-safety-tools/git_repos_rebase_commit_push.sh diff --git a/git_repos_status.sh b/git-work-safety-tools/git_repos_status.sh similarity index 100% rename from git_repos_status.sh rename to git-work-safety-tools/git_repos_status.sh diff --git a/git-work-safety-tools/multi_repo_interactive_fix.sh b/git-work-safety-tools/multi_repo_interactive_fix.sh new file mode 100644 index 0000000..eca9e64 --- /dev/null +++ b/git-work-safety-tools/multi_repo_interactive_fix.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +gitdirs=$(find . -type d -name ".git") + +for gitdir in $gitdirs; do + repo=$(dirname "$gitdir") + cd "$repo" || continue + echo -e "${CYAN}šŸ“ Repository: $repo${NC}" + + # Check status + uncommitted=$(git status --porcelain | wc -l | tr -d ' ') + git remote update > /dev/null 2>&1 + if git rev-parse --abbrev-ref --symbolic-full-name @{u} > /dev/null 2>&1; then + ahead=$(git rev-list --count @{u}..HEAD 2>/dev/null) + behind=$(git rev-list --count HEAD..@{u} 2>/dev/null) + else + ahead=0 + behind=0 + fi + + # Handle uncommitted changes + if [ "$uncommitted" -gt 0 ]; then + echo -e " ${YELLOW}You have $uncommitted uncommitted change(s).${NC}" + git status --short + echo " What do you want to do?" + select action in "Commit" "Stash" "Skip"; do + case $action in + Commit) + echo " Enter commit message:" + read msg + git add -A + git commit -m "$msg" + break + ;; + Stash) + git stash push -u -m "Interactive stash by script" + break + ;; + Skip) + echo " Skipping uncommitted changes." + break + ;; + esac + done + fi + + # Handle behind remote + if [ "$behind" -gt 0 ]; then + echo -e " ${YELLOW}Your branch is behind remote by $behind commit(s).${NC}" + echo " Do you want to pull (rebase) now? (y/n)" + read ans + if [[ "$ans" =~ ^[Yy]$ ]]; then + git pull --rebase + fi + fi + + # Handle unpushed commits + if [ "$ahead" -gt 0 ]; then + echo -e " ${YELLOW}You have $ahead local commit(s) not pushed to remote.${NC}" + echo " Do you want to push now? (y/n)" + read ans + if [[ "$ans" =~ ^[Yy]$ ]]; then + git push + fi + fi + + # Handle stashes + stash_count=$(git stash list | wc -l | tr -d ' ') + if [ "$stash_count" -gt 0 ]; then + echo -e " ${YELLOW}You have $stash_count stash(es). Do you want to pop the latest? (y/n)${NC}" + read ans + if [[ "$ans" =~ ^[Yy]$ ]]; then + git stash pop + fi + fi + + echo -e "${CYAN}──────────────────────────────────────────────${NC}" + cd - > /dev/null || exit +done \ No newline at end of file diff --git a/git-work-safety-tools/multi_repo_safe_push.sh b/git-work-safety-tools/multi_repo_safe_push.sh new file mode 100644 index 0000000..bf88c8c --- /dev/null +++ b/git-work-safety-tools/multi_repo_safe_push.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +CYAN='\033[0;36m' +NC='\033[0m' + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +printf "\n${CYAN}===== Initial Multi-Repo Status =====${NC}\n" +sh "$SCRIPT_DIR/multi_repo_status.sh" + +printf "\n${CYAN}===== Interactive Fixer =====${NC}\n" +sh "$SCRIPT_DIR/multi_repo_interactive_fix.sh" + +printf "\n${CYAN}===== Final Multi-Repo Status =====${NC}\n" +sh "$SCRIPT_DIR/multi_repo_status.sh" \ No newline at end of file diff --git a/git-work-safety-tools/multi_repo_status.sh b/git-work-safety-tools/multi_repo_status.sh new file mode 100644 index 0000000..bcf1df8 --- /dev/null +++ b/git-work-safety-tools/multi_repo_status.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +CYAN='\033[0;36m' +NC='\033[0m' # No Color + +gitdirs=$(find . -type d -name ".git") + +printf "\n${CYAN}šŸ“Š Multi-Repo Status Summary${NC}\n" +printf "${YELLOW}%-35s │ %-13s │ %-11s │ %-8s${NC}\n" "Repository" "šŸ—‚ļø Uncommitted" "ā¬†ļø Unpushed" "āš ļø Behind" +printf "%0.s─" {1..75}; printf "\n" + +total_uncommitted=0 +total_ahead=0 +total_behind=0 + +for gitdir in $gitdirs; do + repo=$(dirname "$gitdir") + cd "$repo" || continue + uncommitted=$(git status --porcelain | wc -l | tr -d ' ') + git remote update > /dev/null 2>&1 + if git rev-parse --abbrev-ref --symbolic-full-name @{u} > /dev/null 2>&1; then + ahead=$(git rev-list --count @{u}..HEAD 2>/dev/null) + behind=$(git rev-list --count HEAD..@{u} 2>/dev/null) + else + ahead=0 + behind=0 + fi + printf "%-35s │ %-13s │ %-11s │ %-8s\n" "$repo" "$uncommitted" "$ahead" "$behind" + total_uncommitted=$((total_uncommitted + uncommitted)) + total_ahead=$((total_ahead + ahead)) + total_behind=$((total_behind + behind)) + cd - > /dev/null || exit +done + +printf "%0.s─" {1..75}; printf "\n" +printf "${GREEN}🟢 Overall: ${NC}šŸ—‚ļø %d uncommitted file(s), ā¬†ļø %d unpushed commit(s), āš ļø %d behind remote\n" "$total_uncommitted" "$total_ahead" "$total_behind" \ No newline at end of file