@@ -96,6 +96,7 @@ import qualified Data.List as List
96
96
import qualified Data.Map as Map
97
97
import System.Directory
98
98
( doesDirectoryExist
99
+ , doesFileExist
99
100
, removeDirectoryRecursive
100
101
, removePathForcibly
101
102
)
@@ -468,11 +469,18 @@ vcsGit =
468
469
[programInvocation prog cloneArgs]
469
470
-- And if there's a tag, we have to do that in a second step:
470
471
++ [git (resetArgs tag) | tag <- maybeToList (srpTag repo)]
471
- ++ [ git ( [" submodule" , " sync" , " --recursive" ] ++ verboseArg)
472
- , git ( [" submodule" , " update" , " --init" , " --force" , " --recursive" ] ++ verboseArg)
472
+ ++ [ whenGitModulesExists $ git $ [" submodule" , " sync" , " --recursive" ] ++ verboseArg
473
+ , whenGitModulesExists $ git $ [" submodule" , " update" , " --init" , " --force" , " --recursive" ] ++ verboseArg
473
474
]
474
475
where
475
476
git args = (programInvocation prog args){progInvokeCwd = Just destdir}
477
+
478
+ gitModulesPath = destdir </> " .gitmodules"
479
+ whenGitModulesExists invocation =
480
+ invocation
481
+ { progInvokeWhen = doesFileExist gitModulesPath
482
+ }
483
+
476
484
cloneArgs =
477
485
[" clone" , srcuri, destdir]
478
486
++ branchArgs
@@ -516,29 +524,38 @@ vcsGit =
516
524
-- is needed because sometimes `git submodule sync` does not actually
517
525
-- update the submodule source URL. Detailed description here:
518
526
-- https://git.coop/-/snippets/85
519
- git localDir [" submodule" , " deinit" , " --force" , " --all" ]
520
- let gitModulesDir = localDir </> " .git" </> " modules"
521
- gitModulesExists <- doesDirectoryExist gitModulesDir
522
- when gitModulesExists $
527
+ let dotGitModulesPath = localDir </> " .git" </> " modules"
528
+ gitModulesPath = localDir </> " .gitmodules"
529
+
530
+ -- Remove any `.git/modules` if they exist.
531
+ dotGitModulesExists <- doesDirectoryExist dotGitModulesPath
532
+ when dotGitModulesExists $ do
533
+ git localDir $ [" submodule" , " deinit" , " --force" , " --all" ] ++ verboseArg
523
534
if buildOS == Windows
524
535
then do
525
536
-- Windows can't delete some git files #10182
526
537
void $
527
538
Process. createProcess_ " attrib" $
528
539
Process. shell $
529
- " attrib -s -h -r " <> gitModulesDir <> " \\ *.* /s /d"
540
+ " attrib -s -h -r " <> dotGitModulesPath <> " \\ *.* /s /d"
530
541
531
542
catch
532
- (removePathForcibly gitModulesDir)
533
- (\ e -> if isPermissionError e then removePathForcibly gitModulesDir else throw e)
534
- else removeDirectoryRecursive gitModulesDir
543
+ (removePathForcibly dotGitModulesPath)
544
+ (\ e -> if isPermissionError e then removePathForcibly dotGitModulesPath else throw e)
545
+ else removeDirectoryRecursive dotGitModulesPath
546
+
535
547
when (resetTarget /= " HEAD" ) $ do
536
548
git localDir fetchArgs -- first fetch the tag if needed
537
549
git localDir setTagArgs
538
550
git localDir resetArgs -- only then reset to the commit
539
- git localDir $ [" submodule" , " sync" , " --recursive" ] ++ verboseArg
540
- git localDir $ [" submodule" , " update" , " --force" , " --init" , " --recursive" ] ++ verboseArg
541
- git localDir $ [" submodule" , " foreach" , " --recursive" ] ++ verboseArg ++ [" git clean -ffxdq" ]
551
+
552
+ -- We need to check if `.gitmodules` exists _after_ the `git reset` call.
553
+ gitModulesExists <- doesFileExist gitModulesPath
554
+ when gitModulesExists $ do
555
+ git localDir $ [" submodule" , " sync" , " --recursive" ] ++ verboseArg
556
+ git localDir $ [" submodule" , " update" , " --force" , " --init" , " --recursive" ] ++ verboseArg
557
+ git localDir $ [" submodule" , " foreach" , " --recursive" ] ++ verboseArg ++ [" git clean -ffxdq" ]
558
+
542
559
git localDir $ [" clean" , " -ffxdq" ]
543
560
where
544
561
git :: FilePath -> [String ] -> IO ()
0 commit comments