@@ -69,7 +69,7 @@ std::optional<std::string> readHead(const Path & path)
6969
7070 std::string_view line = output;
7171 line = line.substr (0 , line.find (" \n " ));
72- if (const auto parseResult = git::parseLsRemoteLine (line)) {
72+ if (const auto parseResult = git::parseLsRemoteLine (line); parseResult && parseResult-> reference == " HEAD " ) {
7373 switch (parseResult->kind ) {
7474 case git::LsRemoteRefLine::Kind::Symbolic:
7575 debug (" resolved HEAD ref '%s' for repo '%s'" , parseResult->target , path);
@@ -459,8 +459,14 @@ struct GitInputScheme : InputScheme
459459 url);
460460 }
461461 repoInfo.location = std::filesystem::absolute (url.path );
462- } else
462+ } else {
463+ if (url.scheme == " file" )
464+ /* Query parameters are meaningless for file://, but
465+ Git interprets them as part of the file name. So get
466+ rid of them. */
467+ url.query .clear ();
463468 repoInfo.location = url;
469+ }
464470
465471 // If this is a local directory and no ref or revision is
466472 // given, then allow the use of an unclean working tree.
@@ -605,16 +611,16 @@ struct GitInputScheme : InputScheme
605611 try {
606612 auto fetchRef =
607613 getAllRefsAttr (input)
608- ? " refs/*"
614+ ? " refs/*:refs/* "
609615 : input.getRev ()
610616 ? input.getRev ()->gitRev ()
611617 : ref.compare (0 , 5 , " refs/" ) == 0
612- ? ref
618+ ? fmt ( " %1%:%1% " , ref)
613619 : ref == " HEAD"
614620 ? ref
615- : " refs/heads/" + ref;
621+ : fmt ( " %1%:%1% " , " refs/heads/" + ref) ;
616622
617- repo->fetch (repoUrl.to_string (), fmt ( " %s:%s " , fetchRef, fetchRef) , getShallowAttr (input));
623+ repo->fetch (repoUrl.to_string (), fetchRef, getShallowAttr (input));
618624 } catch (Error & e) {
619625 if (!std::filesystem::exists (localRefFile)) throw ;
620626 logError (e.info ());
0 commit comments