如何检查 homebrew-core 是否是 bash 脚本中的浅克隆?
How can I check if homebrew-core is a shallow clone in a bash script?
我如何在 bash 脚本中检查当前 homebrew-core
和 homebrew-cask
是否是浅层克隆,如果是则取消浅层克隆?如果他们已经不浅了,我也想打印一条消息。
运行 git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
在已经非浅层克隆上只给出错误消息而不是优雅处理。
我试过了
if [[ "git rev-parse --is-shallow-repository /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" == "false" ]]
then
echo "homebrew core is already non shallow. Moving to next step."
else
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
fi
但是得到了
fatal: --unshallow on a complete repository does not make sense
你可以使用像
这样的东西
$ for d in homebrew-core homebrew-cask
do
(cd /usr/local/Homebrew/Library/Taps/homebrew/$d && git rev-parse --is-shallow-repository)
done
如果 repo 很浅,它将打印 true
或 false
。
这似乎有效
if [[ "git rev-parse --is-shallow-repository /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core | grep -q 'false'" ]]
then
echo "homebrew core is already non shallow. Moving to next step."
else
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
fi
我如何在 bash 脚本中检查当前 homebrew-core
和 homebrew-cask
是否是浅层克隆,如果是则取消浅层克隆?如果他们已经不浅了,我也想打印一条消息。
运行 git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask" fetch --unshallow
在已经非浅层克隆上只给出错误消息而不是优雅处理。
我试过了
if [[ "git rev-parse --is-shallow-repository /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" == "false" ]]
then
echo "homebrew core is already non shallow. Moving to next step."
else
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
fi
但是得到了
fatal: --unshallow on a complete repository does not make sense
你可以使用像
这样的东西$ for d in homebrew-core homebrew-cask
do
(cd /usr/local/Homebrew/Library/Taps/homebrew/$d && git rev-parse --is-shallow-repository)
done
如果 repo 很浅,它将打印 true
或 false
。
这似乎有效
if [[ "git rev-parse --is-shallow-repository /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core | grep -q 'false'" ]]
then
echo "homebrew core is already non shallow. Moving to next step."
else
git -C "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core" fetch --unshallow
fi