Skip to content

Commit

Permalink
Merge pull request #50 from expipiplus1/joe-refs
Browse files Browse the repository at this point in the history
Pass `--heads --tags` to `git ls-remote` to avoid fetching remote refs
  • Loading branch information
expipiplus1 authored Nov 14, 2020
2 parents 52d41bd + 1b9787e commit 7e9fdb1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## 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`

## [0.2.4] - 2020-11-11

- Add --dry-run option
Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
19 changes: 13 additions & 6 deletions src/Update/Nix/FetchGit/Prefetch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion update-nix-fetchgit.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e9fdb1

Please sign in to comment.