From 1f5954390b638e05b9c531fe5258cbb5281ac67f Mon Sep 17 00:00:00 2001 From: root Date: Sun, 13 Apr 2025 17:35:58 +0200 Subject: [PATCH] Update 2025-04-13_17:35:58 --- gitea_push.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/gitea_push.sh b/gitea_push.sh index 0bca28e..217433d 100755 --- a/gitea_push.sh +++ b/gitea_push.sh @@ -1,10 +1,21 @@ #!/bin/zsh -# Script Version: 1.5 +# Script Version: 1.6 # Description: Pushes the current folder (e.g. /etc) to a nested Gitea repo using provided nesting arguments. Auto-creates the remote repo via Gitea API if missing. # 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 if [ -z "$GITEA_API_TOKEN" ] && [ -f "$HOME/.gitea_token" ]; then GITEA_API_TOKEN=$(<"$HOME/.gitea_token") @@ -197,6 +208,12 @@ if [ ! -d .git ]; then git config init.defaultBranch main git checkout -b main else + CURRENT_BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) + if [ "$CURRENT_BRANCH" != "main" ]; then + log WARNING "Current branch is '$CURRENT_BRANCH', renaming to 'main'" + git branch -m main + fi + log DEBUG ".git directory already present" log DEBUG ".git directory already present" fi