Repository: conan-io/conan

Issue:
[feature] Print git commands when print_run_commands = True
<!-- What is your suggestion? Please be as specific as possible! -->
It would be nice to have `git` commands from the `tools.Git` helper be printed out if the `print_run_commands` variable is set to `True`. Could even be a new configuration option if desired

- [X] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).



Discussion:
Hi! 

Yes, probably it makes sense for commands using `Git` or `SVN` helpers, as we do for other helpers like `CMake`. Nevertheless I feel like it should output only the commands that are explicit in the recipes, but not other usages that Conan is doing in the internals (those commands could be using a git library instead of the command line).

wdyt? Should we print every usage of the command line or just those commands written in the recipes?
@jgsogo I think it might make the most sense to have a new config option, maybe `print_git_commands`. This would be really nice so that it is more clear what is happening, especially when debugging issues in CI
I prefer not to add so many config options, it becomes harder to maintain and to understand. If the log output is good enough (probably something to improve) a `grep` over the lines should be enough to retrieve only those you are interested in.

My question was if you think that the output should contain only the commands that the user is running in the `conanfile.py` or also commands that Conan runs behind the scenes (like cloning the repository defined in the `scm` attribute)
@jgsogo Oh I understand now. I'm thinking just the commands that are explicit in the conanfile. Otherwise the user might get confused. Maybe the commands that Conan executes behind the scenes could be logged if the trace level is debug?
@jgsogo But I think the more important feature to implement for now is just the explicit logging of commands that the user runs
Closed as solved in Conan 2.0

Patch:
diff --git a/conan/tools/scm/git.py b/conan/tools/scm/git.py
--- a/conan/tools/scm/git.py
+++ b/conan/tools/scm/git.py
@@ -1,6 +1,7 @@
 import fnmatch
 import os
 
+from conan.api.output import Color
 from conan.tools.files import chdir, update_conandata
 from conan.errors import ConanException
 from conans.model.conf import ConfDefinition
@@ -31,12 +32,14 @@ def __init__(self, conanfile, folder=".", excluded=None):
             else:
                 self._excluded = conf_excluded
 
-    def run(self, cmd):
+    def run(self, cmd, hidden_output=None):
         """
         Executes ``git <cmd>``
 
         :return: The console output of the command.
         """
+        print_cmd = cmd if hidden_output is None else cmd.replace(hidden_output, "<hidden>")
+        self._conanfile.output.info(f"RUN: git {print_cmd}", fg=Color.BRIGHT_BLUE)
         with chdir(self._conanfile, self.folder):
             # We tried to use self.conanfile.run(), but it didn't work:
             #  - when using win_bash, crashing because access to .settings (forbidden in source())
@@ -203,7 +206,8 @@ def clone(self, url, target="", args=None):
         mkdir(self.folder)
         self._conanfile.output.info("Cloning git repo")
         target_path = f'"{target}"' if target else ""  # quote in case there are spaces in path
-        self.run('clone "{}" {} {}'.format(url, " ".join(args), target_path))
+        # Avoid printing the clone command, it can contain tokens
+        self.run('clone "{}" {} {}'.format(url, " ".join(args), target_path), hidden_output=url)
 
     def fetch_commit(self, url, commit):
         """
@@ -214,7 +218,7 @@ def fetch_commit(self, url, commit):
             url = url.replace("\\", "/")  # Windows local directory
         self._conanfile.output.info("Shallow fetch of git repo")
         self.run('init')
-        self.run(f'remote add origin "{url}"')
+        self.run(f'remote add origin "{url}"', hidden_output=url)
         self.run(f'fetch --depth 1 origin {commit}')
         self.run('checkout FETCH_HEAD')
 


Test patch:
diff --git a/conans/test/functional/tools/scm/test_git.py b/conans/test/functional/tools/scm/test_git.py
--- a/conans/test/functional/tools/scm/test_git.py
+++ b/conans/test/functional/tools/scm/test_git.py
@@ -275,7 +275,10 @@ def test_clone_checkout(self):
 
         c = TestClient()
         c.save({"conanfile.py": self.conanfile.format(url=url, commit=commit)})
-        c.run("create .")
+        c.run("create . -v")
+        # Clone is not printed, it might contain tokens
+        assert 'pkg/0.1: RUN: git clone "<hidden>"  "."' in c.out
+        assert "pkg/0.1: RUN: git checkout" in c.out
         assert "pkg/0.1: MYCMAKE: mycmake" in c.out
         assert "pkg/0.1: MYFILE: myheader!" in c.out
 
@@ -407,7 +410,8 @@ def test_clone_checkout(self):
 
         c = TestClient()
         c.save({"conanfile.py": self.conanfile.format(url=url, commit=commit)})
-        c.run("create .")
+        c.run("create . -v")
+        assert 'pkg/0.1: RUN: git remote add origin "<hidden>"' in c.out
         assert "pkg/0.1: MYCMAKE: mycmake" in c.out
         assert "pkg/0.1: MYFILE: myheader!" in c.out