Skip to content

Commit c12168e

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

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
@@ -491,9 +491,6 @@ vcsGit =
491491
resetArgs tag = "reset" : verboseArg ++ ["--hard", tag, "--"]
492492
verboseArg = ["--quiet" | verbosity < Verbosity.normal]
493493

494-
-- Note: No --depth=1 for vcsCloneRepo since that is used for `cabal get -s`,
495-
-- whereas `vcsSyncRepo` is used for source-repository-package where we do want shallow clones.
496-
497494
vcsSyncRepos
498495
:: Verbosity
499496
-> ConfiguredProgram
@@ -546,44 +543,9 @@ vcsGit =
546543
(\e -> if isPermissionError e then removePathForcibly dotGitModulesPath else throw e)
547544
else removeDirectoryRecursive dotGitModulesPath
548545

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

611573
cloneArgs =
612-
["clone", "--depth=1", "--no-checkout", loc, localDir]
574+
["clone", "--no-checkout", loc, localDir]
613575
++ case peer of
614576
Nothing -> []
615577
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)