# 变量默认值与传入赋值 no_local=false iftest"$1" = "--no-local"; then no_local=true shift fi # 变量默认值与传入赋值 srctree=. iftest$# -gt 0; then srctree=$1 shift fi # 检查脚本输入参数>0或者$srctree路径不存在 iftest$# -gt 0 -o ! -d "$srctree"; then usage fi
scm_version() { local short=false local no_dirty=false local tag
while [ $# -gt 0 ]; do case"$1"in --short) short=true;; --no-dirty) no_dirty=true;; esac shift done
cd"$srctree"
# 检查当前目录是否在一个 Git 仓库中。 iftest -n "$(git rev-parse --show-cdup 2>/dev/null)"; then return fi # 验证 Git 仓库的 HEAD 引用 if ! head=$(git rev-parse --verify HEAD 2>/dev/null); then return fi