feat(flow): more cases for sync check

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

View File

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