From 41d7946dee6f1147884092d66f75387df47b5a2d Mon Sep 17 00:00:00 2001
From: Bodigrim <andrew.lelechenko@gmail.com>
Date: Wed, 20 Sep 2023 21:22:33 +0100
Subject: [PATCH] Fix overzelous warnOnTwoConfigs

---
 .../src/Distribution/Client/Config.hs         | 24 ++++++++++---------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/cabal-install/src/Distribution/Client/Config.hs b/cabal-install/src/Distribution/Client/Config.hs
index a590c339cd..9bf3ad40d7 100644
--- a/cabal-install/src/Distribution/Client/Config.hs
+++ b/cabal-install/src/Distribution/Client/Config.hs
@@ -731,17 +731,19 @@ initialSavedConfig = do
 warnOnTwoConfigs :: Verbosity -> IO ()
 warnOnTwoConfigs verbosity = do
   defaultDir <- getAppUserDataDirectory "cabal"
-  dotCabalExists <- doesDirectoryExist defaultDir
-  xdgCfg <- getXdgDirectory XdgConfig ("cabal" </> "config")
-  xdgCfgExists <- doesFileExist xdgCfg
-  when (dotCabalExists && xdgCfgExists) $
-    warn verbosity $
-      "Both "
-        <> defaultDir
-        <> " and "
-        <> xdgCfg
-        <> " exist - ignoring the former.\n"
-        <> "It is advisable to remove one of them. In that case, we will use the remaining one by default (unless '$CABAL_DIR' is explicitly set)."
+  xdgCfgDir <- getXdgDirectory XdgConfig "cabal"
+  when (defaultDir /= xdgCfgDir) $ do
+    dotCabalExists <- doesDirectoryExist defaultDir
+    let xdgCfg = xdgCfgDir </> "config"
+    xdgCfgExists <- doesFileExist xdgCfg
+    when (dotCabalExists && xdgCfgExists) $
+      warn verbosity $
+        "Both "
+          <> defaultDir
+          <> " and "
+          <> xdgCfg
+          <> " exist - ignoring the former.\n"
+          <> "It is advisable to remove one of them. In that case, we will use the remaining one by default (unless '$CABAL_DIR' is explicitly set)."
 
 -- | If @CABAL\_DIR@ is set, return @Just@ its value. Otherwise, if
 -- @~/.cabal@ exists and @$XDG_CONFIG_HOME/cabal/config@ does not
-- 
GitLab