diff --git a/deploy.sh b/deploy.sh index 0b9dded..7529882 100755 --- a/deploy.sh +++ b/deploy.sh @@ -4,15 +4,33 @@ set -euo pipefail PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$PROJECT_ROOT" -TARGET_BRANCH="${1:-$(git rev-parse --abbrev-ref HEAD)}" +resolve_default_branch() { + local current + current="$(git branch --show-current 2>/dev/null || true)" + if [[ -n "$current" ]]; then + echo "$current" + return + fi + + local remote_head + remote_head="$(git symbolic-ref --short refs/remotes/origin/HEAD 2>/dev/null || true)" + if [[ -n "$remote_head" ]]; then + echo "${remote_head#origin/}" + return + fi + + echo "main" +} + +TARGET_BRANCH="${1:-$(resolve_default_branch)}" echo "==> Deploy directory: $PROJECT_ROOT" echo "==> Target branch: $TARGET_BRANCH" if [[ -n "$(git status --porcelain)" ]]; then - echo "Error: working tree is not clean." - echo "Please commit/stash local changes before deployment." - exit 1 + STASH_NAME="auto-deploy-$(date +%Y%m%d-%H%M%S)" + echo "==> Working tree is not clean, auto stashing: $STASH_NAME" + git stash push -u -m "$STASH_NAME" >/dev/null fi echo "==> Fetching remote updates..."