Files
gitea-cli/scripts/clone.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

49 lines
1.0 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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: clone.sh <repo> [target-dir]
<repo> GITEA_USER 名下的 repo 名稱
[target-dir] clone 目的地(預設 ./<repo>
EOF
exit 1
}
[[ $# -ge 1 && $# -le 2 ]] || usage
case "$1" in
-h|--help) usage ;;
esac
REPO="$1"
TARGET="${2:-./${REPO}}"
if [[ -e "$TARGET" ]]; then
# 空目錄 OK其他情況拒絕
if [[ -d "$TARGET" ]]; then
if [[ -n "$(ls -A "$TARGET")" ]]; then
log_err "目標目錄已存在且非空:${TARGET}"
exit 1
fi
else
log_err "目標路徑已存在且不是目錄:${TARGET}"
exit 1
fi
fi
load_config
CLEAN_URL="${GITEA_URL}/${GITEA_USER}/${REPO}.git"
log_info "clone ${GITEA_USER}/${REPO}${TARGET}"
git_clone_with_token "$CLEAN_URL" "$TARGET"
ABS="$(cd "$TARGET" && pwd)"
log_done "完成"
echo "$ABS"