From ec2bb0c02490f11b4e62d238e6bae1e739d93613 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Thu, 21 Nov 2024 12:35:31 -0800 Subject: [PATCH] VCS tests: Quieter output This prevents the tests from spamming lots of output, making it easier to watch them as they run. Before: ``` check VCS test framework: 10% warning: refname 'd6077f476a7c17fe8528e62688a19cc5bddbfbdc' is ambiguous. Git normally never creates a ref that ends with 40 hex characters because it will be ignored when you just specify 40-hex. These refs may be created by mistake. For example, git switch -c $br $(git rev-parse ...) where "$br" is somehow empty and a 40-hex ref is created. Please examine these refs and maybe delete them. Turn this message off by running "git config advice.objectNameWarning false" rm 'file/C' Cloning into '/private/var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/T/vcstest-64269/src/file/C'... done. Submodule path 'file/C': checked out '210af0166ade8b306b425782305b8c6e910aa2c0' Cloning into '/private/var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/T/vcstest-64267/src/file/D'... done. Submodule path 'file/D': checked out '95b580ef06aec22b38f6e0a5c3305d5c293669a0' branch 'branch_D' set up to track 'main'. branch 'branch_C' set up to track 'main'. rm 'file/C' Cloning into '/private/var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/T/vcstest-64269/src/file/C'... done. rm 'file/D' Submodule path 'file/C': checked out 'ee47ffdda57945d841bc7f59ea72a78043c4ac02' Cloning into '/private/var/folders/z5/fclwwdms3r1gq4k4p3pkvvc00000gn/T/vcstest-64267/src/file/D'... done. Submodule path 'file/D': checked out '23d9b5f39ae56c429dd9498d42338d27ea4e6545' ``` After: ``` UnitTests.Distribution.Client.VCS git check VCS test framework: warning: --depth is ignored in local clones; use file:// instead. warning: refname 'fbfe708a98c79a7c97e83609275b0f604f26e18b' is ambiguous. Git normally never creates a ref that ends with 40 hex characters because it will be ignored when you just specify 40-hex. These refs may be created by mistake. For example, git switch -c $br $(git rev-parse ...) where "$br" is somehow empty and a 40-hex ref is created. Please examine these refs and maybe delete them. Turn this message off by running "git config advice.objectNameWarning false" warning: --depth is ignored in local clones; use file:// instead. warning: --depth is ignored in local clones; use file:// instead. warning: refname 'dc2abca0fd032b5cdd8904e6931679b4d6e6b25b' is ambiguous. Git normally never creates a ref that ends with 40 hex characters because it will be ignored when you just specify 40-hex. These refs may be created by mistake. For example, git switch -c $br $(git rev-parse ...) where "$br" is somehow empty and a 40-hex ref is created. Please examine these refs and maybe delete them. Turn this message off by running "git config advice.objectNameWarning false" ``` These warnings require semantic changes which will come in a separate PR. --- cabal-install/src/Distribution/Client/VCS.hs | 2 +- .../UnitTests/Distribution/Client/VCS.hs | 35 +++++++++++-------- changelog.d/pr-10587 | 12 +++++++ 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 changelog.d/pr-10587 diff --git a/cabal-install/src/Distribution/Client/VCS.hs b/cabal-install/src/Distribution/Client/VCS.hs index 029e190a790..33b7078bd79 100644 --- a/cabal-install/src/Distribution/Client/VCS.hs +++ b/cabal-install/src/Distribution/Client/VCS.hs @@ -516,7 +516,7 @@ vcsGit = -- is needed because sometimes `git submodule sync` does not actually -- update the submodule source URL. Detailed description here: -- https://git.coop/-/snippets/85 - git localDir ["submodule", "deinit", "--force", "--all"] + git localDir $ ["submodule", "deinit", "--force", "--all"] ++ verboseArg let gitModulesDir = localDir ".git" "modules" gitModulesExists <- doesDirectoryExist gitModulesDir when gitModulesExists $ diff --git a/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs b/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs index 9b9507d13e9..65ef835837a 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/VCS.hs @@ -897,16 +897,15 @@ vcsTestDriverGit gitconfigExists <- doesFileExist gitconfigPath unless gitconfigExists $ do writeFile gitconfigPath gitconfig - git $ ["init"] ++ verboseArg + gitQuiet ["init"] , vcsAddFile = \_ filename -> git ["add", filename] , vcsCommitChanges = \_state -> do - git $ + gitQuiet [ "commit" , "--all" , "--message=a patch" ] - ++ verboseArg commit <- git' ["rev-parse", "HEAD"] let commit' = takeWhile (not . isSpace) commit return (Just commit') @@ -928,22 +927,22 @@ vcsTestDriverGit (||) <$> doesFileExist (repoRoot dest) <*> doesDirectoryExist (repoRoot dest) - when destExists $ git ["rm", "-f", dest] + when destExists $ gitQuiet ["rm", "--force", dest] -- If there is an old submodule git dir with the same name, remove it. -- It most likely has a different URL and `git submodule add` will fai. submoduleGitDirExists <- doesDirectoryExist $ submoduleGitDir dest when submoduleGitDirExists $ removeDirectoryRecursive (submoduleGitDir dest) - git ["submodule", "add", source, dest] - git ["submodule", "update", "--init", "--recursive", "--force"] + gitQuiet ["submodule", "add", source, dest] + gitQuiet ["submodule", "update", "--init", "--recursive", "--force"] , vcsSwitchBranch = \RepoState{allBranches} branchname -> do deinitAndRemoveCachedSubmodules unless (branchname `Map.member` allBranches) $ - git ["branch", branchname] - git $ ["checkout", branchname] ++ verboseArg + gitQuiet ["branch", branchname] + gitQuiet ["checkout", branchname] updateSubmodulesAndCleanup , vcsCheckoutTag = Left $ \tagname -> do deinitAndRemoveCachedSubmodules - git $ ["checkout", "--detach", "--force", tagname] ++ verboseArg + gitQuiet ["checkout", "--detach", "--force", tagname] updateSubmodulesAndCleanup } where @@ -981,24 +980,32 @@ vcsTestDriverGit ] } } + gitInvocation args = (programInvocation (vcsProgram vcs') args) { progInvokeCwd = Just repoRoot } + git = runProgramInvocation verbosity . gitInvocation git' = getProgramInvocationOutput verbosity . gitInvocation + + gitQuiet [] = git [] + gitQuiet (cmd : args) = git (cmd : verboseArg ++ args) + verboseArg = ["--quiet" | verbosity < Verbosity.normal] + submoduleGitDir path = repoRoot ".git" "modules" path deinitAndRemoveCachedSubmodules = do - git $ ["submodule", "deinit", "--force", "--all"] ++ verboseArg + gitQuiet ["submodule", "deinit", "--force", "--all"] let gitModulesDir = repoRoot ".git" "modules" gitModulesExists <- doesDirectoryExist gitModulesDir when gitModulesExists $ removeDirectoryRecursive gitModulesDir updateSubmodulesAndCleanup = do - git $ ["submodule", "sync", "--recursive"] ++ verboseArg - git $ ["submodule", "update", "--init", "--recursive", "--force"] ++ verboseArg - git $ ["submodule", "foreach", "--recursive"] ++ verboseArg ++ ["git clean -ffxdq"] - git $ ["clean", "-ffxdq"] ++ verboseArg + gitQuiet ["submodule", "sync", "--recursive"] + gitQuiet ["submodule", "update", "--init", "--recursive", "--force"] + -- Note: We need to manually add `verboseArg` here so that the embedded `git clean` command includes it as well. + gitQuiet $ ["submodule", "foreach", "--recursive", "git clean -ffxdq"] ++ verboseArg + gitQuiet ["clean", "-ffxdq"] type MTimeChange = Int diff --git a/changelog.d/pr-10587 b/changelog.d/pr-10587 new file mode 100644 index 00000000000..92428be048b --- /dev/null +++ b/changelog.d/pr-10587 @@ -0,0 +1,12 @@ +--- +synopsis: "Quieter Git output" +packages: [cabal-install] +prs: 10587 +--- + +When `cabal` clones a Git repo for a `source-repository-package` listed in a +`cabal.project`, it will run various commands to check out the correct +revision, initialize submodules if they're present, and so on. + +Now, `cabal` will pass `--quiet` to Git in more cases to help prevent +cluttering command-line output.