From cd294552c547cdd18fe55e3d6e45a8569a6eceb5 Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Sat, 14 Nov 2020 17:43:33 +0800 Subject: [PATCH 1/2] Pass `--heads --tags` to `git ls-remote` to avoid fetching remote refs Don't pass when the revision begins with `refs` --- CHANGELOG.md | 3 +++ src/Update/Nix/FetchGit/Prefetch.hs | 19 +++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1bba5..70f9713 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## WIP +- Pass `--heads --tags` to `git ls-remote` to avoid fetching remote + refs. Don't pass when the revision begins with `refs` + ## [0.2.4] - 2020-11-11 - Add --dry-run option diff --git a/src/Update/Nix/FetchGit/Prefetch.hs b/src/Update/Nix/FetchGit/Prefetch.hs index 5a396ac..28696ce 100644 --- a/src/Update/Nix/FetchGit/Prefetch.hs +++ b/src/Update/Nix/FetchGit/Prefetch.hs @@ -103,16 +103,23 @@ getGitRevision repo revision = do | otherwise -> pure hash Nothing -> refute1 $ NoSuchRef (unRevision revision) --- | Run git ls-remote --sort=-v:refname and return the first match if any +-- | Run git ls-remote --heads --tags --sort=-v:refname and return the first +-- match if any. Use '--heads --tags' if the revision doesn't start with +-- 'refs/' to avoid getting 'remote' refs. gitLsRemotes :: Text -> Revision -> M (Maybe (Text, Text)) gitLsRemotes repo revision = do + let headsTags = if T.isPrefixOf "refs/" (unRevision revision) + then [] + else ["--heads", "--tags"] (exitCode, nsStdout, nsStderr) <- liftIO $ readProcessWithExitCode "git" - [ "ls-remote" - , "--sort=-v:refname" - , T.unpack repo - , T.unpack (unRevision revision) - ] + ( [ "ls-remote" + , "--sort=-v:refname" + , T.unpack repo + , T.unpack (unRevision revision) + ] + <> headsTags + ) "" case exitCode of ExitFailure e -> refute1 (NixPrefetchGitFailed e (pack nsStderr)) From 1b9787e14a0874835413a19fca89c33838c7e9de Mon Sep 17 00:00:00 2001 From: actions-bot <58130806+actions-bot@users.noreply.github.com> Date: Sat, 14 Nov 2020 09:46:17 +0000 Subject: [PATCH 2/2] v0.2.5 - Pass `--heads --tags` to `git ls-remote` to avoid fetching remote refs. Don't pass when the revision begins with `refs` --- CHANGELOG.md | 2 ++ package.yaml | 2 +- update-nix-fetchgit.cabal | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70f9713..992a7ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## WIP +## [0.2.5] - 2020-11-14 + - Pass `--heads --tags` to `git ls-remote` to avoid fetching remote refs. Don't pass when the revision begins with `refs` diff --git a/package.yaml b/package.yaml index cf281e7..154edd1 100644 --- a/package.yaml +++ b/package.yaml @@ -1,5 +1,5 @@ name: update-nix-fetchgit -version: "0.2.4" +version: "0.2.5" synopsis: A program to update fetchgit values in Nix expressions description: | This command-line utility is meant to be used by people maintaining Nix diff --git a/update-nix-fetchgit.cabal b/update-nix-fetchgit.cabal index e50f0e9..c73f0a8 100644 --- a/update-nix-fetchgit.cabal +++ b/update-nix-fetchgit.cabal @@ -5,7 +5,7 @@ cabal-version: 1.12 -- see: https://github.com/sol/hpack name: update-nix-fetchgit -version: 0.2.4 +version: 0.2.5 synopsis: A program to update fetchgit values in Nix expressions description: This command-line utility is meant to be used by people maintaining Nix expressions that fetch files from Git repositories. It automates the process