Skip to content

Commit

Permalink
git: fix the config output formatting
Browse files Browse the repository at this point in the history
When setting values using the `git config --set` command, git formats
the file a bit differently. This changes the output so it maps to that
format.

Differences:

* each `key = value` in a section is prefixed by a tab character
* the `=` between the key and the value is surrounded by spaces

PR nix-community#1069
  • Loading branch information
zimbatm authored and jorsn committed Apr 25, 2020
1 parent e60752c commit 7c516c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions modules/programs/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let

# generation for multiple ini values
mkKeyValue = k: v:
let mkKeyValue = generators.mkKeyValueDefault { } "=" k;
in concatStringsSep "\n" (map mkKeyValue (toList v));
let mkKeyValue = generators.mkKeyValueDefault { } " = " k;
in concatStringsSep "\n" (map (kv: " " + mkKeyValue kv) (toList v));

# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI
gitFlattenAttrs = let
Expand Down
3 changes: 3 additions & 0 deletions tests/modules/programs/git/git-expected-include.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[user]
email = user@example.org
name = John Doe
42 changes: 21 additions & 21 deletions tests/modules/programs/git/git-expected.conf
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
[alias]
a1=foo
a2=baz
a1 = foo
a2 = baz

[commit]
gpgSign=true
gpgSign = true

[extra]
boolean=true
integer=38
multiple=1
multiple=2
name=value
boolean = true
integer = 38
multiple = 1
multiple = 2
name = value

[extra "backcompat.with.dots"]
previously=worked
previously = worked

[extra "subsection"]
value=test
value = test

[filter "lfs"]
clean=git-lfs clean -- %f
process=git-lfs filter-process
required=true
smudge=git-lfs smudge -- %f
clean = git-lfs clean -- %f
process = git-lfs filter-process
required = true
smudge = git-lfs smudge -- %f

[gpg]
program=path-to-gpg
program = path-to-gpg

[user]
email=user@example.org
name=John Doe
signingKey=00112233445566778899AABBCCDDEEFF
email = user@example.org
name = John Doe
signingKey = 00112233445566778899AABBCCDDEEFF

[include]
path=~/path/to/config.inc
path = ~/path/to/config.inc

[includeIf "gitdir:~/src/dir"]
path=~/path/to/conditional.inc
path = ~/path/to/conditional.inc

[includeIf "gitdir:~/src/dir"]
path=@git_include_path@
path = @git_include_path@
20 changes: 10 additions & 10 deletions tests/modules/programs/git/git-with-email-expected.conf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[sendemail "hm-account"]
from=hm@example.org
smtpEncryption=tls
smtpServer=smtp.example.org
smtpUser=home.manager.jr
from = hm@example.org
smtpEncryption = tls
smtpServer = smtp.example.org
smtpUser = home.manager.jr

[sendemail "hm@example.com"]
from=hm@example.com
smtpEncryption=tls
smtpServer=smtp.example.com
smtpUser=home.manager
from = hm@example.com
smtpEncryption = tls
smtpServer = smtp.example.com
smtpUser = home.manager

[user]
email=hm@example.com
name=H. M. Test
email = hm@example.com
name = H. M. Test
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
This can be anything.

[user]
email=user@example.org
name=John Doe
email = user@example.org
name = John Doe
4 changes: 2 additions & 2 deletions tests/modules/programs/git/git.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ let
pkgs.substituteAll {
src = path;

git_include_path =
pkgs.writeText "contents" (generators.toINI { } gitInclude);
git_include_path = pkgs.writeText "contents"
(builtins.readFile ./git-expected-include.conf);
};

in {
Expand Down

0 comments on commit 7c516c9

Please sign in to comment.