diff mbox series

[bug#52722,v2,1/2] tests: Smarten up git repository testing framework.

Message ID 20211222102855.21822-1-attila@lendvai.name
State Accepted
Headers show
Series [bug#52722,v2,1/2] tests: Smarten up git repository testing framework. | expand

Checks

Context Check Description
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue
cbaines/applying patch fail View Laminar job
cbaines/issue success View issue

Commit Message

Attila Lendvai Dec. 22, 2021, 10:28 a.m. UTC
* guix/tests/git.scm (with-git-repository): New macro, exported.  It can be used
repeatedly inside a WITH-TEMPORARY-GIT-REPOSITORY.
(populate-git-repository): Extend the DSL with (ADD "some-noise"), (RESET
"[commit hash]"), (CHECKOUT "branch" ORPHAN).
---

as requested on IRC, resending it as two commits.

 guix/tests/git.scm | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

Comments

Leo Famulari Dec. 23, 2021, 5:40 p.m. UTC | #1
On Wed, Dec 22, 2021 at 11:28:55AM +0100, Attila Lendvai wrote:
> * guix/tests/git.scm (with-git-repository): New macro, exported.  It can be used
> repeatedly inside a WITH-TEMPORARY-GIT-REPOSITORY.
> (populate-git-repository): Extend the DSL with (ADD "some-noise"), (RESET
> "[commit hash]"), (CHECKOUT "branch" ORPHAN).

This commit introduced some ambiguity while importing the RESET
procedure:

WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)

We need to make sure that the correct reset is imported here. Can you
take a look and make any adjustments, if necessary?
Attila Lendvai Dec. 23, 2021, 9 p.m. UTC | #2
> WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)
>
> We need to make sure that the correct reset is imported here. Can you
> take a look and make any adjustments, if necessary?

i wonder why that is only a warning and not a full error.

but anyway, the fix is to only import let/ec. please change the
relevant line to:

  #:use-module ((ice-9 control) #:select (let/ec))

can you please commit this without going through the full
patch-submission cycle?

- attila
Leo Famulari Dec. 23, 2021, 11:49 p.m. UTC | #3
On Thu, Dec 23, 2021 at 09:00:10PM +0000, Attila Lendvai wrote:
> > WARNING: (guix tests git): `reset' imported from both (git) and (ice-9 control)
> >
> > We need to make sure that the correct reset is imported here. Can you
> > take a look and make any adjustments, if necessary?
> 
> i wonder why that is only a warning and not a full error.
> 
> but anyway, the fix is to only import let/ec. please change the
> relevant line to:
> 
>   #:use-module ((ice-9 control) #:select (let/ec))
> 
> can you please commit this without going through the full
> patch-submission cycle?

Sure, done as commit ba744faeb104a1132d9f6ed04fc296b23bc09334
diff mbox series

Patch

diff --git a/guix/tests/git.scm b/guix/tests/git.scm
index 69960284d9..76f5a8b937 100644
--- a/guix/tests/git.scm
+++ b/guix/tests/git.scm
@@ -26,6 +26,7 @@  (define-module (guix tests git)
   #:use-module (ice-9 control)
   #:export (git-command
             with-temporary-git-repository
+            with-git-repository
             find-commit))
 
 (define git-command
@@ -59,8 +60,9 @@  (define (git command . args)
         (apply invoke (git-command) "-C" directory
                command args)))))
 
-  (mkdir-p directory)
-  (git "init")
+  (unless (directory-exists? (string-append directory "/.git"))
+    (mkdir-p directory)
+    (git "init"))
 
   (let loop ((directives directives))
     (match directives
@@ -78,6 +80,9 @@  (define (git command . args)
                       port)))
          (git "add" file)
          (loop rest)))
+      ((('add file-name-and-content) rest ...)
+       (loop (cons `(add ,file-name-and-content ,file-name-and-content)
+                   rest)))
       ((('remove file) rest ...)
        (git "rm" "-f" file)
        (loop rest))
@@ -99,12 +104,18 @@  (define (git command . args)
       ((('checkout branch) rest ...)
        (git "checkout" branch)
        (loop rest))
+      ((('checkout branch 'orphan) rest ...)
+       (git "checkout" "--orphan" branch)
+       (loop rest))
       ((('merge branch message) rest ...)
        (git "merge" branch "-m" message)
        (loop rest))
       ((('merge branch message ('signer fingerprint)) rest ...)
        (git "merge" branch "-m" message
             (string-append "--gpg-sign=" fingerprint))
+       (loop rest))
+      ((('reset to) rest ...)
+       (git "reset" "--hard" to)
        (loop rest)))))
 
 (define (call-with-temporary-git-repository directives proc)
@@ -121,6 +132,14 @@  (define-syntax-rule (with-temporary-git-repository directory
                                       (lambda (directory)
                                         exp ...)))
 
+(define-syntax-rule (with-git-repository directory
+                                         directives exp ...)
+  "Evaluate EXP in a context where DIRECTORY is (further) populated as
+per DIRECTIVES."
+  (begin
+    (populate-git-repository directory directives)
+    exp ...))
+
 (define (find-commit repository message)
   "Return the commit in REPOSITORY whose message includes MESSAGE, a string."
   (let/ec return