2 Commits

Author SHA1 Message Date
laily 2dedb9573c fix: invoke git credential helpers via absolute path
Apple Git osxkeychain exclusive-locks argv[0]. A relative name looks in
cwd and fails with "failed to lock git-credential-osxkeychain".
2026-09-08 11:39:25 +08:00
laily dc302bff1c fix: fail mise-install when curl pipeline errors
Do not print success after a failed curl | sh install; enable pipefail and verify mise is on PATH before continuing.
2026-09-08 11:34:46 +08:00
2 changed files with 39 additions and 13 deletions
+26 -9
View File
@@ -21,23 +21,40 @@ warn_store_fallback() {
EOF EOF
} }
# helper 在 `git --exec-path`,不一定在 PATH。必须 exec 绝对路径:
# Apple Git 的 osxkeychain 会对 argv[0] 做 O_EXLOCK,相对名会去锁 cwd 下的同名文件。
dotfile_git_credential_exec() {
local name="$1"
shift
local helper=""
local exec_path
exec_path="$(git --exec-path 2>/dev/null || true)"
if [ -n "$exec_path" ] && [ -x "$exec_path/git-credential-$name" ]; then
helper="$exec_path/git-credential-$name"
elif command -v "git-credential-$name" >/dev/null 2>&1; then
helper="$(command -v "git-credential-$name")"
else
return 1
fi
exec "$helper" "$@"
}
case "$(uname -s)" in case "$(uname -s)" in
Darwin) Darwin)
if command -v git-credential-osxkeychain >/dev/null 2>&1; then dotfile_git_credential_exec osxkeychain "$@" || true
exec git-credential-osxkeychain "$@"
fi
warn_store_fallback "未找到 osxkeychain" warn_store_fallback "未找到 osxkeychain"
exec git-credential-store "$@" dotfile_git_credential_exec store "$@" || true
;; ;;
Linux) Linux)
if command -v git-credential-libsecret >/dev/null 2>&1; then dotfile_git_credential_exec libsecret "$@" || true
exec git-credential-libsecret "$@"
fi
warn_store_fallback "未找到 git-credential-libsecret" warn_store_fallback "未找到 git-credential-libsecret"
exec git-credential-store "$@" dotfile_git_credential_exec store "$@" || true
;; ;;
*) *)
warn_store_fallback "未知系统 $(uname -s)" warn_store_fallback "未知系统 $(uname -s)"
exec git-credential-store "$@" dotfile_git_credential_exec store "$@" || true
;; ;;
esac esac
echo "git credential helper 不可用" >&2
exit 1
+13 -4
View File
@@ -20,18 +20,28 @@ EOF
dotfile_help_requested "${1:-}" && dotfile_show_help dotfile_help_requested "${1:-}" && dotfile_show_help
set -e set -euo pipefail
GREEN='\033[0;32m' GREEN='\033[0;32m'
RED='\033[0;31m' RED='\033[0;31m'
YELLOW='\033[1;33m' YELLOW='\033[1;33m'
NC='\033[0m' NC='\033[0m'
mise_fail() {
echo -e "${RED}mise 安装失败,请检查错误信息${NC}" >&2
exit 1
}
if ! command -v mise &>/dev/null; then if ! command -v mise &>/dev/null; then
echo -e "${YELLOW}mise 未安装. 正在安装 mise...${NC}" echo -e "${YELLOW}mise 未安装. 正在安装 mise...${NC}"
curl https://mise.run | sh # 无 pipefail 时 curl 失败 sh 仍可能退出 0,会误报「安装完成」
curl -fL --retry 3 https://mise.run | sh || mise_fail
export PATH="$HOME/.local/bin:$PATH" export PATH="$HOME/.local/bin:$PATH"
if ! command -v mise &>/dev/null; then
mise_fail
fi
if [ -f ~/.config/fish/config.fish ]; then if [ -f ~/.config/fish/config.fish ]; then
if ! grep -q "mise activate" ~/.config/fish/config.fish; then if ! grep -q "mise activate" ~/.config/fish/config.fish; then
echo -e "${YELLOW}正在为 fish shell 配置 mise...${NC}" echo -e "${YELLOW}正在为 fish shell 配置 mise...${NC}"
@@ -72,6 +82,5 @@ fi
if command -v mise &>/dev/null; then if command -v mise &>/dev/null; then
echo -e "${GREEN}mise 安装成功!${NC}" echo -e "${GREEN}mise 安装成功!${NC}"
else else
echo -e "${RED}mise 安装失败,请检查错误信息${NC}" mise_fail
exit 1
fi fi