feat(flow): more cases for sync check

This commit is contained in:
2025-11-07 19:06:49 +02:00
parent 2fdf72d746
commit 5972c3c5df

View File

@@ -286,33 +286,43 @@ cmd_enter() {
cmd_sync_check() { cmd_sync_check() {
local base_dir="$HOME/projects" local base_dir="$HOME/projects"
local -a needs_action=() local -a needs_action=()
local -a not_git=()
for repo in "$base_dir"/*; do for repo in "$base_dir"/*; do
[ -d "$repo" ] || continue
local git_dir="$repo/.git" local git_dir="$repo/.git"
if [ -e "$git_dir" ]; then
echo "=== $(basename "$repo") ==="
# Disable immediate exit inside the conditional block if [ ! -d "$git_dir" ]; then
if ( not_git+=("$(basename "$repo")")
cd "$repo" || exit 1 continue
fi
echo "=== $(basename "$repo") ==="
cd "$repo" || continue
local action_required=0 local action_required=0
git fetch --all --quiet || true git fetch --all --quiet || true
local branch
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD")
# Uncommitted changes # --- Uncommitted or untracked changes ---
if ! git diff --quiet || ! git diff --cached --quiet; then if ! git diff --quiet || ! git diff --cached --quiet; then
echo "Uncommitted changes:" echo "Uncommitted changes:"
git status --short git status --short
action_required=1 action_required=1
elif [ -n "$(git ls-files --others --exclude-standard)" ]; then
echo "Untracked files:"
git ls-files --others --exclude-standard
action_required=1
else else
echo "No uncommitted changes." echo "No uncommitted or untracked changes."
fi fi
branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "HEAD") # --- Unpushed commits on current branch ---
# Unpushed commits
if git rev-parse --abbrev-ref "${branch}@{u}" >/dev/null 2>&1; then if git rev-parse --abbrev-ref "${branch}@{u}" >/dev/null 2>&1; then
unpushed=$(git log --oneline "${branch}@{u}..${branch}") local unpushed
unpushed=$(git rev-list --oneline "${branch}@{u}..${branch}")
if [ -n "$unpushed" ]; then if [ -n "$unpushed" ]; then
echo "Unpushed commits on ${branch}:" echo "Unpushed commits on ${branch}:"
echo "$unpushed" echo "$unpushed"
@@ -325,11 +335,11 @@ cmd_sync_check() {
action_required=1 action_required=1
fi fi
# Unpushed branches # --- Unpushed branches ---
branches=$(git for-each-ref --format='%(refname:short)' refs/heads) local unpushed_branches=()
unpushed_branches=() while IFS= read -r b; do
for b in $branches; do
if git rev-parse --abbrev-ref "${b}@{u}" >/dev/null 2>&1; then if git rev-parse --abbrev-ref "${b}@{u}" >/dev/null 2>&1; then
local ahead
ahead=$(git rev-list --count "${b}@{u}..${b}") ahead=$(git rev-list --count "${b}@{u}..${b}")
if [ "$ahead" -gt 0 ]; then if [ "$ahead" -gt 0 ]; then
unpushed_branches+=("$b ($ahead ahead)") unpushed_branches+=("$b ($ahead ahead)")
@@ -337,7 +347,7 @@ cmd_sync_check() {
else else
unpushed_branches+=("$b (no upstream)") unpushed_branches+=("$b (no upstream)")
fi fi
done done < <(git for-each-ref --format='%(refname:short)' refs/heads)
if [ "${#unpushed_branches[@]}" -gt 0 ]; then if [ "${#unpushed_branches[@]}" -gt 0 ]; then
echo "Unpushed branches:" echo "Unpushed branches:"
@@ -348,13 +358,7 @@ cmd_sync_check() {
fi fi
echo echo
exit "$action_required" ((action_required)) && needs_action+=("$(basename "$repo")")
); then
:
else
needs_action+=("$(basename "$repo")")
fi
fi
done done
echo "=== SUMMARY ===" echo "=== SUMMARY ==="
@@ -364,6 +368,12 @@ cmd_sync_check() {
else else
echo "All repositories clean and synced." echo "All repositories clean and synced."
fi fi
if [ "${#not_git[@]}" -gt 0 ]; then
echo
echo "Directories without Git repositories:"
printf ' %s\n' "${not_git[@]}" | sort -u
fi
} }
# shellcheck disable=SC2154,SC2155 # shellcheck disable=SC2154,SC2155