aboutsummaryrefslogtreecommitdiff
path: root/zsh/functions/sync-repos.zsh
diff options
context:
space:
mode:
authorRuben Beltran del Rio <git@r.bdr.sh>2024-12-18 21:26:19 +0100
committerRuben Beltran del Rio <git@r.bdr.sh>2024-12-18 21:26:19 +0100
commitfe17fef03f8c2bb44f0c2dc8f2185db6f33145f4 (patch)
tree160fb08c5d4be5384528cafe07dfbe990413c779 /zsh/functions/sync-repos.zsh
parentf3e9f5c17a6ba27ae5715a566b1454031f5a10da (diff)
Add repo sync functionality
Diffstat (limited to 'zsh/functions/sync-repos.zsh')
-rw-r--r--zsh/functions/sync-repos.zsh52
1 files changed, 52 insertions, 0 deletions
diff --git a/zsh/functions/sync-repos.zsh b/zsh/functions/sync-repos.zsh
new file mode 100644
index 0000000..fdc0876
--- /dev/null
+++ b/zsh/functions/sync-repos.zsh
@@ -0,0 +1,52 @@
+#!/usr/bin/env zsh
+
+# Function to check and process git repositories
+sync-repo() {
+ local repo_path="$1"
+ local relative_path="${repo_path#$PWD/}"
+
+ pushd "$repo_path"
+
+ print -n "${relative_path}: "
+
+ local remotes=($(git remote))
+
+ if [[ ${#remotes[@]} -eq 0 ]]; then
+ print -P "%F{red}NO REMOTES%f"
+ popd
+ return
+ fi
+
+ # Check for required remotes
+ local has_origin=0
+ local has_conchos=0
+ local existing_remotes=""
+
+ for remote in $remotes; do
+ [[ $remote == "origin" ]] && has_origin=1
+ [[ $remote == "conchos" ]] && has_conchos=1
+ existing_remotes="${existing_remotes:+$existing_remotes,}$remote"
+ done
+
+ # If missing any required remote
+ if [[ $has_origin -eq 0 || $has_conchos -eq 0 ]]; then
+ print -P "%F{yellow}MISSING REMOTES ${existing_remotes}%f"
+ popd
+ return
+ fi
+
+ # Try pushing to both remotes
+ if git push --all origin >/dev/null 2>&1 && git push --all conchos >/dev/null 2>&1; then
+ print -P "%F{green}UPDATED%f"
+ else
+ print -P "%F{red}OUTDATED%f"
+ fi
+ popd
+}
+
+sync-repos() {
+ local start_dir="${1:-.}"
+ fd -H -t d '^\.git$' -x echo {} | sort | sed 's/\/\.git$//' | rg -v "${SYNC_REPOS_IGNORE}" | while read -r repo_path; do
+ sync-repo "$repo_path"
+ done
+}