]>
Commit | Line | Data |
---|---|---|
fe17fef0 RBR |
1 | #!/usr/bin/env zsh |
2 | ||
3 | # Function to check and process git repositories | |
4 | sync-repo() { | |
5 | local repo_path="$1" | |
6 | local relative_path="${repo_path#$PWD/}" | |
7 | ||
8 | pushd "$repo_path" | |
9 | ||
10 | print -n "${relative_path}: " | |
11 | ||
12 | local remotes=($(git remote)) | |
13 | ||
14 | if [[ ${#remotes[@]} -eq 0 ]]; then | |
15 | print -P "%F{red}NO REMOTES%f" | |
16 | popd | |
17 | return | |
18 | fi | |
19 | ||
20 | # Check for required remotes | |
21 | local has_origin=0 | |
22 | local has_conchos=0 | |
23 | local existing_remotes="" | |
24 | ||
25 | for remote in $remotes; do | |
26 | [[ $remote == "origin" ]] && has_origin=1 | |
27 | [[ $remote == "conchos" ]] && has_conchos=1 | |
28 | existing_remotes="${existing_remotes:+$existing_remotes,}$remote" | |
29 | done | |
30 | ||
31 | # If missing any required remote | |
32 | if [[ $has_origin -eq 0 || $has_conchos -eq 0 ]]; then | |
33 | print -P "%F{yellow}MISSING REMOTES ${existing_remotes}%f" | |
34 | popd | |
35 | return | |
36 | fi | |
37 | ||
38 | # Try pushing to both remotes | |
39 | if git push --all origin >/dev/null 2>&1 && git push --all conchos >/dev/null 2>&1; then | |
40 | print -P "%F{green}UPDATED%f" | |
41 | else | |
42 | print -P "%F{red}OUTDATED%f" | |
43 | fi | |
44 | popd | |
45 | } | |
46 | ||
47 | sync-repos() { | |
48 | local start_dir="${1:-.}" | |
49 | fd -H -t d '^\.git$' -x echo {} | sort | sed 's/\/\.git$//' | rg -v "${SYNC_REPOS_IGNORE}" | while read -r repo_path; do | |
50 | sync-repo "$repo_path" | |
51 | done | |
52 | } |