git: fix the config output formatting

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 #1069
This commit is contained in:
zimbatm 2020-03-05 15:57:19 +01:00 committed by Robert Helgesson
parent 71c7aaee83
commit 9a1feb5b10
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
6 changed files with 40 additions and 37 deletions

View file

@ -21,8 +21,8 @@ let
# generation for multiple ini values # generation for multiple ini values
mkKeyValue = k: v: mkKeyValue = k: v:
let mkKeyValue = generators.mkKeyValueDefault { } "=" k; let mkKeyValue = generators.mkKeyValueDefault { } " = " k;
in concatStringsSep "\n" (map mkKeyValue (toList v)); in concatStringsSep "\n" (map (kv: " " + mkKeyValue kv) (toList v));
# converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI # converts { a.b.c = 5; } to { "a.b".c = 5; } for toINI
gitFlattenAttrs = let gitFlattenAttrs = let

View file

@ -0,0 +1,3 @@
[user]
email = user@example.org
name = John Doe

View file

@ -1,42 +1,42 @@
[alias] [alias]
a1=foo a1 = foo
a2=baz a2 = baz
[commit] [commit]
gpgSign=true gpgSign = true
[extra] [extra]
boolean=true boolean = true
integer=38 integer = 38
multiple=1 multiple = 1
multiple=2 multiple = 2
name=value name = value
[extra "backcompat.with.dots"] [extra "backcompat.with.dots"]
previously=worked previously = worked
[extra "subsection"] [extra "subsection"]
value=test value = test
[filter "lfs"] [filter "lfs"]
clean=git-lfs clean -- %f clean = git-lfs clean -- %f
process=git-lfs filter-process process = git-lfs filter-process
required=true required = true
smudge=git-lfs smudge -- %f smudge = git-lfs smudge -- %f
[gpg] [gpg]
program=path-to-gpg program = path-to-gpg
[user] [user]
email=user@example.org email = user@example.org
name=John Doe name = John Doe
signingKey=00112233445566778899AABBCCDDEEFF signingKey = 00112233445566778899AABBCCDDEEFF
[include] [include]
path=~/path/to/config.inc path = ~/path/to/config.inc
[includeIf "gitdir:~/src/dir"] [includeIf "gitdir:~/src/dir"]
path=~/path/to/conditional.inc path = ~/path/to/conditional.inc
[includeIf "gitdir:~/src/dir"] [includeIf "gitdir:~/src/dir"]
path=@git_include_path@ path = @git_include_path@

View file

@ -1,15 +1,15 @@
[sendemail "hm-account"] [sendemail "hm-account"]
from=hm@example.org from = hm@example.org
smtpEncryption=tls smtpEncryption = tls
smtpServer=smtp.example.org smtpServer = smtp.example.org
smtpUser=home.manager.jr smtpUser = home.manager.jr
[sendemail "hm@example.com"] [sendemail "hm@example.com"]
from=hm@example.com from = hm@example.com
smtpEncryption=tls smtpEncryption = tls
smtpServer=smtp.example.com smtpServer = smtp.example.com
smtpUser=home.manager smtpUser = home.manager
[user] [user]
email=hm@example.com email = hm@example.com
name=H. M. Test name = H. M. Test

View file

@ -1,5 +1,5 @@
This can be anything. This can be anything.
[user] [user]
email=user@example.org email = user@example.org
name=John Doe name = John Doe

View file

@ -15,8 +15,8 @@ let
pkgs.substituteAll { pkgs.substituteAll {
src = path; src = path;
git_include_path = git_include_path = pkgs.writeText "contents"
pkgs.writeText "contents" (generators.toINI { } gitInclude); (builtins.readFile ./git-expected-include.conf);
}; };
in { in {