Skip to content

Commit 18a040a

Browse files
9999yearsMikolaj
authored andcommitted
VCS: Use FETCH_HEAD actually
1 parent 5185598 commit 18a040a

File tree

1 file changed

+31
-1
lines changed
  • cabal-install/src/Distribution/Client

1 file changed

+31
-1
lines changed

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,38 @@ vcsGit =
539539
ref <- case srpBranch `mplus` srpTag of
540540
Nothing -> pure "HEAD"
541541
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.
542572
git localDir ("fetch" : verboseArg ++ ["origin", ref])
543-
pure ref
573+
pure "FETCH_HEAD"
544574

545575
-- Then, reset to the appropriate ref.
546576
git localDir $

0 commit comments

Comments
 (0)