feat(flow): more cases for sync check
This commit is contained in:
parent
2fdf72d746
commit
5972c3c5df
@ -286,75 +286,79 @@ 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
|
||||||
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
|
|
||||||
fi
|
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
|
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
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user