about summary refs log tree commit diff
path: root/nix/users/fcuny/git.nix
blob: c89454b0b528f69679f7c4382d376991c1b96df7 (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
{ lib, pkgs, ... }: {
  home.packages = with pkgs; [
    gitAndTools.pre-commit
    git-credential-manager
    gh
  ];

  programs.git = {
    enable = true;
    userName = "Franck Cuny";
    userEmail = "franck@fcuny.net";

    aliases = { amend = "commit --amend"; };

    # https://stackoverflow.com/questions/74012449/git-includeif-hasconfigremote-url-not-working
    # to test it's working as expected:
    # run `git config --get-all user.email' in a repository to check that we get all the possible emails
    # run `git config --get user.email' in a repository to check which email is selected
    includes = [
      {
        condition = "hasconfig:remote.*.url:git@github.rbx.com:*/**";
        path = pkgs.writeText "username.cfg"
          (lib.generators.toGitINI { user.email = "fcuny@roblox.com"; });
      }
      {
        condition = "hasconfig:remote.*.url:git@github.com:Roblox/**";
        path = pkgs.writeText "username.cfg"
          (lib.generators.toGitINI { user.email = "fcuny@roblox.com"; });
      }
    ];

    ignores = [ ".envrc" ".direnv" ];

    extraConfig = {
      core.whitespace = "trailing-space,space-before-tab";
      color.ui = "true";

      # abort if the remote branch does not match the local one
      push.default = "simple";

      # https://adamj.eu/tech/2024/01/18/git-improve-diff-histogram/
      diff.algorithm = "histogram";

      init.defaultBranch = "main";

      pull.rebase = true;
      rebase = {
        # Automatically create a temporary stash entry before the
        # operation begins, and apply it after the operation ends.
        autoStash = true;
        # Print a warning if some commits are removed
        missingCommitsCheck = "warn";
      };

      branch.autosetuprebase = "remote";
      branch.sort = "authordate";

      url = {
        "ssh://git@github.rbx.com/" = {
          insteadOf = "https://github.rbx.com/";
        };
        "ssh://git@git.fcuny.net:422/" = {
          insteadOf = "https://git.fcuny.net/";
        };
      };
    };
  };
}