Skip to content

Commit 1f52963

Browse files
authored
Merge pull request #10587 from 9999years/git-quiet
VCS tests: Quieter output
2 parents 55ccc0a + ec2bb0c commit 1f52963

File tree

3 files changed

+34
-15
lines changed
  • cabal-install
    • src/Distribution/Client
    • tests/UnitTests/Distribution/Client
  • changelog.d

3 files changed

+34
-15
lines changed

cabal-install/src/Distribution/Client/VCS.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ vcsGit =
516516
-- is needed because sometimes `git submodule sync` does not actually
517517
-- update the submodule source URL. Detailed description here:
518518
-- https://git.coop/-/snippets/85
519-
git localDir ["submodule", "deinit", "--force", "--all"]
519+
git localDir $ ["submodule", "deinit", "--force", "--all"] ++ verboseArg
520520
let gitModulesDir = localDir </> ".git" </> "modules"
521521
gitModulesExists <- doesDirectoryExist gitModulesDir
522522
when gitModulesExists $

cabal-install/tests/UnitTests/Distribution/Client/VCS.hs

+21-14
Original file line numberDiff line numberDiff line change
@@ -897,16 +897,15 @@ vcsTestDriverGit
897897
gitconfigExists <- doesFileExist gitconfigPath
898898
unless gitconfigExists $ do
899899
writeFile gitconfigPath gitconfig
900-
git $ ["init"] ++ verboseArg
900+
gitQuiet ["init"]
901901
, vcsAddFile = \_ filename ->
902902
git ["add", filename]
903903
, vcsCommitChanges = \_state -> do
904-
git $
904+
gitQuiet
905905
[ "commit"
906906
, "--all"
907907
, "--message=a patch"
908908
]
909-
++ verboseArg
910909
commit <- git' ["rev-parse", "HEAD"]
911910
let commit' = takeWhile (not . isSpace) commit
912911
return (Just commit')
@@ -928,22 +927,22 @@ vcsTestDriverGit
928927
(||)
929928
<$> doesFileExist (repoRoot </> dest)
930929
<*> doesDirectoryExist (repoRoot </> dest)
931-
when destExists $ git ["rm", "-f", dest]
930+
when destExists $ gitQuiet ["rm", "--force", dest]
932931
-- If there is an old submodule git dir with the same name, remove it.
933932
-- It most likely has a different URL and `git submodule add` will fai.
934933
submoduleGitDirExists <- doesDirectoryExist $ submoduleGitDir dest
935934
when submoduleGitDirExists $ removeDirectoryRecursive (submoduleGitDir dest)
936-
git ["submodule", "add", source, dest]
937-
git ["submodule", "update", "--init", "--recursive", "--force"]
935+
gitQuiet ["submodule", "add", source, dest]
936+
gitQuiet ["submodule", "update", "--init", "--recursive", "--force"]
938937
, vcsSwitchBranch = \RepoState{allBranches} branchname -> do
939938
deinitAndRemoveCachedSubmodules
940939
unless (branchname `Map.member` allBranches) $
941-
git ["branch", branchname]
942-
git $ ["checkout", branchname] ++ verboseArg
940+
gitQuiet ["branch", branchname]
941+
gitQuiet ["checkout", branchname]
943942
updateSubmodulesAndCleanup
944943
, vcsCheckoutTag = Left $ \tagname -> do
945944
deinitAndRemoveCachedSubmodules
946-
git $ ["checkout", "--detach", "--force", tagname] ++ verboseArg
945+
gitQuiet ["checkout", "--detach", "--force", tagname]
947946
updateSubmodulesAndCleanup
948947
}
949948
where
@@ -981,24 +980,32 @@ vcsTestDriverGit
981980
]
982981
}
983982
}
983+
984984
gitInvocation args =
985985
(programInvocation (vcsProgram vcs') args)
986986
{ progInvokeCwd = Just repoRoot
987987
}
988+
988989
git = runProgramInvocation verbosity . gitInvocation
989990
git' = getProgramInvocationOutput verbosity . gitInvocation
991+
992+
gitQuiet [] = git []
993+
gitQuiet (cmd : args) = git (cmd : verboseArg ++ args)
994+
990995
verboseArg = ["--quiet" | verbosity < Verbosity.normal]
996+
991997
submoduleGitDir path = repoRoot </> ".git" </> "modules" </> path
992998
deinitAndRemoveCachedSubmodules = do
993-
git $ ["submodule", "deinit", "--force", "--all"] ++ verboseArg
999+
gitQuiet ["submodule", "deinit", "--force", "--all"]
9941000
let gitModulesDir = repoRoot </> ".git" </> "modules"
9951001
gitModulesExists <- doesDirectoryExist gitModulesDir
9961002
when gitModulesExists $ removeDirectoryRecursive gitModulesDir
9971003
updateSubmodulesAndCleanup = do
998-
git $ ["submodule", "sync", "--recursive"] ++ verboseArg
999-
git $ ["submodule", "update", "--init", "--recursive", "--force"] ++ verboseArg
1000-
git $ ["submodule", "foreach", "--recursive"] ++ verboseArg ++ ["git clean -ffxdq"]
1001-
git $ ["clean", "-ffxdq"] ++ verboseArg
1004+
gitQuiet ["submodule", "sync", "--recursive"]
1005+
gitQuiet ["submodule", "update", "--init", "--recursive", "--force"]
1006+
-- Note: We need to manually add `verboseArg` here so that the embedded `git clean` command includes it as well.
1007+
gitQuiet $ ["submodule", "foreach", "--recursive", "git clean -ffxdq"] ++ verboseArg
1008+
gitQuiet ["clean", "-ffxdq"]
10021009

10031010
type MTimeChange = Int
10041011

changelog.d/pr-10587

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
synopsis: "Quieter Git output"
3+
packages: [cabal-install]
4+
prs: 10587
5+
---
6+
7+
When `cabal` clones a Git repo for a `source-repository-package` listed in a
8+
`cabal.project`, it will run various commands to check out the correct
9+
revision, initialize submodules if they're present, and so on.
10+
11+
Now, `cabal` will pass `--quiet` to Git in more cases to help prevent
12+
cluttering command-line output.

0 commit comments

Comments
 (0)