Files
remoteconn-gitea/runit.sh
2026-03-21 18:57:10 +08:00

51 lines
883 B
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
set -euo pipefail
LOG_PREFIX="[${LOG_CONTEXT:-RUNIT}]"
if [ -t 1 ]; then
COLOR_RESET=$'\033[0m'
case "${LOG_CONTEXT:-RUNIT}" in
LOCAL)
COLOR_PREFIX=$'\033[1;32m'
;;
REMOTE)
COLOR_PREFIX=$'\033[1;94m'
;;
*)
COLOR_PREFIX=$'\033[1;33m'
;;
esac
else
COLOR_RESET=""
COLOR_PREFIX=""
fi
log() {
echo "${COLOR_PREFIX}${LOG_PREFIX}${COLOR_RESET} $*"
}
log "开始同步远端 main先 pull 再 push..."
git pull --rebase --autostash origin main
log "开始收集本地变更..."
git add -A
msg="update at $(date '+%Y-%m-%d %H:%M:%S')"
if [ $# -gt 0 ]; then
msg="$*"
fi
if git diff --cached --quiet; then
log "没有可提交变更,跳过 commit。"
else
log "开始提交:${msg}"
git commit -m "$msg"
fi
log "开始推送到 origin/main..."
git push origin main
log "runit.sh 执行完成。"