Files
gitea-cli/scripts/tag.sh
timmy faee15bc78 Initial commit
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-21 13:04:09 +08:00

57 lines
1.1 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# shellcheck source=lib/common.sh
source "${SCRIPT_DIR}/lib/common.sh"
usage() {
cat >&2 <<'EOF'
Usage: tag.sh <tag> [-m "message"]
建立 annotated tag 並推到 origin。
需要在 cwd 已有 git repo 且 origin 已指到 Gitea。
EOF
exit 1
}
[[ $# -ge 1 ]] || usage
TAG=""
MSG=""
while [[ $# -gt 0 ]]; do
case "$1" in
-m) [[ $# -ge 2 ]] || { log_err "-m 需要一個值"; exit 1; }; MSG="$2"; shift 2 ;;
-h|--help) usage ;;
-*) log_err "未知參數:$1"; usage ;;
*)
if [[ -z "$TAG" ]]; then TAG="$1"; else log_err "多餘參數:$1"; usage; fi
shift ;;
esac
done
[[ -n "$TAG" ]] || usage
MSG="${MSG:-Tag $TAG}"
load_config
if ! git rev-parse --git-dir >/dev/null 2>&1; then
log_err "cwd 不是 git repo"
exit 1
fi
if git rev-parse "$TAG" >/dev/null 2>&1; then
log_err "tag 已存在:${TAG}"
exit 1
fi
log_info "建立 tag ${TAG}"
git tag -a "$TAG" -m "$MSG"
log_info "推送 tag 到 origin"
git_push_tag_with_token "$TAG"
log_done "完成"
echo "$TAG"