From: Marc Branchaud <marcnarc@xiplink.com>
To: Stefan Haller <lists@haller-berlin.de>, git@vger.kernel.org
Subject: Re: Storing private config files in .git directory?
Date: Mon, 8 Jan 2024 14:48:34 -0500 [thread overview]
Message-ID: <3717f23b-14a9-4c00-aaa9-ebb0f46f811e@xiplink.com> (raw)
In-Reply-To: <8e344dee-f84e-4a2c-835a-406ee72d129b@haller-berlin.de>
On 2024-01-07 08:03, Stefan Haller wrote:
> Our git client (lazygit) has a need to store per-repo config files that
> override the global one, much like git itself. The easiest way to do
> that is to store those in a .git/lazygit.cfg file, and I'm wondering if
> there's any reason why this is a bad idea?
In a worktree (created by "git worktree"), .git is a file not a directory.
Worktrees are designed to each have their own .git directory, which you
can find with "git rev-parse --git-dir". If you just want a single,
repo-wide config file, not a per-worktree config, you probably want to
instead use "git rev-parse --git-common-dir" to find the "main" repo's
.git directory.
The problem of finding a worktree's .git directory goes away if you use
Git's own config system, though.
> Another alternative would be to store the config values in .git/config
> (that's the path taken by git gui, for example), but since our config
> file format is yaml, this would require translation. It would be trivial
> for scalar values such as int or string, but I'm not sure how well this
> would work for more complex settings like lists of objects.
>
> Any thoughts?
YAML is a horrid little format (hey, you asked for "thoughts"!), and
IIRC Git's config file format only supports multi-line values with
\-escaping and similar patterns, making it nearly impossible to directly
embed YAML in Git's config file. Ideally, if you do use Git's own
config then you really should just drop YAML altogether.
But you have a couple of options without going so far as translating all
the YAML constructs you use into git-config ones. For example, you
could replace all the newlines in a YAML blob with \n to make a
single-line value that you could store in Git's config file. That
complicates hand-editing the YAML though, if that's a use case you care
about.
But even if you replace all the newlines with \n, in my experience there
are always corner-case clashes when mixing file syntaxes (e.g. quoted
strings are often problematic, and maybe some of your YAML values are
themselves multi-line). If you want to use Git's own config file but
stick with YAML, and you really don't care about directly editing the
YAML, I suggest you encode the entire YAML blob in a robust single-line
format, like base64, and store/retrieve that using "git config".
You could still support hand-editing the YAML with a command like
"lazygit editconfig", too.
M.
prev parent reply other threads:[~2024-01-08 19:48 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-07 13:03 Storing private config files in .git directory? Stefan Haller
2024-01-08 18:20 ` Junio C Hamano
2024-01-10 11:08 ` Jeff King
2024-01-11 13:28 ` Stefan Haller
2024-01-12 6:56 ` Jeff King
2024-01-08 18:56 ` Konstantin Ryabitsev
2024-01-08 19:48 ` Marc Branchaud [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3717f23b-14a9-4c00-aaa9-ebb0f46f811e@xiplink.com \
--to=marcnarc@xiplink.com \
--cc=git@vger.kernel.org \
--cc=lists@haller-berlin.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).