summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tournier <zimon.toutoune@gmail.com>2026-07-03 13:27:22 +0200
committerSimon Tournier <zimon.toutoune@gmail.com>2026-07-06 12:00:49 +0200
commitf729199e7b7f8933ee73ac7cb7a234e62beef025 (patch)
tree3bef955c709f843a00b13e0ebd0c8ecfaee90c89
parent1178100657fba8f4b1ff23d7752c9d9b13c7d938 (diff)
tests: git: Avoid duplicated helper code.
* tests/git.scm (git): New procedure. ("update-cached-checkout, tag", "update-cached-checkout, recursive submodules follow ref", "update-cached-checkout, symref tag", "update-cached-checkout, symref pull-request"): Use it. Change-Id: I85aa14e729be1efe691418e74e37d6ae1fd3e633
-rw-r--r--tests/git.scm86
1 files changed, 30 insertions, 56 deletions
diff --git a/tests/git.scm b/tests/git.scm
index 12f17d4a7b9..2bb7cc712e6 100644
--- a/tests/git.scm
+++ b/tests/git.scm
@@ -31,6 +31,12 @@
31 31
32;; Test the (guix git) tools. 32;; Test the (guix git) tools.
33 33
34(define (git . args)
35 (let* ((pipe (apply open-pipe* OPEN_READ (git-command) args))
36 (str (string-trim-right (get-string-all pipe))))
37 (close-pipe pipe)
38 str))
39
34(test-begin "git") 40(test-begin "git")
35 41
36(test-assert "commit-difference, linear history" 42(test-assert "commit-difference, linear history"
@@ -248,41 +254,27 @@
248 (commit "Second commit") 254 (commit "Second commit")
249 (tag "v1.1" "release-1.1") 255 (tag "v1.1" "release-1.1")
250 (checkout "master")) 256 (checkout "master"))
251 (let* ((tag (let* ((pipe (open-pipe* OPEN_READ (git-command) 257 (let* ((tag (git "-C" directory
252 "-C" directory 258 "rev-parse" "v1.1^{}"))
253 "rev-parse" "v1.1^{}"))
254 (str (get-string-all pipe)))
255 (close-pipe pipe)
256 (string-trim-right str)))
257 (cached-directory commit relation 259 (cached-directory commit relation
258 (update-cached-checkout directory 260 (update-cached-checkout directory
259 #:ref '(tag . "v1.1") 261 #:ref '(tag . "v1.1")
260 #:cache-directory cache)) 262 #:cache-directory cache))
261 (head (let* ((pipe (open-pipe* OPEN_READ (git-command) 263 (head (git "-C" cached-directory
262 "-C" cached-directory 264 "rev-parse" "HEAD")))
263 "rev-parse" "HEAD"))
264 (str (get-string-all pipe)))
265 (close-pipe pipe)
266 (string-trim-right str))))
267 (and (string=? commit head) 265 (and (string=? commit head)
268 (string=? tag head))))))) 266 (string=? tag head)))))))
269 267
270(test-assert "update-cached-checkout, recursive submodules follow ref" 268(test-assert "update-cached-checkout, recursive submodules follow ref"
271 (call-with-temporary-directory 269 (call-with-temporary-directory
272 (lambda (cache) 270 (lambda (cache)
273 (define (git-output . args)
274 (let* ((pipe (apply open-pipe* OPEN_READ (git-command) args))
275 (str (string-trim-right (get-string-all pipe))))
276 (close-pipe pipe)
277 str))
278
279 (with-temporary-git-repository sub 271 (with-temporary-git-repository sub
280 '((add "file.txt" "v1\n") 272 '((add "file.txt" "v1\n")
281 (commit "submodule v1") 273 (commit "submodule v1")
282 (add "file.txt" "v2\n") 274 (add "file.txt" "v2\n")
283 (commit "submodule v2")) 275 (commit "submodule v2"))
284 (let ((sub-v1 (git-output "-C" sub "rev-parse" "HEAD~1")) 276 (let ((sub-v1 (git "-C" sub "rev-parse" "HEAD~1"))
285 (sub-v2 (git-output "-C" sub "rev-parse" "HEAD"))) 277 (sub-v2 (git "-C" sub "rev-parse" "HEAD")))
286 (with-temporary-git-repository main 278 (with-temporary-git-repository main
287 `((add "root.txt" "root\n") 279 `((add "root.txt" "root\n")
288 (commit "root") 280 (commit "root")
@@ -300,17 +292,15 @@
300 (update-cached-checkout main 292 (update-cached-checkout main
301 #:recursive? #t 293 #:recursive? #t
302 #:cache-directory cache)) 294 #:cache-directory cache))
303 (head-cached1 (git-output "-C" 295 (head-cached1 (git "-C" (in-vicinity checkout1 "modules/sub")
304 (in-vicinity checkout1 "modules/sub") 296 "rev-parse" "HEAD"))
305 "rev-parse" "HEAD"))
306 (checkout2 commit2 relation2 297 (checkout2 commit2 relation2
307 (update-cached-checkout main 298 (update-cached-checkout main
308 #:recursive? #t 299 #:recursive? #t
309 #:ref '(branch . "release") 300 #:ref '(branch . "release")
310 #:cache-directory cache)) 301 #:cache-directory cache))
311 (head-cached2 (git-output "-C" 302 (head-cached2 (git "-C" (in-vicinity checkout2 "modules/sub")
312 (in-vicinity checkout2 "modules/sub") 303 "rev-parse" "HEAD")))
313 "rev-parse" "HEAD")))
314 (and 304 (and
315 (string=? sub-v1 head-cached1) 305 (string=? sub-v1 head-cached1)
316 (string=? sub-v2 head-cached2))))))))) 306 (string=? sub-v2 head-cached2)))))))))
@@ -348,28 +338,20 @@
348 (commit "Second commit") 338 (commit "Second commit")
349 (tag "v1.1" "release-1.1") 339 (tag "v1.1" "release-1.1")
350 (checkout "master")) 340 (checkout "master"))
351 (let* ((tag-directory (let* ((pipe (open-pipe* OPEN_READ (git-command) 341 (let* ((tag-directory (git "-C" directory
352 "-C" directory 342 "rev-parse" "v1.1"))
353 "rev-parse" "v1.1"))
354 (str (get-string-all pipe)))
355 (close-pipe pipe)
356 (string-trim-right str)))
357 (cached-directory commit relation 343 (cached-directory commit relation
358 (update-cached-checkout directory 344 (update-cached-checkout directory
359 #:ref '(symref . "refs/tags/v1.1") 345 #:ref '(symref . "refs/tags/v1.1")
360 #:cache-directory cache)) 346 #:cache-directory cache))
361 (head-cached (let* ((pipe (open-pipe* OPEN_READ (git-command) 347 (head-cached (git "-C" cached-directory
362 "-C" cached-directory 348 ;; switch-to-ref doesn't dereference the Git object,
363 ;; switch-to-ref doesn't dereference the Git object, 349 ;; thus it points to a Git tag object.
364 ;; thus it points to a Git tag object. 350 ;; And HEAD points to a Git commit object.
365 ;; And HEAD points to a Git commit object. 351 ;; Hence, the check is against Git tag objects.
366 ;; Hence, the check is against Git tag objects. 352 ;; For the difference see:
367 ;; For the difference see: 353 ;; git show-ref --dereference v1.1
368 ;; git show-ref --dereference v1.1 354 "rev-parse" "v1.1")))
369 "rev-parse" "v1.1"))
370 (str (get-string-all pipe)))
371 (close-pipe pipe)
372 (string-trim-right str))))
373 (and (string=? commit head-cached) 355 (and (string=? commit head-cached)
374 (string=? tag-directory head-cached))))))) 356 (string=? tag-directory head-cached)))))))
375 357
@@ -387,22 +369,14 @@
387 (tag "v1.1" "release-1.1") 369 (tag "v1.1" "release-1.1")
388 (symbolic-ref "refs/pull/1/head" "refs/heads/develop") 370 (symbolic-ref "refs/pull/1/head" "refs/heads/develop")
389 (checkout "master")) 371 (checkout "master"))
390 (let* ((head-directory (let* ((pipe (open-pipe* OPEN_READ (git-command) 372 (let* ((head-directory (git "-C" directory
391 "-C" directory 373 "rev-parse" "refs/pull/1/head"))
392 "rev-parse" "refs/pull/1/head"))
393 (str (get-string-all pipe)))
394 (close-pipe pipe)
395 (string-trim-right str)))
396 (cached-directory commit relation 374 (cached-directory commit relation
397 (update-cached-checkout directory 375 (update-cached-checkout directory
398 #:ref '(symref . "refs/pull/1/head") 376 #:ref '(symref . "refs/pull/1/head")
399 #:cache-directory cache)) 377 #:cache-directory cache))
400 (head-cached (let* ((pipe (open-pipe* OPEN_READ (git-command) 378 (head-cached (git "-C" cached-directory
401 "-C" cached-directory 379 "rev-parse" "HEAD")))
402 "rev-parse" "HEAD"))
403 (str (get-string-all pipe)))
404 (close-pipe pipe)
405 (string-trim-right str))))
406 (and (string=? commit head-directory) 380 (and (string=? commit head-directory)
407 (string=? head-cached head-directory))))))) 381 (string=? head-cached head-directory)))))))
408 382