我需要检查 git push
命令是否真的会在 bash 脚本中推送某些内容。我无法使用退出代码,因为成功推送和“不需要推送”的情况下它都为零。
这是我目前的解决方法,但它可能不是很优雅。
# some code that does things with a repo
# check whether push is necessary
push_output=$(git push origin "$BRANCH" --dry-run 2>&1)
if [[ "$push_output" == "Everything up-to-date" ]]; then
echo "no push necessary."
# do something
else
# do something else
fi
# more code here