]> Git — Sourcephile - julm/julm-nix.git/blob - home-manager/profiles/git.nix
git: push: replace --force with --force-with-lease --force-if-includes
[julm/julm-nix.git] / home-manager / profiles / git.nix
1 { pkgs, lib, config, ... }:
2 {
3 home.packages = lib.mkIf config.programs.git.enable [
4 pkgs.b4
5 pkgs.delta
6 pkgs.difftastic
7 pkgs.git-absorb
8 pkgs.git-bug
9 pkgs.git-chglog
10 pkgs.git-cliff
11 pkgs.git-crypt
12 pkgs.git-extras
13 pkgs.git-filter-repo
14 #pkgs.git-publish
15 pkgs.git-quick-stats
16 pkgs.gitui
17 #pkgs.radicle-node
18 pkgs.tig
19 ];
20 programs.git = {
21 enable = lib.mkDefault true;
22 ignores = [ "*~" "*.swp" ];
23 package = lib.mkDefault pkgs.gitMinimal;
24 aliases = {
25 a = "add";
26 ab = "absorb";
27 abr = "absorb -r";
28 ap = "add -p";
29 au = "add -u";
30 authors = "shortlog -s -n";
31 b = "branch";
32 bl = "git log -p -M --follow --stat --";
33 c = "commit";
34 ca = "commit --amend";
35 caa = "commit --amend -C@";
36 caaa = "commit --amend -C@ -a";
37 cf = "commit --fixup";
38 co = "checkout";
39 d = "diff";
40 dc = "diff --cached";
41 dcw = "diff --cached --word-diff=color";
42 dh = "diff --histogram";
43 dp = "diff --patience";
44 dt = "difftool --patience";
45 dtc = "difftool --cached";
46 dw = "diff --word-diff=color";
47 g = "grep";
48 ign = "ls-files -o -i --exclude-standard";
49 l = "log";
50 ll = "log --graph --decorate --pretty=oneline --abbrev-commit";
51 lp = "log -p --pretty=fuller --stat";
52 lpg = "log -p --pretty=fuller --stat -g";
53 p = "push -v";
54 pa = "patch";
55 patch = "push rad HEAD:refs/patches";
56 # See https://stackoverflow.com/a/65839129/6741004
57 pf = "push -v --force-with-lease --force-if-includes";
58 pl = "pull";
59 r = "reset";
60 rh = "reset --hard";
61 ri = "rebase -i";
62 rp = "reset -p";
63 s = "status";
64 spull = "!git-svn fetch && git-svn rebase";
65 spush = "!git-svn dcommit";
66 ss = "status -s";
67 st = "status -uno";
68 sw = "switch";
69 fetch-local = "!git fetch local && git tag -d $(git describe --exact-match 2>/dev/null >/dev/null) && git fetch --tags local";
70 pull-local = "!git fetch-local && git checkout -B master local/master";
71 pull-local-old = "!git fetch-local && git checkout HEAD'^' && git branch -f master local/master && git checkout master";
72 root = ''!git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"'';
73 has-tag-version = ''!git show-ref --tags -d | grep -qx \"^$(git rev-parse HEAD) refs/tags/v[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]\\(\\^{}\\)\\?\"'';
74 tag-version = ''"!git has-tag-version && return; v=$(TZ=UTC date +v%Y-%m-%d) && name=$(git rev-parse --show-toplevel | sed -e 's:^.*/work::') && set -x && git tag -s -m \"$name $v\" $v"'';
75 has-tag-majordate = ''!git show-ref --tags -d | grep -qx \"^$(git rev-parse HEAD) refs/tags/v[0-9]\\+.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\\(\\^{}\\)\\?\"'';
76 tag-majordate = ''"!git has-tag-majordate && return; name=$(basename $(dirname $(git rev-parse --show-toplevel))); major=$(basename $(git rev-parse --show-toplevel)); version=''${version:-$(TZ=UTC date +\"v$major.%Y%m%d\")} && set -x && git tag -s -m \"$name $version\" $version"'';
77 tag-cabal = ''"!set -x; for cabal in $(git ls-files | grep '.*\\.cabal$'); do name=$(sed -ne 's/^name: *\\(.*\\)/\\1/p' \"$cabal\"); version=$(sed -ne 's/^version: *\\(.*\\)/\\1/p' \"$cabal\"); git tag --merged | grep -Fqx \"$name-$version\" || git tag -f -s -m \"$name v$version\" $name-$version; done"'';
78 cl = "notes --ref=changelog append";
79 cl-bug = "notes --ref=changelogs/bugs append";
80 cl-feature = "notes --ref=changelogs/features append";
81 wip = "for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads";
82 };
83 extraConfig = {
84 browser.elinks.cmd = "elinks";
85 color.branch = "auto";
86 color.diff = "auto";
87 #color.diff.whitespace = "red reverse";
88 color.status = "auto";
89 core.commentChar = "auto";
90 core.quotepath = "false";
91 core.whitespace = "fix,-indent-with-non-tab,trailing-space,cr-at-eol";
92 diff.algorithm = "histogram";
93 diff.sqldiff.command = "sqldiff";
94 format.pretty = "oneline";
95 gui.fontdiff = ''-family "DejaVu Sans Mono" -size 8 -weight normal -slant roman -underline 0 -overstrike 0'';
96 gui.fontui = ''-family "DejaVu Sans" -size 8 -weight normal -slant roman -underline 0 -overstrike 0'';
97 gui.spellingdictionary = "en_US";
98 gui.tabsize = 4;
99 guitool."Rebase interactive" = {
100 cmd = "EDITOR=gvim git rebase -i $REVISION";
101 revprompt = true;
102 };
103 init.defaultBranch = "main";
104 merge.tool = "vimdiff";
105 merge.conflictStyle = "zdiff3";
106 protocol.version = 2;
107 pull.rebase = true;
108 push.default = "simple";
109 push.useForceIfIncludes = true;
110 rebase.autosquash = "true";
111 sendemail.chainReplyTo = "false";
112 sendemail.composeencoding = "UTF-8";
113 sendemail.confirm = "always";
114 sendemail.envelopeSender = "auto";
115 sendemail.multiedit = "yes";
116 sendemail.suppressFrom = "false";
117 sendemail.suppresscc = "self";
118 sendemail.thread = "true";
119 sendemail.validate = "true";
120 web.browser = "elinks";
121 };
122 iniContent = {
123 /*
124 diff.external = lib.concatStringsSep " " [
125 "${pkgs.difftastic}/bin/difft"
126 "--color auto"
127 "--background dark"
128 "--display side-by-side"
129 ];
130 */
131 # difftastic
132 /*
133 diff.tool = "difftastic";
134 difftool.prompt = false;
135 difftool.difftastic.cmd = ''${pkgs.difftastic}/bin/difft "$LOCAL" "$REMOTE"'';
136 pager.difftool = true;
137 */
138
139 # delta
140 /*
141 core.pager = "delta --grep-separator-symbol keep";
142 interactive.diffFilter = "delta --color-only --features=interactive";
143 delta.features = "decorations";
144 delta.interactive = {
145 keep-plus-minus-markers = false;
146 };
147 delta.decorations = {
148 commit-decoration-style = "blue ol";
149 commit-style = "raw";
150 file-style = "omit";
151 hunk-header-decoration-style = "blue box";
152 hunk-header-file-style = "red";
153 hunk-header-line-number-style = "#067a00";
154 hunk-header-style = "file line-number syntax";
155 };
156 */
157 };
158 };
159 programs.bash = lib.mkIf config.programs.git.enable {
160 shellAliases = {
161 g = "git";
162 ge = "git-edit-commit";
163 gg = "git grep";
164 gge = "git-grep-edit";
165 gui = "gitui";
166 };
167 initExtra = ''
168 git-edit-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); }
169 git-grep-edit () { $EDITOR $(git grep --name-only --recursive "$@"); }
170 '';
171 };
172 }