我正在编写一个自动脚本.
在某些时候,我在打电话git clone <repo>.但是这个操作有可能已经完成.
git clone --no-fail如果存储库存在,我如何调用它以忽略它?
谢谢
hir*_*oga 29
它使存储库成为最新的。
git -C "$TARGET_DIR" pull || git clone https://github.com/<repo>.git "$TARGET_DIR"
Run Code Online (Sandbox Code Playgroud)
hek*_*mgl 22
最稳定的解决方案就是让它失败.
你可以这样做:
folder="foo"
if ! git clone "${url}" "${folder}" 2>/dev/null && [ -d "${folder}" ] ; then
echo "Clone failed because the folder ${folder} exists"
fi
Run Code Online (Sandbox Code Playgroud)
但这很容易受到竞争条件的影响.
spa*_*erj 10
聚会晚了一点,但我正在做类似的事情,但我想确保如果回购协议已经存在,请及时更新,以便在回购协议已经存在的情况下扩展上述答案,然后可以拉动以确保它是最新的。
if [ ! -d "$FOLDER" ] ; then
git clone $URL $FOLDER
else
cd "$FOLDER"
git pull $URL
fi
Run Code Online (Sandbox Code Playgroud)
git clone $url || true将使 shell 在set -e失败后运行并不会git clone失败。
如果这不是您想要的,那么建议的对已经存在的目标目录进行显式测试的解决方案应该可以工作。
它们唯一的问题是你需要模拟 Git 的方法来找出它的名字。
这样的事情应该工作:
url=git://host/path/name.git
last=${url##*/}
bare=${last%%.git}
test -e "$bare" || git clone "$url"
Run Code Online (Sandbox Code Playgroud)
这些“招数”以##和%%为的POSIX壳的“参数扩展”规则标准featues。
git clone如果克隆已经存在,则没有避免克隆的选项。你最好的选择是:
[ ! -d 'MyRepo' ] && git clone https://github.com/Myorg/MyRepo.git
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12532 次 |
| 最近记录: |