Skip to content

Commit

Permalink
Pass --heads --tags to git ls-remote to avoid fetching remote refs
Browse files Browse the repository at this point in the history
Don't pass when the revision begins with `refs`
  • Loading branch information
expipiplus1 committed Nov 14, 2020
1 parent 52d41bd commit cd29455
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit cd29455

Please sign in to comment.