feat: Add push command to automate pushing changes to all remotes

This commit is contained in:
Menno van Leeuwen 2024-08-27 20:52:24 +02:00
parent a087ffe7b0
commit 63a1948551
Signed by: vleeuwenmenno
SSH Key Fingerprint: SHA256:OJFmjANpakwD3F2Rsws4GLtbdz1TJ5tkQF0RZmF0TRE
2 changed files with 37 additions and 0 deletions

29
bin/actions/push.sh Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env zsh
source $HOME/dotfiles/bin/helpers/functions.sh
# Push all changes from $HOME/dotfiles to ALL remotes in $HOME/dotfiles/.git/config
push_all() {
# Get all remotes from the .git/config file
remotes=($(cat $HOME/dotfiles/.git/config | grep url | awk '{print $3}'))
printfe "%s\n" "cyan" "Pushing all changes to all remotes..."
# For each remote, push all changes
for remote in $remotes; do
printfe "%s" "green" " - Pushing to ["
printfe "%s" "blue" "$remote"
printfe "%s\n" "green" "]..."
result=$(git -C $HOME/dotfiles push $remote 2>&1)
# If the push failed, print an error
if [ $? -ne 0 ]; then
printfe "%s\n" "red" " - Failed to push to $remote:"
printfe "%s\n" "red" " $result"
continue
fi
done
}
push_all

View File

@ -23,6 +23,10 @@ secrets() {
$HOME/dotfiles/bin/actions/secrets.sh $@
}
push() {
$HOME/dotfiles/bin/actions/push.sh $@
}
ensure_git_hooks() {
# If ~/dotfiles/.git/hooks is a symlink, skip this
if [[ -L ~/dotfiles/.git/hooks ]]; then
@ -50,6 +54,10 @@ case $1 in
logo
update $@
;;
"push")
logo continue
push $@
;;
"status")
logo continue
status $@