feat(flow): add git sync command
This commit is contained in:
parent
7b72fa6796
commit
9db467735f
@ -21,6 +21,11 @@ SPEC=(
|
||||
"argument;ssh-args;type:rest;dest:ssh_args;help:Additional SSH arguments (after --)"
|
||||
"end"
|
||||
|
||||
"command;sync;Git tools"
|
||||
"command;check;Check all projects status"
|
||||
"end"
|
||||
"end"
|
||||
|
||||
"command;create;Create and start a new development container"
|
||||
"argument;image,i;required;type:option;help:Container image to use (with optional tag)"
|
||||
"argument;project,p;type:option;help:Path to local project directory"
|
||||
@ -220,6 +225,90 @@ cmd_enter() {
|
||||
exec "${ssh_cmd[@]}"
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2154,SC2155
|
||||
cmd_sync_check() {
|
||||
local base_dir="$HOME/projects"
|
||||
local -a needs_action=()
|
||||
|
||||
for repo in "$base_dir"/*; do
|
||||
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
|
||||
fi
|
||||
done
|
||||
|
||||
echo "=== SUMMARY ==="
|
||||
if [ "${#needs_action[@]}" -gt 0 ]; then
|
||||
echo "Projects needing action:"
|
||||
printf ' %s\n' "${needs_action[@]}" | sort -u
|
||||
else
|
||||
echo "All repositories clean and synced."
|
||||
fi
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2154,SC2155
|
||||
cmd_create() {
|
||||
# VARS: name_arg, image_arg, project_arg
|
||||
|
||||
Loading…
Reference in New Issue
Block a user