如果在执行 `git checkout $tag` 命令之前标签存在,我如何检查间隔循环?
How can I check in interval loop if the tags exist before doing the `git checkout $tag` command?
在 bash 脚本中,我正在等待特定的远程 git 标记被释放,然后再在我的脚本中使用它。
如果在执行 git checkout $tag
命令之前标签存在,我如何检查间隔循环?
例如:
while sleep 3; do git fetch && git rev-parse --verify <tag> && break; done
编辑
我创建了以下 bash 函数:
function wait_for_tag() {
tag=v${1#v}
interval=${2:-20}
while :; do
echo "Waiting for tag ${tag}..."
git remote update > /dev/null 2>&1
git rev-parse --verify --quiet "${tag}" && break
sleep ${interval}
done
}
function git_checkout() {
tag=v${1#v}
is_release && wait_for_tag "${tag}"
git checkout ${tag} || echo "testing"
npm install
}
我希望在执行 git_checkout v2.0.13-bs-redux-saga-router-dom-intl
时检查标签是否已存在,否则获取新标签并稍后重试。
这似乎在本地环境中工作得很好,但是当我在 Gitlab 中这样做时-CI,并行管道永远不会看到新标签,即使它们被标记并存在于 Gitlab UI.
如何确保 wait_for_tag
函数确实检索标签,为什么 git remote update
无法做到这一点?
您可以使用git rev-parse
来检查标签是否存在。像这样:
while :; do
git remote update
git rev-parse --verify --quiet SomeInterestingTag && break
# the tag did not exist
sleep 10
done
您可以使用git rev-parse
来检查标签是否存在:
git rev-parse -q --verify "refs/tags/$tag" >/dev/null
在你提到的一个循环中,结合 git checkout
它可能看起来像这样:
tag="foo"
while true; do
git fetch --all
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
git checkout "$tag" && break
fi
sleep 5
done
在这种情况下,您确实必须将 标签名称 作为 $tag
传递 - 没有提交散列或分支。
在 bash 脚本中,我正在等待特定的远程 git 标记被释放,然后再在我的脚本中使用它。
如果在执行 git checkout $tag
命令之前标签存在,我如何检查间隔循环?
例如:
while sleep 3; do git fetch && git rev-parse --verify <tag> && break; done
编辑
我创建了以下 bash 函数:
function wait_for_tag() {
tag=v${1#v}
interval=${2:-20}
while :; do
echo "Waiting for tag ${tag}..."
git remote update > /dev/null 2>&1
git rev-parse --verify --quiet "${tag}" && break
sleep ${interval}
done
}
function git_checkout() {
tag=v${1#v}
is_release && wait_for_tag "${tag}"
git checkout ${tag} || echo "testing"
npm install
}
我希望在执行 git_checkout v2.0.13-bs-redux-saga-router-dom-intl
时检查标签是否已存在,否则获取新标签并稍后重试。
这似乎在本地环境中工作得很好,但是当我在 Gitlab 中这样做时-CI,并行管道永远不会看到新标签,即使它们被标记并存在于 Gitlab UI.
如何确保 wait_for_tag
函数确实检索标签,为什么 git remote update
无法做到这一点?
您可以使用git rev-parse
来检查标签是否存在。像这样:
while :; do
git remote update
git rev-parse --verify --quiet SomeInterestingTag && break
# the tag did not exist
sleep 10
done
您可以使用git rev-parse
来检查标签是否存在:
git rev-parse -q --verify "refs/tags/$tag" >/dev/null
在你提到的一个循环中,结合 git checkout
它可能看起来像这样:
tag="foo"
while true; do
git fetch --all
if git rev-parse -q --verify "refs/tags/$tag" >/dev/null; then
git checkout "$tag" && break
fi
sleep 5
done
在这种情况下,您确实必须将 标签名称 作为 $tag
传递 - 没有提交散列或分支。