@@ -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
@@ -518,22 +526,25 @@ vcsGit =
518
526
-- is needed because sometimes `git submodule sync` does not actually
519
527
-- update the submodule source URL. Detailed description here:
520
528
-- https://git.coop/-/snippets/85
521
- git localDir $ [" submodule" , " deinit" , " --force" , " --all" ] ++ verboseArg
522
- let gitModulesDir = localDir </> " .git" </> " modules"
523
- gitModulesExists <- doesDirectoryExist gitModulesDir
524
- when gitModulesExists $
529
+ let dotGitModulesPath = localDir </> " .git" </> " modules"
530
+ gitModulesPath = localDir </> " .gitmodules"
531
+
532
+ -- Remove any `.git/modules` if they exist.
533
+ dotGitModulesExists <- doesDirectoryExist dotGitModulesPath
534
+ when dotGitModulesExists $ do
535
+ git localDir $ [" submodule" , " deinit" , " --force" , " --all" ] ++ verboseArg
525
536
if buildOS == Windows
526
537
then do
527
538
-- Windows can't delete some git files #10182
528
539
void $
529
540
Process. createProcess_ " attrib" $
530
541
Process. shell $
531
- " attrib -s -h -r " <> gitModulesDir <> " \\ *.* /s /d"
542
+ " attrib -s -h -r " <> dotGitModulesPath <> " \\ *.* /s /d"
532
543
533
544
catch
534
- (removePathForcibly gitModulesDir )
535
- (\ e -> if isPermissionError e then removePathForcibly gitModulesDir else throw e)
536
- else removeDirectoryRecursive gitModulesDir
545
+ (removePathForcibly dotGitModulesPath )
546
+ (\ e -> if isPermissionError e then removePathForcibly dotGitModulesPath else throw e)
547
+ else removeDirectoryRecursive dotGitModulesPath
537
548
538
549
-- If we want a particular branch or tag, fetch it.
539
550
ref <- case srpBranch `mplus` srpTag of
@@ -581,9 +592,13 @@ vcsGit =
581
592
, " --"
582
593
]
583
594
584
- git localDir $ [" submodule" , " sync" , " --recursive" ] ++ verboseArg
585
- git localDir $ [" submodule" , " update" , " --force" , " --init" , " --recursive" ] ++ verboseArg
586
- git localDir $ [" submodule" , " foreach" , " --recursive" ] ++ verboseArg ++ [" git clean -ffxdq" ]
595
+ -- We need to check if `.gitmodules` exists _after_ the `git reset` call.
596
+ gitModulesExists <- doesFileExist gitModulesPath
597
+ when gitModulesExists $ do
598
+ git localDir $ [" submodule" , " sync" , " --recursive" ] ++ verboseArg
599
+ git localDir $ [" submodule" , " update" , " --force" , " --init" , " --recursive" ] ++ verboseArg
600
+ git localDir $ [" submodule" , " foreach" , " --recursive" ] ++ verboseArg ++ [" git clean -ffxdq" ]
601
+
587
602
git localDir $ [" clean" , " -ffxdq" ]
588
603
where
589
604
git :: FilePath -> [String ] -> IO ()
0 commit comments