GNU bug report logs - #37679
Local git configuration interferes with testsuite

Previous Next

Package: guix;

Reported by: Gábor Boskovits <boskovits <at> gmail.com>

Date: Wed, 9 Oct 2019 10:37:01 UTC

Severity: normal

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37679 in the body.
You can then email your comments to 37679 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Wed, 09 Oct 2019 10:37:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Gábor Boskovits <boskovits <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Wed, 09 Oct 2019 10:37:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Gábor Boskovits <boskovits <at> gmail.com>
To: bug-guix <at> gnu.org
Subject: Local git configuration interferes with testsuite
Date: Wed, 9 Oct 2019 12:35:58 +0200
[Message part 1 (text/plain, inline)]
I noticed that the local git configuration interferes with the guix test
suite.

After discussion on IRC with nckx I came up with the attached patch.
Comments are welcome!

Best regards,
g_bor
-- 
OpenPGP Key Fingerprint: 7988:3B9F:7D6A:4DBF:3719:0367:2506:A96C:CF63:0B21
[Message part 2 (text/html, inline)]
[0001-tests-Isolate-git-from-external-configuration.patch (text/x-patch, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Tue, 07 Jan 2020 09:12:02 GMT) Full text and rfc822 format available.

Message #8 received at 37679 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Gábor Boskovits <boskovits <at> gmail.com>
Cc: 37679 <at> debbugs.gnu.org
Subject: Re: bug#37679: Local git configuration interferes with testsuite
Date: Tue, 07 Jan 2020 10:11:32 +0100
Hello!

Gábor Boskovits <boskovits <at> gmail.com> skribis:

> From abf20477ea139bfaf1f2e21f09c2420fe618c9ca Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?G=C3=A1bor=20Boskovits?= <boskovits <at> gmail.com>
> Date: Tue, 8 Oct 2019 22:41:20 +0200
> Subject: [PATCH] tests: Isolate git from external configuration.
>
> * Makefile.am(AM_TESTS_ENVIRONMENT): Add environment variables to
> make git ignore the user and system configuration files.
> * tests/fake-home/.gitconfig: New file. Provide minimal git
> configuration for tests.
> ---
>  Makefile.am                |  9 ++++++++-
>  tests/fake-home/.gitconfig | 21 +++++++++++++++++++++
>  2 files changed, 29 insertions(+), 1 deletion(-)
>  create mode 100644 tests/fake-home/.gitconfig
>
> diff --git a/Makefile.am b/Makefile.am
> index 36767c2f47..e7bf819a6b 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -14,6 +14,7 @@
>  # Copyright © 2018 Oleg Pykhalov <go.wigust <at> gmail.com>
>  # Copyright © 2018 Alex Vong <alexvong1995 <at> gmail.com>
>  # Copyright © 2019 Efraim Flashner <efraim <at> flashner.co.il>
> +# Copyright © 2019 Gábor Boskovits <boskovits <at> gmail.com>
>  #
>  # This file is part of GNU Guix.
>  #
> @@ -472,7 +473,13 @@ SH_TESTS =					\
>  
>  TESTS = $(SCM_TESTS) $(SH_TESTS)
>  
> -AM_TESTS_ENVIRONMENT = abs_top_srcdir="$(abs_top_srcdir)" GUILE_AUTO_COMPILE=0
> +AM_TESTS_ENVIRONMENT = 				\
> +  abs_top_srcdir="$(abs_top_srcdir)" 		\
> +  GUILE_AUTO_COMPILE=0				\
> +  GIT_CONFIG_NOSYSTEM=1				\
> +  GIT_ATTR_NOSYSTEM=1				\
> +  HOME="$(abs_top_srcdir)/tests/fake-home"	\
> +  XDG_CONFIG_HOME="$(abs_top_srcdir)/tests/fake-xgd-config-home"

Ooh, good catch.  This change fixes issues with ‘tests/git.scm’, is that
correct?

The ‘GIT_’ environment variables are honored by Git itself, not by
libgit2/Guile-Git, right?

Can we avoid setting HOME and XDG_CONFIG_HOME?

Perhaps these variables should all be set in ‘test-env’ along with their
friends, for consistency?

Last, if we end up keeping ‘tests/fake-home’, make sure to also add it
to ‘EXTRA_DIST’ in ‘Makefile.am’.

Could you send an updated patch?

Thanks for addressing it, and sorry for the loooong delay!

Ludo’.




Information forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Mon, 30 Mar 2020 02:36:27 GMT) Full text and rfc822 format available.

Message #11 received at 37679 <at> debbugs.gnu.org (full text, mbox):

From: Gábor Boskovits <boskovits <at> gmail.com>
To: 37679 <at> debbugs.gnu.org
Cc: Gábor Boskovits <boskovits <at> gmail.com>
Subject: [PATCH 0/2] Local git configuration interferes with testsuite
Date: Sun, 29 Mar 2020 15:18:08 +0200
Create a fake home in tests with a gitconfig so that the user configuration
does not get picked up.
I investigated how to solve this best, but git only respects HOME for the
commands we are using.
Also note that this does not affect libraries, only the git cli, as libraries
do not use the environment variables.

Gábor Boskovits (2):
  tests: Isolate git from user configuration.
  tests: Ignore files created by the testsuite.

 .gitignore                 |  4 +++-
 Makefile.am                |  2 ++
 build-aux/test-env.in      |  4 ++++
 tests/fake-home/.gitconfig | 21 +++++++++++++++++++++
 4 files changed, 30 insertions(+), 1 deletion(-)
 create mode 100644 tests/fake-home/.gitconfig

-- 
2.25.0





Information forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Mon, 30 Mar 2020 02:36:27 GMT) Full text and rfc822 format available.

Message #14 received at 37679 <at> debbugs.gnu.org (full text, mbox):

From: Gábor Boskovits <boskovits <at> gmail.com>
To: 37679 <at> debbugs.gnu.org
Cc: Gábor Boskovits <boskovits <at> gmail.com>
Subject: [PATCH 1/2] tests: Isolate git from user configuration.
Date: Sun, 29 Mar 2020 15:18:09 +0200
* tests/fake-home/.gitconfig: New file. Provide minimal git
configuration for tests.
* build-aux/test-env.in: Set HOME to the fake home.
* Makefile.am(EXTRA_DIST): Add fake-home/.gitconfig.
---
 Makefile.am                |  2 ++
 build-aux/test-env.in      |  4 ++++
 tests/fake-home/.gitconfig | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+)
 create mode 100644 tests/fake-home/.gitconfig

diff --git a/Makefile.am b/Makefile.am
index 344ecdbc42..5eb918d599 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -14,6 +14,7 @@
 # Copyright © 2018 Oleg Pykhalov <go.wigust <at> gmail.com>
 # Copyright © 2018 Alex Vong <alexvong1995 <at> gmail.com>
 # Copyright © 2019 Efraim Flashner <efraim <at> flashner.co.il>
+# Copyright © 2020 Gábor Boskovits <boskovits <at> gmail.com>
 #
 # This file is part of GNU Guix.
 #
@@ -560,6 +561,7 @@ EXTRA_DIST +=						\
   build-aux/update-NEWS.scm				\
   d3.v3.js						\
   graph.js						\
+  tests/fake-home/.gitconfig				\
   tests/test.drv					\
   tests/signing-key.pub					\
   tests/signing-key.sec					\
diff --git a/build-aux/test-env.in b/build-aux/test-env.in
index 59ab58cc94..1121570fbc 100644
--- a/build-aux/test-env.in
+++ b/build-aux/test-env.in
@@ -2,6 +2,7 @@
 
 # GNU Guix --- Functional package management for GNU
 # Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo <at> gnu.org>
+# Copyright © 2020 Gábor Boskovits <boskovits <at> gmail.com>
 #
 # This file is part of GNU Guix.
 #
@@ -151,6 +152,9 @@ export GUIX_BUILD_OPTIONS
 # Ignore user settings.
 unset GUIX_PACKAGE_PATH
 
+# Provide fake home for tests using git
+HOME="@abs_top_srcdir@/tests/fake-home"
+
 storedir="@storedir@"
 prefix="@prefix@"
 datarootdir="@datarootdir@"
diff --git a/tests/fake-home/.gitconfig b/tests/fake-home/.gitconfig
new file mode 100644
index 0000000000..c32de560e7
--- /dev/null
+++ b/tests/fake-home/.gitconfig
@@ -0,0 +1,21 @@
+# GNU Guix --- Functional package management for GNU
+# Copyright © 2020 Gábor Boskovits <boskovits <at> gmail.com>
+#
+# This file is part of GNU Guix.
+#
+# GNU Guix is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# GNU Guix is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+[user]
+  email = alice <at> example.com
+  name = Alice
-- 
2.25.0





Information forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Mon, 30 Mar 2020 02:36:28 GMT) Full text and rfc822 format available.

Message #17 received at 37679 <at> debbugs.gnu.org (full text, mbox):

From: Gábor Boskovits <boskovits <at> gmail.com>
To: 37679 <at> debbugs.gnu.org
Cc: Gábor Boskovits <boskovits <at> gmail.com>
Subject: [PATCH 2/2] tests: Ignore files created by the testsuite.
Date: Sun, 29 Mar 2020 15:18:10 +0200
* .gitignore: Add /tests/fake-home/.guix-profile.
Ignore test result files in tests subdirectories.
Ignore top level files staring with t-.
---
 .gitignore | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index de058dda5e..19aae6c5ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -137,7 +137,8 @@
 /scripts/guix
 /test-env
 /test-tmp
-/tests/*.trs
+/tests/**/*.trs
+/tests/fake-home/.guix-profile
 GPATH
 GRTAGS
 GTAGS
@@ -152,3 +153,4 @@ tmp
 /.version
 /doc/stamp-[0-9]
 /gnu/packages/bootstrap
+/t-*
\ No newline at end of file
-- 
2.25.0





Information forwarded to bug-guix <at> gnu.org:
bug#37679; Package guix. (Fri, 17 Apr 2020 08:47:02 GMT) Full text and rfc822 format available.

Message #20 received at 37679 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Gábor Boskovits <boskovits <at> gmail.com>
Cc: 37679 <at> debbugs.gnu.org
Subject: Re: bug#37679: Local git configuration interferes with testsuite
Date: Fri, 17 Apr 2020 10:46:04 +0200
[Message part 1 (text/plain, inline)]
Hi Gábor,

Gábor Boskovits <boskovits <at> gmail.com> skribis:

> +AM_TESTS_ENVIRONMENT = 				\
> +  abs_top_srcdir="$(abs_top_srcdir)" 		\
> +  GUILE_AUTO_COMPILE=0				\
> +  GIT_CONFIG_NOSYSTEM=1				\
> +  GIT_ATTR_NOSYSTEM=1				\
> +  HOME="$(abs_top_srcdir)/tests/fake-home"	\
> +  XDG_CONFIG_HOME="$(abs_top_srcdir)/tests/fake-xgd-config-home"

As discussed on IRC yesterday (?), we can arrange to move these
variables directly in (guix tests git), which is the only place where
‘git’ is invoked.  That way, it can’t possibly interfere with other uses
of HOME, etc.

WDYT of something like the patch below?

Thanks,
Ludo’.

[Message part 2 (text/x-patch, inline)]
diff --git a/guix/tests/git.scm b/guix/tests/git.scm
index 21573ac14e..54d306fbba 100644
--- a/guix/tests/git.scm
+++ b/guix/tests/git.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2019 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2019, 2020 Ludovic Courtès <ludo <at> gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -30,6 +30,23 @@
 (define git-command
   (make-parameter "git"))
 
+(define (call-with-environment-variables variables thunk)
+  (let ((environment (environ)))
+    (dynamic-wind
+      (lambda ()
+        (for-each (match-lambda
+                    ((variable value)
+                     (setenv variable value)))
+                  variables))
+      thunk
+      (lambda ()
+        (environ environment)))))
+
+(define-syntax-rule (with-environment-variables variables exp ...)
+  "Evaluate EXP with the given environment VARIABLES set."
+  (call-with-environment-variables variables
+                                   (lambda () exp ...)))
+
 (define (populate-git-repository directory directives)
   "Initialize a new Git checkout and repository in DIRECTORY and apply
 DIRECTIVES.  Each element of DIRECTIVES is an sexp like:
@@ -41,8 +58,21 @@ Return DIRECTORY on success."
   ;; Note: As of version 0.2.0, Guile-Git lacks the necessary bindings to do
   ;; all this, so resort to the "git" command.
   (define (git command . args)
-    (apply invoke (git-command) "-C" directory
-           command args))
+    ;; Make sure Git doesn't rely on the user's config.
+    (call-with-temporary-directory
+     (lambda (home)
+       (call-with-output-file (string-append home "/.gitconfig")
+         (lambda (port)
+           (display "[user]
+  email = charlie <at> example.org\n  name = Charlie Guix\n"
+                    port)))
+
+       (with-environment-variables
+        `(("GIT_CONFIG_NOSYSTEM" "1")
+          ("GIT_ATTR_NOSYSTEM" "1")
+          ("HOME" ,home))
+        (apply invoke (git-command) "-C" directory
+               command args)))))
 
   (mkdir-p directory)
   (git "init")
@@ -59,7 +89,7 @@ Return DIRECTORY on success."
              (display (if (string? contents)
                           contents
                           (with-repository directory repository
-                            (contents repository)))
+                                           (contents repository)))
                       port)))
          (git "add" file)
          (loop rest)))

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sun, 19 Apr 2020 11:29:02 GMT) Full text and rfc822 format available.

Notification sent to Gábor Boskovits <boskovits <at> gmail.com>:
bug acknowledged by developer. (Sun, 19 Apr 2020 11:29:04 GMT) Full text and rfc822 format available.

Message #25 received at 37679-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Gábor Boskovits <boskovits <at> gmail.com>
Cc: 37679-done <at> debbugs.gnu.org
Subject: Re: bug#37679: Local git configuration interferes with testsuite
Date: Sun, 19 Apr 2020 13:28:35 +0200
Hi Gábor,

Ludovic Courtès <ludo <at> gnu.org> skribis:

> As discussed on IRC yesterday (?), we can arrange to move these
> variables directly in (guix tests git), which is the only place where
> ‘git’ is invoked.  That way, it can’t possibly interfere with other uses
> of HOME, etc.
>
> WDYT of something like the patch below?

I pushed it as 3c91f003416c9fb79af2dc8766a7f449aa03f839.

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 18 May 2020 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 3 years and 337 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.