主题与企微

This commit is contained in:
super committed 2026-03-29 00:57:37 +08:00
1 parent 20271ada61
commit 514c3d01be
3 files changed
+161 -1

No files matched your search

+154
View File
@@ -427,6 +427,148 @@ show_non_system_open_ports() {
print_group "其它服务" "${f_other}"
}
show_local_changes_detail() {
echo "=== 本地改动详情(相对上游分支 @{u}) ==="
if ! git -C "${ROOT_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "当前目录不是 Git 仓库。"
return 1
fi
local branch upstream
branch="$(git -C "${ROOT_DIR}" rev-parse --abbrev-ref HEAD)"
upstream="$(git -C "${ROOT_DIR}" rev-parse --abbrev-ref --symbolic-full-name '@{u}' 2>/dev/null || true)"
if [[ -z "${upstream}" ]]; then
echo "当前分支 ${branch} 未设置上游分支,无法执行: git diff --stat @{u}.."
echo "可先执行: git branch --set-upstream-to origin/${branch} ${branch}"
return 1
fi
echo "当前分支: ${branch}"
echo "上游分支: ${upstream}"
echo ""
echo "== 统计(git diff --stat @{u}..) =="
git -C "${ROOT_DIR}" -c color.ui=always diff --stat --color=always '@{u}..' || true
local tracked_files
tracked_files="$(git -C "${ROOT_DIR}" diff --name-only '@{u}..' || true)"
if [[ -z "${tracked_files}" ]]; then
echo ""
echo "当前相对 ${upstream} 没有改动。"
return 0
fi
echo ""
echo "== 文件改动内容(彩色) =="
while IFS= read -r f; do
[[ -z "${f}" ]] && continue
echo ""
echo "---- ${f} ----"
git -C "${ROOT_DIR}" -c color.ui=always diff --color=always '@{u}..' -- "${f}" || true
done <<< "${tracked_files}"
}
show_remote_branch_changes_detail() {
echo "=== 远端分支改动详情(仅远端新增) ==="
if ! git -C "${ROOT_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "当前目录不是 Git 仓库。"
return 1
fi
local current_branch target_branch remote_ref
current_branch="$(git -C "${ROOT_DIR}" rev-parse --abbrev-ref HEAD)"
read -r -p "请输入远端分支名(默认 ${current_branch}): " target_branch
target_branch="${target_branch:-${current_branch}}"
remote_ref="origin/${target_branch}"
if ! git -C "${ROOT_DIR}" fetch origin "${target_branch}" --prune >/dev/null 2>&1; then
echo "警告: 拉取 origin/${target_branch} 失败,尝试使用本地已缓存的远端引用继续。"
fi
if ! git -C "${ROOT_DIR}" show-ref --verify --quiet "refs/remotes/${remote_ref}"; then
echo "未找到本地远端引用 ${remote_ref}。"
echo "请先确认分支存在,或手动执行: git fetch origin ${target_branch}"
return 1
fi
local remote_numstat remote_files
remote_numstat="$(git -C "${ROOT_DIR}" diff --numstat HEAD..${remote_ref} || true)"
remote_files="$(git -C "${ROOT_DIR}" diff --name-only HEAD..${remote_ref} || true)"
if [[ -z "${remote_files}" ]]; then
echo "远端分支相对本地 HEAD 没有新增改动。"
return 0
fi
echo "== 远端相对本地的文件与行数统计 =="
printf "%-10s %-10s %s\n" "ADDED" "DELETED" "FILE"
printf "%-10s %-10s %s\n" "----------" "----------" "------------------------------"
echo "${remote_numstat}" | awk '{printf "%-10s %-10s %s\n", $1, $2, $3}'
echo ""
echo "== 远端新增提交(HEAD..${remote_ref}) =="
git -C "${ROOT_DIR}" log --oneline --decorate HEAD..${remote_ref} | sed -n '1,200p'
echo ""
echo "== 远端每个文件改动内容(HEAD..${remote_ref}) =="
while IFS= read -r f; do
[[ -z "${f}" ]] && continue
echo ""
echo "---- ${f} ----"
git -C "${ROOT_DIR}" diff --no-color HEAD..${remote_ref} -- "${f}" || true
done <<< "${remote_files}"
}
show_local_remote_compare() {
echo "=== 本地与远端差异对比(直观) ==="
if ! git -C "${ROOT_DIR}" rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "当前目录不是 Git 仓库。"
return 1
fi
local current_branch target_branch remote_ref
current_branch="$(git -C "${ROOT_DIR}" rev-parse --abbrev-ref HEAD)"
read -r -p "请输入远端分支名(默认 ${current_branch}): " target_branch
target_branch="${target_branch:-${current_branch}}"
remote_ref="origin/${target_branch}"
if ! git -C "${ROOT_DIR}" fetch origin "${target_branch}" --prune >/dev/null 2>&1; then
echo "警告: 拉取 origin/${target_branch} 失败,尝试使用本地已缓存的远端引用继续。"
fi
if ! git -C "${ROOT_DIR}" show-ref --verify --quiet "refs/remotes/${remote_ref}"; then
echo "未找到本地远端引用 ${remote_ref}。"
echo "请先确认分支存在,或手动执行: git fetch origin ${target_branch}"
return 1
fi
local ahead behind
read -r ahead behind < <(git -C "${ROOT_DIR}" rev-list --left-right --count HEAD...${remote_ref})
echo "对比分支: HEAD vs ${remote_ref}"
echo "本地领先: ${ahead} 个提交"
echo "远端领先: ${behind} 个提交"
echo ""
echo "== 本地独有提交(${remote_ref}..HEAD) =="
git -C "${ROOT_DIR}" log --oneline --decorate "${remote_ref}..HEAD" | sed -n '1,120p'
echo ""
echo "== 远端独有提交(HEAD..${remote_ref}) =="
git -C "${ROOT_DIR}" log --oneline --decorate "HEAD..${remote_ref}" | sed -n '1,120p'
echo ""
echo "== 双向文件统计(git diff --stat HEAD...${remote_ref}) =="
git -C "${ROOT_DIR}" diff --stat HEAD..."${remote_ref}" || true
echo ""
echo "== 本地相对远端的改动(${remote_ref}..HEAD) =="
git -C "${ROOT_DIR}" diff --stat "${remote_ref}..HEAD" || true
echo ""
echo "== 远端相对本地的改动(HEAD..${remote_ref}) =="
git -C "${ROOT_DIR}" diff --stat "HEAD..${remote_ref}" || true
}
show_help() {
cat <<'HELP'
可输入的指令与结果:
@@ -436,6 +578,9 @@ show_help() {
status或 4 -> 查看服务运行状态
ports 或 5 -> 扫描当前用户开启的开发服务端口
allports或 6 -> 扫描所有非系统监听端口(应用/自装服务)
localchg或 31 -> 查看本地改了哪些文件/多少行/逐文件改动
remotechg或 32 -> 只查看远端分支改了哪些文件/多少行/逐文件改动
compare 或 33 -> 直观对比本地与远端差异(领先提交、双向改动)
help -> 再次显示本帮助
exit 或 0 -> 退出脚本
HELP
@@ -479,6 +624,15 @@ main_loop() {
6|allports)
show_non_system_open_ports
;;
31|localchg)
show_local_changes_detail
;;
32|remotechg)
show_remote_branch_changes_detail
;;
33|compare)
show_local_remote_compare
;;
help)
show_help
;;