Update 2025-04-17_20:44:56
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
#!/bin/zsh
|
||||
# Script Version: 1.5
|
||||
# Script Version: 19
|
||||
# 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
|
||||
@ -36,11 +36,11 @@ log() {
|
||||
local color_reset="$(tput sgr0)"
|
||||
local color=""
|
||||
case "$level" in
|
||||
INFO) color="$(tput setaf 2)" ;; # green
|
||||
WARNING) color="$(tput setaf 3)" ;; # yellow
|
||||
ERROR) color="$(tput setaf 1)" ;; # red
|
||||
DEBUG) color="$(tput setaf 4)" ;; # blue
|
||||
esac
|
||||
INFO) color="$(tput setaf 6)" ;; # cyan
|
||||
WARNING) color="$(tput setaf 3)" ;; # yellow
|
||||
ERROR) color="$(tput setaf 1)" ;; # red
|
||||
DEBUG) color="$(tput bold; tput setaf 4)" ;; # bold blue
|
||||
esac
|
||||
echo "${color}[$level] $*${color_reset}"
|
||||
}
|
||||
|
||||
@ -66,17 +66,11 @@ create_repo() {
|
||||
|
||||
prepare_commit() {
|
||||
git add .
|
||||
if git diff --quiet HEAD && ! git rev-parse --verify HEAD >/dev/null 2>&1; then
|
||||
log INFO "Creating initial commit"
|
||||
git commit -m "$COMMIT_MESSAGE"
|
||||
elif ! git diff --quiet HEAD; then
|
||||
log INFO "Committing changes"
|
||||
git commit -m "$COMMIT_MESSAGE"
|
||||
else
|
||||
log INFO "Nothing to commit"
|
||||
fi
|
||||
log INFO "Committing changes"
|
||||
git commit -m "$COMMIT_MESSAGE" || log INFO "Nothing to commit"
|
||||
}
|
||||
|
||||
|
||||
setup_remote() {
|
||||
if git remote | grep -q '^origin$'; then
|
||||
log INFO "Updating remote origin URL"
|
||||
@ -181,6 +175,59 @@ check_or_create_repo
|
||||
# Main Process
|
||||
# ========
|
||||
|
||||
# Add safe.directory for current repo if needed
|
||||
if [ -n "$GIT_REMOTE" ]; then
|
||||
SAFE_DIR="$(pwd)"
|
||||
git config --global --add safe.directory "$SAFE_DIR"
|
||||
log DEBUG "Added safe.directory: $SAFE_DIR"
|
||||
fi
|
||||
|
||||
|
||||
# Create default .gitignore if not present
|
||||
if [ ! -f .gitignore ]; then
|
||||
log INFO "Creating default .gitignore"
|
||||
cat > .gitignore <<EOF
|
||||
# Bytecode-Dateien
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
|
||||
# Virtuelle Umgebungen
|
||||
.venv/
|
||||
venv/
|
||||
|
||||
# Betriebssystem-Dateien
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
# Logfiles und Dumps
|
||||
*.log
|
||||
*.bak
|
||||
*.swp
|
||||
*.tmp
|
||||
|
||||
# IDEs und Editoren
|
||||
.vscode/
|
||||
.idea/
|
||||
EOF
|
||||
fi
|
||||
|
||||
|
||||
# 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
|
||||
if [[ "$PWD" == "$HOME" || "$PWD" == "/" ]]; then
|
||||
log ERROR "Refusing to run inside \$PWD=$PWD"
|
||||
@ -197,10 +244,27 @@ 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'"
|
||||
if ! git rev-parse HEAD >/dev/null 2>&1; then
|
||||
git checkout -b main
|
||||
else
|
||||
git branch -m main
|
||||
fi
|
||||
fi
|
||||
log DEBUG ".git directory already present"
|
||||
fi
|
||||
|
||||
# Ensure at least one commit exists
|
||||
|
||||
# Create placeholder file if no untracked files exist
|
||||
if [ -z "$(git ls-files)" ]; then
|
||||
touch .gitkeep
|
||||
git add .gitkeep
|
||||
log DEBUG "Added .gitkeep to ensure initial commit"
|
||||
fi
|
||||
|
||||
prepare_commit
|
||||
|
||||
# Set or update remote
|
||||
|
Reference in New Issue
Block a user