1 Star 0 Fork 0

正版水民/tunasync-scripts

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
git-worktree.sh 1.65 KB
一键复制 编辑 原始数据 按行查看 历史
Zenithal 提交于 2023-04-11 15:11 . git-worktree: handle upstream force push
#!/bin/bash
set -e
git_option="git -c [email protected] -c user.name=Noname"
function repo_init() {
UPSTREAM="$1"
WORKING_DIR="$2"
git clone "$UPSTREAM" "$WORKING_DIR"
}
function update_git() {
UPSTREAM="$1"
repo_dir="$2"
cd "$repo_dir"
echo "==== SYNC $repo_dir START ===="
git remote set-url origin "$UPSTREAM"
timeout -s INT 3600 git remote -v update -p
head=$(git remote show origin | awk '/HEAD branch:/ {print $NF}')
[[ -n "$head" ]] && echo "ref: refs/heads/$head" > HEAD
objs=$(find objects -type f | wc -l)
[[ "$objs" -gt 8 ]] && git repack -a -b -d
sz=$(git count-objects -v|grep -Po '(?<=size-pack: )\d+')
total_size=$(($total_size+1024*$sz))
echo "==== SYNC $repo_dir DONE ===="
}
function checkout_branch() {
repo_dir="$1"
work_tree="$2"
branch="$3"
echo "Checkout branch $branch to $work_tree"
if [[ ! -d "$2" ]]; then
$git_option clone "$repo_dir" --branch "$branch" --single-branch "$work_tree"
else
cd "$work_tree"
$git_option checkout -B "$branch" "origin/$branch"
fi
}
UPSTREAM_BASE=${TUNASYNC_UPSTREAM_URL}
UPSTREAM_BRANCH=${UPSTREAM_BRANCH:-"master"}
total_size=0
if [[ ! -d "$TUNASYNC_WORKING_DIR/.git" ]]; then
echo "Initializing"
repo_init "${UPSTREAM_BASE}" "$TUNASYNC_WORKING_DIR"
fi
update_git "${UPSTREAM_BASE}" "$TUNASYNC_WORKING_DIR/.git"
checkout_branch "$TUNASYNC_WORKING_DIR/.git" "$TUNASYNC_WORKING_DIR" "$UPSTREAM_BRANCH"
echo "Total size is" $(numfmt --to=iec $total_size)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wyk0930/tunasync-scripts.git
[email protected]:wyk0930/tunasync-scripts.git
wyk0930
tunasync-scripts
tunasync-scripts
master

搜索帮助