Initial commit
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
48
scripts/clone.sh
Normal file
48
scripts/clone.sh
Normal file
@@ -0,0 +1,48 @@
|
||||
#!/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"
|
||||
Reference in New Issue
Block a user