支持非 Git 部署目录滚动更新
This commit is contained in:
+26
-4
@@ -14,6 +14,7 @@ ASSUME_YES=0
|
|||||||
SKIP_BACKUP=0
|
SKIP_BACKUP=0
|
||||||
SKIP_DIRTY_CHECK=0
|
SKIP_DIRTY_CHECK=0
|
||||||
FORCE_PULL=0
|
FORCE_PULL=0
|
||||||
|
BOOTSTRAP_GIT_REPO=0
|
||||||
INSTALL_ARGS=()
|
INSTALL_ARGS=()
|
||||||
|
|
||||||
# 项目身份验证标识文件(至少需要其中 2 个)
|
# 项目身份验证标识文件(至少需要其中 2 个)
|
||||||
@@ -158,8 +159,22 @@ check_git_installed() {
|
|||||||
command -v git >/dev/null 2>&1 || ctms_fail "未检测到 git 命令,请先安装 Git"
|
command -v git >/dev/null 2>&1 || ctms_fail "未检测到 git 命令,请先安装 Git"
|
||||||
}
|
}
|
||||||
|
|
||||||
check_is_git_repo() {
|
detect_git_repository() {
|
||||||
git rev-parse --git-dir >/dev/null 2>&1 || ctms_fail "当前目录不是 Git 仓库"
|
if git rev-parse --git-dir >/dev/null 2>&1 && git rev-parse --verify HEAD >/dev/null 2>&1; then
|
||||||
|
BOOTSTRAP_GIT_REPO=0
|
||||||
|
else
|
||||||
|
BOOTSTRAP_GIT_REPO=1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
initialize_git_repository() {
|
||||||
|
[[ "$BOOTSTRAP_GIT_REPO" -eq 1 ]] || return 0
|
||||||
|
|
||||||
|
ctms_step "接管现有部署目录"
|
||||||
|
if [[ ! -d "$CTMS_ROOT_DIR/.git" ]]; then
|
||||||
|
git init "$CTMS_ROOT_DIR" >/dev/null 2>&1 || ctms_fail "初始化 Git 仓库失败"
|
||||||
|
fi
|
||||||
|
ctms_ok "已初始化 Git 仓库,准备同步远程代码"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_current_branch() {
|
get_current_branch() {
|
||||||
@@ -568,8 +583,14 @@ main() {
|
|||||||
cd "$CTMS_ROOT_DIR"
|
cd "$CTMS_ROOT_DIR"
|
||||||
|
|
||||||
check_git_installed
|
check_git_installed
|
||||||
check_is_git_repo
|
detect_git_repository
|
||||||
check_working_directory
|
if [[ "$BOOTSTRAP_GIT_REPO" -eq 1 ]]; then
|
||||||
|
ctms_warn "部署目录缺少可用的 Git 历史,将从指定仓库接管现有部署"
|
||||||
|
# 必须先确认这是 CTMS 目录,避免在任意目录中初始化并覆盖文件。
|
||||||
|
verify_project_identity
|
||||||
|
else
|
||||||
|
check_working_directory
|
||||||
|
fi
|
||||||
resolve_repo_url
|
resolve_repo_url
|
||||||
setup_git_credentials
|
setup_git_credentials
|
||||||
pick_remote_ref
|
pick_remote_ref
|
||||||
@@ -577,6 +598,7 @@ main() {
|
|||||||
|
|
||||||
# 先验证当前项目身份
|
# 先验证当前项目身份
|
||||||
verify_project_identity
|
verify_project_identity
|
||||||
|
initialize_git_repository
|
||||||
|
|
||||||
# 创建备份
|
# 创建备份
|
||||||
create_backup_tag
|
create_backup_tag
|
||||||
|
|||||||
Reference in New Issue
Block a user