diff --git a/ChangeLog.md b/ChangeLog.md index a92d94a4b9..928fe04cec 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -14,6 +14,8 @@ Behavior changes: Other enhancements: Bug fixes: +* Fix to allow dependencies on specific versions of local git repositories. See + [#4862](https://github.com/commercialhaskell/stack/pull/4862) ## v2.1.1.1 diff --git a/subs/pantry/ChangeLog.md b/subs/pantry/ChangeLog.md index 56de604439..a836c97c81 100644 --- a/subs/pantry/ChangeLog.md +++ b/subs/pantry/ChangeLog.md @@ -1,5 +1,14 @@ # Changelog for pantry +## Unreleased changes + +**Changes since 0.1.0.0** + +Bug fixes: + +* Fix to allow dependencies on specific versions of local git repositories. See + [#4862](https://github.com/commercialhaskell/stack/pull/4862) + ## 0.1.0.0 * Initial release diff --git a/subs/pantry/src/Pantry/Repo.hs b/subs/pantry/src/Pantry/Repo.hs index bc43728940..428f3b8450 100644 --- a/subs/pantry/src/Pantry/Repo.hs +++ b/subs/pantry/src/Pantry/Repo.hs @@ -159,12 +159,13 @@ withRepo -> RIO env a -> RIO env a withRepo repo@(Repo url commit repoType' _subdir) action = - withSystemTempDirectory "with-repo" $ - \tmpdir -> withWorkingDir tmpdir $ do - let suffix = "cloned" - dir = tmpdir suffix - - let (runCommand, resetArgs, submoduleArgs) = + withSystemTempDirectory "with-repo" $ \tmpDir -> do + -- Note we do not immediately change directories into the new temporary directory, + -- but instead wait until we have finished cloning the repo. This is because the + -- repo URL may be a relative path on the local filesystem, and we should interpret + -- it as relative to the current directory, not the temporary directory. + let dir = tmpDir "cloned" + (runCommand, resetArgs, submoduleArgs) = case repoType' of RepoGit -> ( runGitCommand @@ -176,23 +177,21 @@ withRepo repo@(Repo url commit repoType' _subdir) action = , ["update", "-C", T.unpack commit] , Nothing ) + fixANSIForWindows = + -- On Windows 10, an upstream issue with the `git clone` command means that + -- command clears, but does not then restore, the + -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The + -- folowing hack re-enables the lost ANSI-capability. + when osIsWindows $ void $ liftIO $ hSupportsANSIWithoutEmulation stdout logInfo $ "Cloning " <> display commit <> " from " <> display url - runCommand ("clone" : [T.unpack url, suffix]) - -- On Windows 10, an upstream issue with the `git clone` command means that - -- command clears, but does not then restore, the - -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The - -- folowing hack re-enables the lost ANSI-capability. - when osIsWindows $ void $ liftIO $ hSupportsANSIWithoutEmulation stdout + runCommand ["clone", T.unpack url, dir] + fixANSIForWindows created <- doesDirectoryExist dir unless created $ throwIO $ FailedToCloneRepo repo withWorkingDir dir $ do runCommand resetArgs traverse_ runCommand submoduleArgs - -- On Windows 10, an upstream issue with the `git submodule` command means - -- that command clears, but does not then restore, the - -- ENABLE_VIRTUAL_TERMINAL_PROCESSING flag for native terminals. The - -- folowing hack re-enables the lost ANSI-capability. - when osIsWindows $ void $ liftIO $ hSupportsANSIWithoutEmulation stdout + fixANSIForWindows action