Skip to content

Commit

Permalink
Do not ask overwrite questions for empty dirs
Browse files Browse the repository at this point in the history
See #9150, blank projects need not to ask permission to
overwrite files.
  • Loading branch information
ffaf1 committed Jul 29, 2023
1 parent a40876d commit cca7fe6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
14 changes: 10 additions & 4 deletions cabal-install/src/Distribution/Client/Init/Interactive/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,16 @@ genTestTarget flags pkgs = initializeTestSuitePrompt flags >>= go

overwritePrompt :: Interactive m => InitFlags -> m Bool
overwritePrompt flags = do
isOverwrite <- getOverwrite flags
promptYesNo
"Do you wish to overwrite existing files (backups will be created) (y/n)"
(DefaultPrompt isOverwrite)
con <- getPackageDir flags >>= listDirectory

-- Do not ask useless overwrite question if directory is empty.
if null con
then return False
else do
isOverwrite <- getOverwrite flags
promptYesNo
"Do you wish to overwrite existing files (backups will be created) (y/n)"
(DefaultPrompt isOverwrite)

cabalVersionPrompt :: Interactive m => InitFlags -> m CabalSpecVersion
cabalVersionPrompt flags = getCabalVersion flags $ do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# cabal init
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Test.Cabal.Prelude

main = cabalTest $ do
tmpDir <- testTmpDir <$> getTestEnv
withDirectory tmpDir $ do
res <- cabalWithStdin "init"
["-i"]
(replicate 20 '\n') -- Default all the way down.
assertOutputDoesNotContain "backups will be created" res

4 changes: 4 additions & 0 deletions changelog.d/pr-9155
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
synopsis: Do not ask overwrite permissions on blank project
packages: cabal-install
prs: #9155
issues: #9150

0 comments on commit cca7fe6

Please sign in to comment.