Skip to content

Commit

Permalink
Merge pull request #4862 from amalloy/master
Browse files Browse the repository at this point in the history
Don't change directories when cloning a repo
  • Loading branch information
snoyberg authored Jun 19, 2019
2 parents 888aeec + 0e3d160 commit 22fe3b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions subs/pantry/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
33 changes: 16 additions & 17 deletions subs/pantry/src/Pantry/Repo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

0 comments on commit 22fe3b9

Please sign in to comment.