Update 2025-04-13_18:28:34
This commit is contained in:
@ -5,17 +5,6 @@
|
|||||||
# Set variables
|
# Set variables
|
||||||
# ========
|
# ========
|
||||||
|
|
||||||
# Ensure Git user identity is configured
|
|
||||||
log DEBUG "Checking Git user configuration..."
|
|
||||||
if ! git config --global user.name >/dev/null 2>&1; then
|
|
||||||
git config --global user.name "$(whoami)"
|
|
||||||
log DEBUG "Set Git user.name to $(whoami)"
|
|
||||||
fi
|
|
||||||
if ! git config --global user.email >/dev/null 2>&1; then
|
|
||||||
git config --global user.email "$(whoami)@$(hostname -f)"
|
|
||||||
log DEBUG "Set Git user.email to $(whoami)@$(hostname -f)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to extract GITEA_API_TOKEN from ~/.gitea_token if not set
|
# Try to extract GITEA_API_TOKEN from ~/.gitea_token if not set
|
||||||
if [ -z "$GITEA_API_TOKEN" ] && [ -f "$HOME/.gitea_token" ]; then
|
if [ -z "$GITEA_API_TOKEN" ] && [ -f "$HOME/.gitea_token" ]; then
|
||||||
GITEA_API_TOKEN=$(<"$HOME/.gitea_token")
|
GITEA_API_TOKEN=$(<"$HOME/.gitea_token")
|
||||||
@ -47,7 +36,10 @@ log() {
|
|||||||
local color_reset="$(tput sgr0)"
|
local color_reset="$(tput sgr0)"
|
||||||
local color=""
|
local color=""
|
||||||
case "$level" in
|
case "$level" in
|
||||||
INFO) color="$(tput setaf 2)" ;; # green
|
INFO) color="$(tput setaf 6)" ;; # cyan (was green)
|
||||||
|
WARNING) color="$(tput setaf 3)" ;; # yellow
|
||||||
|
ERROR) color="$(tput setaf 1)" ;; # red
|
||||||
|
DEBUG) color="$(tput bold; tput setaf 4)" ;; # bold blue # green
|
||||||
WARNING) color="$(tput setaf 3)" ;; # yellow
|
WARNING) color="$(tput setaf 3)" ;; # yellow
|
||||||
ERROR) color="$(tput setaf 1)" ;; # red
|
ERROR) color="$(tput setaf 1)" ;; # red
|
||||||
DEBUG) color="$(tput setaf 4)" ;; # blue
|
DEBUG) color="$(tput setaf 4)" ;; # blue
|
||||||
@ -77,10 +69,12 @@ create_repo() {
|
|||||||
|
|
||||||
prepare_commit() {
|
prepare_commit() {
|
||||||
git add .
|
git add .
|
||||||
if git diff --quiet HEAD && ! git rev-parse --verify HEAD >/dev/null 2>&1; then
|
git diff --quiet HEAD
|
||||||
|
HAS_CHANGES=$?
|
||||||
|
if [ $HAS_CHANGES -eq 1 ] && ! git rev-parse --verify HEAD >/dev/null 2>&1; then
|
||||||
log INFO "Creating initial commit"
|
log INFO "Creating initial commit"
|
||||||
git commit -m "$COMMIT_MESSAGE"
|
git commit -m "$COMMIT_MESSAGE"
|
||||||
elif ! git diff --quiet HEAD; then
|
elif [ $HAS_CHANGES -eq 1 ]; then
|
||||||
log INFO "Committing changes"
|
log INFO "Committing changes"
|
||||||
git commit -m "$COMMIT_MESSAGE"
|
git commit -m "$COMMIT_MESSAGE"
|
||||||
else
|
else
|
||||||
@ -192,6 +186,22 @@ check_or_create_repo
|
|||||||
# Main Process
|
# Main Process
|
||||||
# ========
|
# ========
|
||||||
|
|
||||||
|
# Ensure Git user identity is configured
|
||||||
|
log DEBUG "Checking Git user configuration..."
|
||||||
|
if ! git config user.name >/dev/null 2>&1; then
|
||||||
|
git config --global user.name "$(whoami)"
|
||||||
|
log DEBUG "Set Git user.name to $(whoami)"
|
||||||
|
else
|
||||||
|
log DEBUG "Git user.name already set to $(git config --show-origin user.name)"
|
||||||
|
fi
|
||||||
|
if ! git config user.email >/dev/null 2>&1; then
|
||||||
|
git config --global user.email "$(whoami)@$(hostname -f)"
|
||||||
|
log DEBUG "Set Git user.email to $(whoami)@$(hostname -f)"
|
||||||
|
else
|
||||||
|
log DEBUG "Git user.email already set to $(git config --show-origin user.email)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Safety check against pushing from / or $HOME
|
# Safety check against pushing from / or $HOME
|
||||||
if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then
|
if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then
|
||||||
log ERROR "Refusing to run inside \$PWD=$PWD"
|
log ERROR "Refusing to run inside \$PWD=$PWD"
|
||||||
|
Reference in New Issue
Block a user