From e4066c04442f86a5a12d492d588e3e82b533053d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 15 Nov 2023 16:15:47 +0100 Subject: [PATCH 1/2] Fetch specific Git revisions This is more efficient, and necessary when using shallow=1 with a rev. --- src/libfetchers/git.cc | 5 ++++- tests/functional/fetchGit.sh | 4 +--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 7208a0b6d..2fd3fb41e 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -518,8 +518,11 @@ struct GitInputScheme : InputScheme if (doFetch) { try { - auto fetchRef = getAllRefsAttr(input) + auto fetchRef = + getAllRefsAttr(input) ? "refs/*" + : input.getRev() + ? input.getRev()->gitRev() : ref.compare(0, 5, "refs/") == 0 ? ref : ref == "HEAD" diff --git a/tests/functional/fetchGit.sh b/tests/functional/fetchGit.sh index c38cd27eb..4985c7764 100644 --- a/tests/functional/fetchGit.sh +++ b/tests/functional/fetchGit.sh @@ -51,9 +51,7 @@ git -C $repo add differentbranch git -C $repo commit -m 'Test2' git -C $repo checkout master devrev=$(git -C $repo rev-parse devtest) -out=$(nix eval --impure --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; }" 2>&1) || status=$? -[[ $status == 1 ]] -[[ $out =~ 'Cannot find Git revision' ]] +nix eval --impure --raw --expr "builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; }" [[ $(nix eval --raw --expr "builtins.readFile (builtins.fetchGit { url = file://$repo; rev = \"$devrev\"; allRefs = true; } + \"/differentbranch\")") = 'different file' ]] From 071f14a0bb25ffa8e5aaf8ad37031d205f49ef7d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 15 Nov 2023 17:17:07 +0100 Subject: [PATCH 2/2] Don't do shallow fetches over ssh --- src/libfetchers/git-utils.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libfetchers/git-utils.cc b/src/libfetchers/git-utils.cc index f554dcc5f..19eae0e1d 100644 --- a/src/libfetchers/git-utils.cc +++ b/src/libfetchers/git-utils.cc @@ -381,7 +381,9 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this }; git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; - opts.depth = shallow ? 1 : GIT_FETCH_DEPTH_FULL; + // FIXME: for some reason, shallow fetching over ssh barfs + // with "could not read from remote repository". + opts.depth = shallow && parseURL(url).scheme != "ssh" ? 1 : GIT_FETCH_DEPTH_FULL; opts.callbacks.payload = &act; opts.callbacks.sideband_progress = sidebandProgressCallback; opts.callbacks.transfer_progress = transferProgressCallback;