home-manager/git/default.nix

128 lines
2.6 KiB
Nix
Raw Normal View History

2024-07-10 10:58:04 +00:00
{ pkgs, userName, userEmail, gpgSigningKey, ... }:
2024-07-10 06:10:56 +00:00
{
programs = {
less.enable = true;
git = {
enable = true;
2024-07-10 06:17:30 +00:00
inherit userName;
inherit userEmail;
2024-07-10 06:10:56 +00:00
signing = {
2024-07-10 10:58:04 +00:00
key = gpgSigningKey;
2024-07-10 06:10:56 +00:00
signByDefault = true;
};
difftastic = {
enable = true;
background = "light";
};
lfs = {
enable = true;
};
extraConfig = {
core.editor = "nvim";
core.pager = "less -FX";
credential.helper = "cache --timeout=3600";
diff.ignoreSubmodules = "none";
2024-07-15 05:45:45 +00:00
fetch.parallel = 8;
2024-07-10 06:10:56 +00:00
fetch.writeCommitGraph = true;
fetch.recurseSubmodules = true;
format.pretty = "format:%C(yellow)%h %Cblue%>(12)%ad %C(red)%G? %Cgreen%<(7,trunc)%aN%Cred%d %Creset%s";
init.defaultBranch = "main";
log.date = "relative";
merge.ff = false;
merge.tool = "nvim";
mergetool.nvim.cmd = "nvim -f -c \"Gdiffsplit!\" \"$MERGED\"";
mergetool.prompt = false;
pager.difftool = true;
pull.rebase = true;
push.recurseSubmodules = "on-demand";
rebase.autostash = true;
rerere.enabled = true;
status.submoduleSummary = true;
2024-07-15 05:45:45 +00:00
submodule.fetchJobs = 8;
2024-07-10 06:10:56 +00:00
submodule.recurse = true;
worktree.guessRemote = true;
};
aliases = {
graph = "log --graph";
2024-07-10 06:10:56 +00:00
};
ignores = [
".env"
".direnv"
"*.swp"
];
};
};
home.packages = with pkgs; [
(writeShellScriptBin "git-clone-worktree" ''
uri=''${1}
dir=''${2}
2024-07-10 11:40:41 +00:00
if [[ -z ''${dir} ]]; then
2024-07-10 06:10:56 +00:00
dir=''$(basename ''${1} .git)
fi
if [[ -e ''${dir} ]]; then
echo "error: directory ''${dir} already exists"
exit 1
fi
mkdir ''${dir}
git clone ''${uri} ''${dir}/.base
branch=`git -C ''${dir}/.base symbolic-ref --short HEAD`
echo "default branch is ''${branch}"
git -C ''${dir}/.base checkout --detach HEAD
git -C ''${dir}/.base worktree add ../''${branch}
'')
(writeShellScriptBin "git-make-relative" ''
2024-07-10 11:40:41 +00:00
2024-07-10 06:10:56 +00:00
gitfile=''${1}
2024-07-10 11:40:41 +00:00
if [[ -z ''${gitfile} ]]; then
2024-07-10 06:10:56 +00:00
gitfile=".git"
2024-07-10 11:40:41 +00:00
fi
2024-07-10 06:10:56 +00:00
2024-07-10 11:40:41 +00:00
if [[ ! -f ''${gitfile} ]]; then
2024-07-10 06:10:56 +00:00
echo "file ''${gitfile} does not exist"
2024-07-10 11:40:41 +00:00
exit 1
fi
2024-07-10 06:10:56 +00:00
gitdir=$(grep "gitdir:" ''${gitfile} | cut -d: -f2 | xargs)
rel_gitdir=$(realpath -s --relative-to=. ''${gitdir})
echo "relative path: ''${rel_gitdir}"
sed -i -e "s,gitdir:.*,gitdir: ''${rel_gitdir}," ''${gitfile}
'')
];
}