about summary refs log tree commit diff stats
path: root/modules/home/conf/git/default.nix
blob: e896b317dd84a51c1817099240d9edfdbafc264f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
{
  nixosConfig,
  lib,
  config,
  sysLib,
  pkgs,
  ...
}: let
  gitIgnoreFile = ./git_ignore.git;
  gitTemplateFile = ./git_template.git;
  commit = sysLib.writeShellScript {
    name = "commit";
    src = ./scripts/commit.sh;
    keepPath = true;
    dependencies = with pkgs; [
      git
      gnused
    ];
  };
in {
  programs.git = {
    enable = true;
    #package = pkgs.gitAndTools.gitFull; # TODO: for git send-email support
    aliases = {
      cm = "!${commit}/bin/commit";
      cmr = "commit --file .git/COMMIT_EDITMSG --edit --verbose";

      st = "status";
      sts = "status --short --branch";

      ds = "diff --staged";
      di = "diff";
      rs = "restore --staged";

      ## Logging:
      ls = "log --max-count=10 --color --format=format:'%C(bold red)%h%C(reset) %C(dim bold blue)%s%C(reset) %C(dim white)[%aN] %C(bold red)<%G?>%C(reset)%C(auto)%d%C(reset)'";

      # https://stackoverflow.com/a/61487052
      lg = "lg1";
      lg1 = "lg1-specific --all";
      lg2 = "lg2-specific --all";
      lg3 = "lg3-specific --all";

      lg1-specific = "log --graph --abbrev-commit --decorate \
                      --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold cyan) [%G?]%C(reset)%C(auto)%d%C(reset)'";

      lg2-specific = "log --graph --abbrev-commit --decorate \
                      --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'";

      lg3-specific = "log --graph --abbrev-commit --decorate \
                      --format=format:'%C(bold blue)%h%C(reset)\
                      - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)\
                      %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)\
                      %C(bold red)(signature: %G? by %GS, trust: %GT)%C(reset)%n\
                      ''          %C(white)%s%C(reset)%n''\
                      %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)\
                      %C(bold white)- trailers: %(trailers) %C(reset)'";

      # hard reset with commit before (use reflog to recover)
      #    git wipe [<commit>]
      wipe = lib.strings.concatStringsSep " " [
        "!git"
        "add"
        "--all"
        "&&"
        "git"
        "commit"
        "--quiet"
        "--message='WIPE-SAVEPOINT'"
        "--no-gpg-sign"
        "&&"
        "git reset \${1:-HEAD~} --hard"
        "&&"
        "git clean -fd"
      ];
      branches = lib.strings.concatStringsSep " " [
        "!git"
        "for-each-ref"
        "--sort=-committerdate"
        "--color=always"
        "--format='${
          lib.strings.concatStringsSep "|" [
            "%(color:blue)%(authordate:relative)"
            "%(color:red)%(authorname)"
            "%(color:green)%(color:bold)%(refname:short)"
          ]
        }'"
        "refs/remotes"
        "|"
        "column -ts'|' -o '   '"
      ];
      tags = "tag --list";
      remotes = "remote --verbose";
      day = "!git log --stat --since '1 day ago' --author $(git config user.email)";
      unpush = "push --force-with-lease origin HEAD~1:${config.programs.git.extraConfig.init.defaultBranch}";
      wip = "!git add . && git commit --amend && git push --force-with-lease";
    };
    extraConfig = {
      core = {
        excludesFile = "${gitIgnoreFile}";
      };
      rebase = {
        autoStash = true;
        autoSquash = true;
      };
      init = {
        defaultBranch = "prime";
      };
      user = {
        name = "Benedikt Peetz";
        email = "benedikt.peetz@b-peetz.de";
        # signingKey = "[is down below]";
      };
      help = {
        autocorrect = 5;
      };
      push = {
        gpgSign = "if-asked";
      };
      commit = {
        template = "${gitTemplateFile}";
      };
      diff = {
        colorMoved = "default";
        # Usually leads to better results
        algorithm = "patience";
        bin = {
          textconv = "hexdump -v -C";
        };
      };
      # Makes it a bit more readable
      blame = {
        coloring = "repeatedLines";
        markIgnoredLines = true;
        markUnblamables = true;
      };
      merge = {
        conflictstyle = "zdiff3";
      };
      url = {
        "git@codeberg.org:" = {
          insteadOf = "@cb:";
        };
        "https://codeberg.org/" = {
          insteadOf = "cb://";
        };

        "git@github.com:" = {
          insteadOf = "@gh:";
        };
        "https://github.com/" = {
          insteadOf = "gh://";
        };

        "git@gitlab.com:" = {
          insteadOf = "@gl:";
        };
        "https://gitlab.com/" = {
          insteadOf = "gl://";
        };
      };
    };
    delta = {
      enable = true;
      options = {
        decorations = {
          commit-decoration-style = "bold yellow box ul";
          file-decoration-style = "none";
          file-style = "bold yellow ul";
        };
        keep-plus-minus-markers = true;
        features = "decorations";
        whitespace-error-style = "22 reverse";
      };
    };
    signing = {
      key = "8321ED3A8DB999A51F3BF80FF2682914EA42DE26";
      signByDefault = true;
    };
  };
}