Skip to content

Commit a66bc9e

Browse files
committed
Do not use shallow clones for source-repository-packages
Fixes #10605 Includes a regression test.
1 parent 8cc49d9 commit a66bc9e

File tree

6 files changed

+36
-42
lines changed

6 files changed

+36
-42
lines changed

cabal-install/src/Distribution/Client/VCS.hs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -483,9 +483,6 @@ vcsGit =
483483
resetArgs tag = "reset" : verboseArg ++ ["--hard", tag, "--"]
484484
verboseArg = ["--quiet" | verbosity < Verbosity.normal]
485485

486-
-- Note: No --depth=1 for vcsCloneRepo since that is used for `cabal get -s`,
487-
-- whereas `vcsSyncRepo` is used for source-repository-package where we do want shallow clones.
488-
489486
vcsSyncRepos
490487
:: Verbosity
491488
-> ConfiguredProgram
@@ -535,44 +532,9 @@ vcsGit =
535532
(\e -> if isPermissionError e then removePathForcibly gitModulesDir else throw e)
536533
else removeDirectoryRecursive gitModulesDir
537534

538-
-- If we want a particular branch or tag, fetch it.
539-
ref <- case srpBranch `mplus` srpTag of
540-
Nothing -> pure "HEAD"
541-
Just ref -> do
542-
-- /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
543-
-- /!\ MULTIPLE HOURS HAVE BEEN LOST HERE!! /!\
544-
-- /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\ /!\
545-
--
546-
-- If you run `git fetch origin MY_TAG`, then the tag _will_ be
547-
-- fetched, but no local ref (e.g. `refs/tags/MY_TAG`) will be
548-
-- created.
549-
--
550-
-- This means that doing `git fetch origin MY_TAG && git reset --hard
551-
-- MY_TAG` will fail with a message like `unknown revision MY_TAG`.
552-
--
553-
-- There are two ways around this:
554-
--
555-
-- 1. Provide a refmap explicitly:
556-
--
557-
-- git fetch --refmap="+refs/tags/*:refs/tags/*" origin MYTAG
558-
--
559-
-- This tells Git to create local tags matching remote tags. It's
560-
-- not in the default refmap so you need to set it explicitly.
561-
-- (You can also set it with `git config set --local
562-
-- remote.origin.fetch ...`.)
563-
--
564-
-- 2. Use `FETCH_HEAD` directly: Git writes a `FETCH_HEAD` ref
565-
-- containing the commit that was just fetched. This feels a bit
566-
-- nasty but seems to work reliably, even if nothing was fetched.
567-
-- (That is, deleting `FETCH_HEAD` and re-running a `git fetch`
568-
-- command will succesfully recreate the `FETCH_HEAD` ref.)
569-
--
570-
-- Option 2 is what Cabal has done historically, and we're keeping it
571-
-- for now. Option 1 is possible but seems to have little benefit.
572-
git localDir ("fetch" : verboseArg ++ ["origin", ref])
573-
pure "FETCH_HEAD"
574-
575-
-- Then, reset to the appropriate ref.
535+
-- If we want a particular branch or tag, reset to it.
536+
-- Otherwise, check out the default `HEAD`.
537+
let ref = fromMaybe "HEAD" $ srpBranch `mplus` srpTag
576538
git localDir $
577539
"reset"
578540
: verboseArg
@@ -594,7 +556,7 @@ vcsGit =
594556
}
595557

596558
cloneArgs =
597-
["clone", "--depth=1", "--no-checkout", loc, localDir]
559+
["clone", "--no-checkout", loc, localDir]
598560
++ case peer of
599561
Nothing -> []
600562
Just peerLocalDir -> ["--reference", peerLocalDir]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# cabal v2-build
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- puppy-1.0 (lib) (first run)
8+
Configuring library for puppy-1.0...
9+
Preprocessing library for puppy-1.0...
10+
Building library for puppy-1.0...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
packages: .
2+
3+
-- Regression for https://github.com/haskell/cabal/issues/10605
4+
source-repository-package
5+
type: git
6+
location: https://github.com/haskell/bytestring
7+
-- Uses an abbreviated commit hash (not a tag! why was this ever accepted???)
8+
tag: c73756a
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import Test.Cabal.Prelude
2+
3+
main = cabalTest $ do
4+
cabal "v2-build" []
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cabal-version: 3.0
2+
name: puppy
3+
version: 1.0
4+
5+
library
6+
default-language: Haskell2010
7+
hs-source-dirs: src
8+
build-depends: base
9+
exposed-modules: Puppy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Puppy () where

0 commit comments

Comments
 (0)