【发布时间】:2014-09-17 19:48:37
【问题描述】:
有时,我的“git ls-remote”语句会通过 HTTP 返回 401 Unauthorized 状态,但并非总是如此。如何在 Bash 中捕获此错误状态,以便在收到 HTTP 401 状态时不继续执行 Bash 脚本?
我正在这样做:
#!/bin/bash
GSERVER_STATUS=$(git ls-remote http://$GREMOTE/$GGROUP/$GREPO.git master | cut -f 1)
# rest of script goes here
大约 50% 的时间,它有效。剩下的 50%,我得到:
error: The requested URL returned error: 401 while accessing http://USER:PASS@SERVER/GROUP/REPO.git/info/refs
fatal: HTTP request failed
(当然,我更改了上面的行以保持我的登录凭据匿名。)
【问题讨论】:
标签: git bash error-handling error-code