git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: Kristoffer Haugsbakk <code@khaugsbakk.name>,
	git@vger.kernel.org, stolee@gmail.com
Subject: Re: [PATCH v1 4/4] maintenance: use XDG config if it exists
Date: Mon, 23 Oct 2023 07:39:25 -0400	[thread overview]
Message-ID: <CAPig+cTx_wbs_b6he2O1EyUwZFp+5T8u6400_h87oCHxADb98A@mail.gmail.com> (raw)
In-Reply-To: <ZTZDsIcrB0zwHlFR@tanuki>

On Mon, Oct 23, 2023 at 5:58 AM Patrick Steinhardt <ps@pks.im> wrote:
> On Wed, Oct 18, 2023 at 10:28:41PM +0200, Kristoffer Haugsbakk wrote:
> > `git maintenance register` registers the repository in the user's global
> > config. `$XDG_CONFIG_HOME/git/config` is supposed to be used if
> > `~/.gitconfig` does not exist. However, this command creates a
> > `~/.gitconfig` file and writes to that one even though the XDG variant
> > exists.
> >
> > This used to work correctly until 50a044f1e4 (gc: replace config
> > subprocesses with API calls, 2022-09-27), when the command started calling
> > the config API instead of git-config(1).
> >
> > Also change `unregister` accordingly.
> >
> > Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name>
> > ---
> > +test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
> > +     XDG_CONFIG_HOME=.config &&
> > +     test_when_finished rm -r "$XDG_CONFIG_HOME"/git/config &&
> > +     export "XDG_CONFIG_HOME" &&
>
> Also, I think we need to unset this variable at the end of this test as
> tests don't run in a subshell. [...]

Yup, well spotted. Almost the entire body of this test should be in a
subshell to ensure that the environment variable does not live beyond
the end of this test. But test_when_finished() can't be used in a
subshell, so a little care is needed:

    test_expect_success 'register uses XDG_CONFIG_HOME config if it exists' '
        test_when_finished rm -r .config/git/config &&
        (
            XDG_CONFIG_HOME=.config &&
            ...
        )
    '

> > +     mkdir -p "$XDG_CONFIG_HOME"/git &&
> > +     touch "$XDG_CONFIG_HOME"/git/config &&

If the timestamp of the file is not significant, then we use `>` to
create it rather than `touch`:

    >"$XDG_CONFIG_HOME"/git/config &&

> > +     git maintenance register &&
> > +     git config --file="$XDG_CONFIG_HOME"/git/config --get maintenance.repo >actual &&
> > +     pwd >expect &&
> > +     test_cmp expect actual
> > +'

  reply	other threads:[~2023-10-23 11:39 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-18 20:28 [PATCH v1 0/4] maintenance: use XDG config if it exists Kristoffer Haugsbakk
2023-10-18 20:28 ` [PATCH v1 1/4] config: format newlines Kristoffer Haugsbakk
2023-10-18 20:28 ` [PATCH v1 2/4] config: rename global config function Kristoffer Haugsbakk
2023-10-18 20:28 ` [PATCH v1 3/4] config: factor out global config file retrieval Kristoffer Haugsbakk
2023-10-23  9:58   ` Patrick Steinhardt
2023-10-23 17:40     ` [PATCH v1 3/4] config: factor out global config file retrievalync-mailbox> Taylor Blau
2023-10-24 13:23       ` Kristoffer Haugsbakk
2023-10-25  5:38         ` Patrick Steinhardt
2023-10-25  7:33           ` Kristoffer Haugsbakk
2023-10-25  8:05             ` Patrick Steinhardt
2023-10-27 15:54               ` Junio C Hamano
2023-10-18 20:28 ` [PATCH v1 4/4] maintenance: use XDG config if it exists Kristoffer Haugsbakk
2023-10-23  9:58   ` Patrick Steinhardt
2023-10-23 11:39     ` Eric Sunshine [this message]
2024-01-14 21:43 ` [PATCH v2 0/4] " Kristoffer Haugsbakk
2024-01-14 21:43   ` [PATCH v2 1/4] config: format newlines Kristoffer Haugsbakk
2024-01-14 21:43   ` [PATCH v2 2/4] config: rename global config function Kristoffer Haugsbakk
2024-01-14 21:43   ` [PATCH v2 3/4] config: factor out global config file retrieval Kristoffer Haugsbakk
2024-01-16 21:39     ` Junio C Hamano
2024-01-16 21:46       ` Kristoffer Haugsbakk
2024-01-19  6:18     ` Patrick Steinhardt
2024-01-19  7:40       ` Kristoffer Haugsbakk
2024-01-19  7:59         ` Patrick Steinhardt
2024-01-19 23:04           ` Junio C Hamano
2024-01-19 18:36         ` Junio C Hamano
2024-01-19 18:59           ` rsbecker
2024-01-14 21:43   ` [PATCH v2 4/4] maintenance: use XDG config if it exists Kristoffer Haugsbakk
2024-01-16 21:52     ` Junio C Hamano
2024-01-18 16:12 ` [PATCH v3 0/4] " Kristoffer Haugsbakk
2024-01-18 16:12   ` [PATCH v3 1/4] config: format newlines Kristoffer Haugsbakk
2024-01-18 16:12   ` [PATCH v3 2/4] config: rename global config function Kristoffer Haugsbakk
2024-01-18 16:12   ` [PATCH v3 3/4] config: factor out global config file retrieval Kristoffer Haugsbakk
2024-01-18 16:12   ` [PATCH v3 4/4] maintenance: use XDG config if it exists Kristoffer Haugsbakk

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=CAPig+cTx_wbs_b6he2O1EyUwZFp+5T8u6400_h87oCHxADb98A@mail.gmail.com \
    --to=sunshine@sunshineco.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=ps@pks.im \
    --cc=stolee@gmail.com \
    /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).