feat: update git credential
This commit is contained in:
@@ -60,8 +60,11 @@ ff reload # 重载 fish 配置
|
||||
|
||||
## Git 配置
|
||||
|
||||
- 公共配置在 `git/.gitconfig`;**按系统拆分**用 `includeIf ondarwin` / `onlinux`
|
||||
- Linux 凭据:`git/git-credential-linux.sh`(libsecret 优先,否则 cache)
|
||||
- 公共配置在 `git/.gitconfig`
|
||||
- **凭据**(所有 Git 版本):`git/git-credential.sh` 写在主配置里,不依赖 `includeIf ondarwin/onlinux`(需 Git 2.36+)
|
||||
- macOS:`osxkeychain` → 回退 `store`(`~/.git-credentials`)
|
||||
- Linux:`libsecret` → 回退 `store`
|
||||
- 平台扩展(可选):`git/.gitconfig.darwin` / `.gitconfig.linux` 仅在高版本 Git 下通过 includeIf 加载
|
||||
|
||||
## 边界(不要做的事)
|
||||
|
||||
|
||||
@@ -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"]
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
[credential]
|
||||
helper = osxkeychain
|
||||
# macOS 专用 Git 配置(可选扩展;凭据见主配置 git-credential.sh)
|
||||
# 需要 Git 2.36+ 的 includeIf ondarwin 才会加载本文件
|
||||
|
||||
@@ -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 才会加载本文件
|
||||
|
||||
@@ -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" "$@"
|
||||
|
||||
Executable
+43
@@ -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
|
||||
+6
-2
@@ -10,7 +10,9 @@ usage() {
|
||||
用法: git-init
|
||||
|
||||
备份已有 ~/.gitconfig,软链接到 ~/.dotfile/git/.gitconfig。
|
||||
同时为 git-credential-linux.sh 添加可执行权限。
|
||||
同时为 git-credential.sh 添加可执行权限。
|
||||
|
||||
凭据由 ~/.dotfile/git/git-credential.sh 处理(兼容 Git < 2.36,低版本回退 store)。
|
||||
|
||||
选项:
|
||||
-h, --help 显示此帮助
|
||||
@@ -28,4 +30,6 @@ if [ -f "$src" ]; then
|
||||
fi
|
||||
ln -s "$HOME/.dotfile/git/.gitconfig" "$src"
|
||||
|
||||
chmod +x "$HOME/.dotfile/git/git-credential-linux.sh"
|
||||
chmod +x "$HOME/.dotfile/git/git-credential.sh"
|
||||
# 兼容旧路径:若仍存在则保持可执行
|
||||
chmod +x "$HOME/.dotfile/git/git-credential-linux.sh" 2>/dev/null || true
|
||||
|
||||
Reference in New Issue
Block a user