ai-project-manage-cli 8.1.21 → 8.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env bash
2
+ # 特性分支相对基线是否有可合并改动(三方差异 base...head)。
3
+ # 用法: branch_has_changes.sh <base-branch> <head-branch>
4
+ # 退出码: 0 有改动;2 无改动;其它失败。
5
+ set -euo pipefail
6
+
7
+ base="${1:?用法: branch_has_changes.sh <base-branch> <head-branch>}"
8
+ head="${2:?用法: branch_has_changes.sh <base-branch> <head-branch>}"
9
+
10
+ base="${base#origin/}"
11
+ head="${head#origin/}"
12
+ # trim
13
+ base="${base#"${base%%[![:space:]]*}"}"
14
+ base="${base%"${base##*[![:space:]]}"}"
15
+ head="${head#"${head%%[![:space:]]*}"}"
16
+ head="${head%"${head##*[![:space:]]}"}"
17
+
18
+ if [[ -z "$base" || -z "$head" ]]; then
19
+ exit 2
20
+ fi
21
+
22
+ git fetch origin "$base"
23
+
24
+ head_ref="$head"
25
+ set +e
26
+ git fetch origin "$head" >/dev/null 2>&1
27
+ git rev-parse --verify "origin/${head}" >/dev/null 2>&1
28
+ fetch_ok=$?
29
+ set -e
30
+ if [[ $fetch_ok -eq 0 ]]; then
31
+ head_ref="origin/${head}"
32
+ else
33
+ git rev-parse --verify "$head" >/dev/null
34
+ fi
35
+
36
+ base_ref="origin/${base}"
37
+ ahead="$(git rev-list --count "${base_ref}..${head_ref}")"
38
+ if [[ "${ahead:-0}" -le 0 ]]; then
39
+ exit 2
40
+ fi
41
+
42
+ set +e
43
+ git diff --quiet "${base_ref}...${head_ref}"
44
+ diff_status=$?
45
+ set -e
46
+ # diff --quiet:无差异 0,有差异 1
47
+ if [[ $diff_status -eq 0 ]]; then
48
+ exit 2
49
+ fi
50
+ if [[ $diff_status -eq 1 ]]; then
51
+ exit 0
52
+ fi
53
+ exit "$diff_status"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ # 工作区有未提交变更时 git add -A && commit;无变更则跳过。
3
+ # 用法: commit_if_dirty.sh [commit-message]
4
+ # 退出码: 0 已提交;2 跳过(无变更);其它失败。
5
+ set -euo pipefail
6
+
7
+ message="${1:-}"
8
+
9
+ git rev-parse --git-dir >/dev/null
10
+
11
+ if [[ -z "$(git status --porcelain)" ]]; then
12
+ exit 2
13
+ fi
14
+
15
+ if [[ -z "$message" ]]; then
16
+ message="chore(apm): 同步工作区 ($(git rev-parse --abbrev-ref HEAD))"
17
+ fi
18
+
19
+ git add -A
20
+ git commit -m "$message"
21
+ echo "[apm] 已提交工作区变更: $message"
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ # 拉取并确认远程存在基线分支 origin/<baseline>。
3
+ # 用法: ensure_baseline.sh <baseline-branch>
4
+ # 退出码: 0 成功;其它失败。
5
+ set -euo pipefail
6
+
7
+ baseline="${1:?用法: ensure_baseline.sh <baseline-branch>}"
8
+
9
+ git fetch origin "$baseline"
10
+ if git ls-remote --heads origin "$baseline" | grep -q .; then
11
+ exit 0
12
+ fi
13
+
14
+ echo "[apm] 远程不存在基线分支 origin/${baseline},请确认仓库默认分支已推送到 origin" >&2
15
+ exit 1
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env bash
2
+ # 确保特性分支就绪:切到/创建 <branch>(基于 <baseline>),必要时补推远程。
3
+ # 用法: ensure_feature_branch.sh <branch> <baseline-branch>
4
+ # 退出码: 0 成功;其它失败。
5
+ set -euo pipefail
6
+
7
+ branch="${1:?用法: ensure_feature_branch.sh <branch> <baseline-branch>}"
8
+ baseline="${2:?用法: ensure_feature_branch.sh <branch> <baseline-branch>}"
9
+ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
10
+
11
+ git rev-parse --git-dir >/dev/null
12
+
13
+ current="$(git rev-parse --abbrev-ref HEAD)"
14
+ if [[ "$current" == "$branch" ]]; then
15
+ echo "[apm] 已在分支 ${branch}"
16
+ else
17
+ bash "$SCRIPT_DIR/ensure_baseline.sh" "$baseline"
18
+
19
+ if [[ -n "$(git status --porcelain)" ]]; then
20
+ git stash push -u -m "apm: switch to ${branch}"
21
+ fi
22
+
23
+ if git ls-remote --heads origin "$branch" | grep -q .; then
24
+ git fetch origin "$branch"
25
+ git checkout -B "$branch" "origin/${branch}"
26
+ elif git show-ref --verify --quiet "refs/heads/${branch}"; then
27
+ git checkout "$branch"
28
+ echo "[apm] 分支 ${branch} 已存在,跳过创建"
29
+ else
30
+ git fetch origin "$baseline"
31
+ set +e
32
+ git checkout --no-track -b "$branch" "origin/${baseline}"
33
+ create_status=$?
34
+ set -e
35
+ if [[ $create_status -ne 0 ]]; then
36
+ # 仅吞掉「并发创建导致本地已存在」
37
+ if git show-ref --verify --quiet "refs/heads/${branch}"; then
38
+ if [[ "$(git rev-parse --abbrev-ref HEAD)" != "$branch" ]]; then
39
+ git checkout "$branch"
40
+ fi
41
+ echo "[apm] 分支 ${branch} 已存在,跳过创建"
42
+ else
43
+ exit "$create_status"
44
+ fi
45
+ fi
46
+ fi
47
+ fi
48
+
49
+ # 本地已在目标分支时也要补推:上次 push 挂死/超时后常见「本地有、远端无」
50
+ if ! git ls-remote --heads origin "$branch" | grep -q .; then
51
+ echo "[apm] 远程尚无 ${branch},正在 push …"
52
+ bash "$SCRIPT_DIR/push_code.sh" "$branch"
53
+ fi
54
+
55
+ echo "[apm] 已就绪分支 ${branch}"
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+ # 推送当前仓库到 origin,并设置 upstream。
3
+ # 用法: push_code.sh [branch]
4
+ # 省略 branch 时推送 HEAD(等价于 git push -u origin HEAD)。
5
+ # 退出码: 0 已推送;2 跳过(非 git 仓 / 无 origin);其它失败。
6
+ set -euo pipefail
7
+
8
+ branch="${1:-HEAD}"
9
+
10
+ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
11
+ echo "[apm] 不是 git 仓库,跳过 push"
12
+ exit 2
13
+ fi
14
+
15
+ if ! git config --get remote.origin.url >/dev/null 2>&1; then
16
+ echo "[apm] 未配置 remote.origin,跳过 push"
17
+ exit 2
18
+ fi
19
+
20
+ # 显式 origin + -u:避免裸 git push 因 upstream 与当前分支名不一致失败
21
+ git push -u origin "$branch"