feat: update git credential

This commit is contained in:
2026-06-26 11:10:23 +08:00
parent 84c7f37c53
commit 9551225ee9
7 changed files with 66 additions and 33 deletions
+6
View File
@@ -123,6 +123,12 @@
[http]
sslVerify = false
# 凭据:统一 wrapper,不依赖 includeIf ondarwin/onlinux(需 Git 2.36+)
# 低版本 Git 也会加载本节;回退为 git-credential-store(~/.git-credentials)
[credential]
helper = ~/.dotfile/git/git-credential.sh
# 以下 includeIf 需 Git 2.36+;仅用于其它平台差异配置(若有)
[includeIf "ondarwin"]
path = ~/.dotfile/git/.gitconfig.darwin
[includeIf "onlinux"]
+2 -2
View File
@@ -1,2 +1,2 @@
[credential]
helper = osxkeychain
# macOS 专用 Git 配置(可选扩展;凭据见主配置 git-credential.sh)
# 需要 Git 2.36+ 的 includeIf ondarwin 才会加载本文件
+2 -3
View File
@@ -1,3 +1,2 @@
# 凭据:优先 libsecret(见 git-credential-linux.sh),未安装则 cache + 提示
[credential]
helper = ~/.dotfile/git/git-credential-linux.sh
# Linux 专用 Git 配置(可选扩展;凭据见主配置 git-credential.sh)
# 需要 Git 2.36+ 的 includeIf onlinux 才会加载本文件
+2 -24
View File
@@ -1,25 +1,3 @@
#!/bin/bash
# Linux 凭据 helper:优先 libsecret,否则回退 cache 并提示安装
set -euo pipefail
warn_missing_libsecret() {
local marker="${XDG_CACHE_HOME:-$HOME/.cache}/git-credential-linux.warned"
[[ -f "$marker" ]] && return 0
mkdir -p "$(dirname "$marker")"
touch "$marker"
cat >&2 <<'EOF'
提示: 未找到 git-credential-libsecret,当前使用内存缓存(默认 1 周过期或登出后失效)。
安装持久化凭据存储:
Debian/Ubuntu: sudo apt install libsecret-1-0 git-credential-libsecret
Fedora/RHEL: sudo dnf install git-credential-libsecret
Arch Linux: sudo pacman -S libsecret git
EOF
}
if command -v git-credential-libsecret >/dev/null 2>&1; then
exec git-credential-libsecret "$@"
fi
warn_missing_libsecret
exec git-credential-cache --timeout=604800 "$@"
# 已合并到 git-credential.sh;保留此文件仅为兼容旧配置引用
exec "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/git-credential.sh" "$@"
+43
View File
@@ -0,0 +1,43 @@
#!/bin/bash
# 跨平台 Git 凭据 helper(不依赖 includeIf ondarwin/onlinux,兼容 Git < 2.36)
# macOS: osxkeychain → store
# Linux: libsecret → store
set -euo pipefail
warn_store_fallback() {
local reason="$1"
local marker="${XDG_CACHE_HOME:-$HOME/.cache}/git-credential-store.warned"
[[ -f "$marker" ]] && return 0
mkdir -p "$(dirname "$marker")"
touch "$marker"
cat >&2 <<EOF
提示: Git 凭据使用 store 明文保存到 ~/.git-credentials(${reason})。
建议:
macOS: 通常可用 osxkeychain(Keychain)
Linux: sudo apt install libsecret-1-0 git-credential-libsecret
请确保 ~/.git-credentials 权限为 600。
EOF
}
case "$(uname -s)" in
Darwin)
if command -v git-credential-osxkeychain >/dev/null 2>&1; then
exec git-credential-osxkeychain "$@"
fi
warn_store_fallback "未找到 osxkeychain"
exec git-credential-store "$@"
;;
Linux)
if command -v git-credential-libsecret >/dev/null 2>&1; then
exec git-credential-libsecret "$@"
fi
warn_store_fallback "未找到 git-credential-libsecret"
exec git-credential-store "$@"
;;
*)
warn_store_fallback "未知系统 $(uname -s)"
exec git-credential-store "$@"
;;
esac