From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id CP5xGUWN1l9UewAA0tVLHw (envelope-from ) for ; Sun, 13 Dec 2020 21:53:09 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id +PgwFUWN1l/TOAAAbx9fmQ (envelope-from ) for ; Sun, 13 Dec 2020 21:53:09 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 324CF9402A2 for ; Sun, 13 Dec 2020 21:53:09 +0000 (UTC) Received: from localhost ([::1]:43236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koZIi-0006i7-5e for larch@yhetil.org; Sun, 13 Dec 2020 16:53:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34708) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1koZIb-0006hr-VZ for bug-guix@gnu.org; Sun, 13 Dec 2020 16:53:01 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:39081) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1koZIb-00015c-Oe for bug-guix@gnu.org; Sun, 13 Dec 2020 16:53:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1koZIb-0001LT-LK for bug-guix@gnu.org; Sun, 13 Dec 2020 16:53:01 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#45187: git download defaults to origin/master Resent-From: Marius Bakke Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Sun, 13 Dec 2020 21:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45187 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: Kyle Meyer , Ricardo Wurmus Received: via spool by 45187-submit@debbugs.gnu.org id=B45187.16078963795148 (code B ref 45187); Sun, 13 Dec 2020 21:53:01 +0000 Received: (at 45187) by debbugs.gnu.org; 13 Dec 2020 21:52:59 +0000 Received: from localhost ([127.0.0.1]:50626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koZIY-0001Kx-MA for submit@debbugs.gnu.org; Sun, 13 Dec 2020 16:52:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41500) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1koZIX-0001KT-6X for 45187@debbugs.gnu.org; Sun, 13 Dec 2020 16:52:57 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:43102) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1koZIR-00010F-1t; Sun, 13 Dec 2020 16:52:51 -0500 Received: from host-37-191-236-253.lynet.no ([37.191.236.253]:44954 helo=localhost) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1koZIQ-0006ju-2f; Sun, 13 Dec 2020 16:52:50 -0500 From: Marius Bakke In-Reply-To: <87v9d8dk0r.fsf@kyleam.com> References: <878sa4vyxb.fsf@elephly.net> <87v9d8dk0r.fsf@kyleam.com> Date: Sun, 13 Dec 2020 22:52:46 +0100 Message-ID: <87lfe19xw1.fsf@gnu.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: 45187@debbugs.gnu.org Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.00 Authentication-Results: aspmx1.migadu.com; none X-Migadu-Queue-Id: 324CF9402A2 X-Spam-Score: -4.00 X-Migadu-Scanner: scn1.migadu.com X-TUID: OisvluR+t5ve --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Kyle Meyer skriver: > Ricardo Wurmus writes: > >> Importing https://github.com/immunogenomics/scpost with the CRAN >> importer fails, because the git repository does not have an >> origin/master branch. This repository only has a =E2=80=9Cmain=E2=80=9D= branch. >> >> Arguably, this shouldn=E2=80=99t matter, but (guix git) has the =E2=80= =9Cmaster=E2=80=9D name >> set up as the default. When cloning a repository it may be better to >> fetch everything and select the default branch =E2=80=94 whichever name = it may >> have. > > One option may be to use the remote HEAD symref. That's probably the > best indicator of what the primary branch is. In a clone, it doesn't > necessarily match HEAD on the remote, because users may change it to > another branch they're interested in, but that isn't really relevant to > these behind-the-scenes checkouts. > > Here's a quick and dirty demo that makes your reproducer work. A real > patch in this direction would of course look very different. Another quick and dirty patch to make this specific example work ... --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=diff Content-Transfer-Encoding: quoted-printable diff --git a/guix/git.scm b/guix/git.scm index ca77b9f54b..0c49859e42 100644 =2D-- a/guix/git.scm +++ b/guix/git.scm @@ -198,47 +198,11 @@ of SHA1 string." (last (string-split url #\/)) ".git" "") "-" (string-take sha1 7))) =20 =2D(define (resolve-reference repository ref) =2D "Resolve the branch, commit or tag specified by REF, and return the =2Dcorresponding Git object." =2D (let resolve ((ref ref)) =2D (match ref =2D (('branch . branch) =2D (let ((oid (reference-target =2D (branch-lookup repository branch BRANCH-REMOTE)))) =2D (object-lookup repository oid))) =2D (('commit . commit) =2D (let ((len (string-length commit))) =2D ;; 'object-lookup-prefix' appeared in Guile-Git in Mar. 2018, s= o we =2D ;; can't be sure it's available. Furthermore, 'string->oid' us= ed to =2D ;; read out-of-bounds when passed a string shorter than 40 char= s, =2D ;; which is why we delay calls to it below. =2D (if (< len 40) =2D (object-lookup-prefix repository (string->oid commit) len) =2D (object-lookup repository (string->oid commit))))) =2D (('tag-or-commit . str) =2D (if (or (> (string-length str) 40) =2D (not (string-every char-set:hex-digit str))) =2D (resolve `(tag . ,str)) ;definitely a tag =2D (catch 'git-error =2D (lambda () =2D (resolve `(tag . ,str))) =2D (lambda _ =2D ;; There's no such tag, so it must be a commit ID. =2D (resolve `(commit . ,str)))))) =2D (('tag . tag) =2D (let ((oid (reference-name->oid repository =2D (string-append "refs/tags/" tag))= )) =2D ;; OID may point to a "tag" object, but it can also point direc= tly =2D ;; to a "commit" object, as surprising as it may seem. Return = that =2D ;; object, whatever that is. =2D (object-lookup repository oid)))))) =2D (define (switch-to-ref repository ref) "Switch to REPOSITORY's branch, commit or tag specified by REF. Return = the OID (roughly the commit hash) corresponding to REF." (define obj =2D (resolve-reference repository ref)) + (revparse-single repository (cdr ref))) =20 (reset repository obj RESET_HARD) (object-id obj)) @@ -320,7 +284,7 @@ definitely available in REPOSITORY, false otherwise." =20 (define* (update-cached-checkout url #:key =2D (ref '(branch . "master")) + (ref '(branch . "HEAD")) recursive? (check-out? #t) starting-commit @@ -349,7 +313,9 @@ it unchanged." (('branch . branch) `(branch . ,(if (string-prefix? "origin/" branch) branch =2D (string-append "origin/" branch)))) + (if (string=3D? "HEAD" branch) + branch + (string-append "origin/" branch))))) (_ ref))) =20 (with-libgit2 @@ -370,8 +336,7 @@ it unchanged." ;; than letting users re-open the checkout later on. (let* ((oid (if check-out? (switch-to-ref repository canonical-ref) =2D (object-id =2D (resolve-reference repository canonical-ref))= )) + (revparse-single repository (cdr canonical-ref))= )) (new (and starting-commit (commit-lookup repository oid))) (old (and starting-commit @@ -395,7 +360,7 @@ it unchanged." (log-port (%make-void-port "w")) (cache-directory (%repository-cache-directory)) =2D (ref '(branch . "master"))) + (ref '(branch . "HEAD"))) "Return two values: the content of the git repository at URL copied into= a store directory and the sha1 of the top level commit in this directory. T= he reference to be checkout, once the repository is fetched, is specified by = REF. @@ -510,7 +475,7 @@ objects: 'ancestor (meaning that OLD is an ancestor of = NEW), 'descendant, or git-checkout make-git-checkout git-checkout? (url git-checkout-url) =2D (branch git-checkout-branch (default "master")) + (branch git-checkout-branch (default "HEAD")) (commit git-checkout-commit (default #f)) ;#f | tag | commit (recursive? git-checkout-recursive? (default #f))) =20 @@ -550,7 +515,7 @@ objects: 'ancestor (meaning that OLD is an ancestor of = NEW), 'descendant, or (($ url branch commit recursive?) (latest-repository-commit* url #:ref (if commit =2D `(tag-or-commit . ,commit) + `(commit . ,commit) `(branch . ,branch)) #:recursive? recursive? #:log-port (current-error-port))))) --=-=-= Content-Type: text/plain I wonder if there was a specific reason to not use 'revparse-single', and instead mostly reinvent it with (resolve-reference ...). This approach can be simplified further by deprecating the 'commit' and 'branch' fields, and just use a single reference string. --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFDBAEBCgAtFiEEu7At3yzq9qgNHeZDoqBt8qM6VPoFAl/WjS4PHG1hcml1c0Bn bnUub3JnAAoJEKKgbfKjOlT6FykIAIodtjZIVzwsRRb+7+1b7MRWQmnxQoy2QQs6 0exMoFaYIX/G3NOfE+RWVjcCgIyIc1iua18GKIe990+5uI8dGezOqBkg3/KqrDZc 90jfz2o/IoudaTKEcH3Hp52h4JDkRLnbhiB8b08pZ2NxzsiBWDSaQoWf21m5y0AD GBtZqcX/n3diNkoJ9giSx+xVLlnGqxKXzugTxmnGc/A5AwRLpa+vO7Z15EwCBZ3K ZYh6zGXkFP1hS08Gk41KPjG8JKbtuZx5zxu+iV7K9hXwptOrEepFX9Lio4YNpigi hB31CyW2ITV891Ut/nmqOgihRCChKvGOIwgPN7z6jiAd0gbjriM= =q4BH -----END PGP SIGNATURE----- --==-=-=--