summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhillip Davis <phdavis1027@gmail.com>2026-06-10 15:36:19 -0400
committerLudovic Courtès <ludo@gnu.org>2026-07-02 19:17:18 +0200
commit8d27b1158de3cc1823d33847cb722722c769a27e (patch)
tree814e9eaec9c4254ca44f001d5e3e539f922da174 /tests
parent58943a859e54f9b2cf6ba9211beff0d02affe125 (diff)
git: Update submodules after switching cached checkout.
Previously, update-cached-checkout updated submodules before switching the cached parent checkout to the requested ref. A second recursive update could therefore update submodules according to the previously checked-out parent tree, then reset the parent to a ref whose gitlinks name different submodule commits, leaving submodule worktrees stale. * guix/git.scm (update-cached-checkout): Update submodules after switching to the requested ref. * tests/git.scm ("update-cached-checkout, recursive submodules follow ref"): New test. Signed-off-by: Ludovic Courtès <ludo@gnu.org> Fixes: guix/guix#7741 Merges: #9231
Diffstat (limited to 'tests')
-rw-r--r--tests/git.scm48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/git.scm b/tests/git.scm
index 6f910070519..35ddc884941 100644
--- a/tests/git.scm
+++ b/tests/git.scm
@@ -267,6 +267,54 @@
267 (and (string=? commit head) 267 (and (string=? commit head)
268 (string=? tag head))))))) 268 (string=? tag head)))))))
269 269
270(test-assert "update-cached-checkout, recursive submodules follow ref"
271 (call-with-temporary-directory
272 (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
280 '((add "file.txt" "v1\n")
281 (commit "submodule v1")
282 (add "file.txt" "v2\n")
283 (commit "submodule v2"))
284 (let ((sub-v1 (git-output "-C" sub "rev-parse" "HEAD~1"))
285 (sub-v2 (git-output "-C" sub "rev-parse" "HEAD")))
286 (with-temporary-git-repository main
287 `((add "root.txt" "root\n")
288 (commit "root")
289 (branch "primary")
290 (checkout "primary")
291 (submodule ,sub "modules/sub")
292 (submodule-checkout "modules/sub" ,sub-v1)
293 (commit "primary uses submodule v1")
294 (branch "release")
295 (checkout "release")
296 (submodule-checkout "modules/sub" ,sub-v2)
297 (commit "release uses submodule v2")
298 (checkout "primary"))
299 (let ((checkout1 commit1 relation1
300 (update-cached-checkout main
301 #:recursive? #t
302 #:cache-directory cache)))
303 (and
304 (string=? sub-v1
305 (git-output "-C"
306 (in-vicinity checkout1 "modules/sub")
307 "rev-parse" "HEAD"))
308 (let ((checkout2 commit2 relation2
309 (update-cached-checkout main
310 #:recursive? #t
311 #:ref '(branch . "release")
312 #:cache-directory cache)))
313 (string=? sub-v2
314 (git-output "-C"
315 (in-vicinity checkout2 "modules/sub")
316 "rev-parse" "HEAD")))))))))))
317
270(test-assert "update-cached-checkout, untracked files removed" 318(test-assert "update-cached-checkout, untracked files removed"
271 (call-with-temporary-directory 319 (call-with-temporary-directory
272 (lambda (cache) 320 (lambda (cache)