patman: Deal with git safe-directory warning

When running tests where the .git directory is not owned by the current
user, various warnings are produced and the tests fail. This happens in
CI.

For patman itself, modify the gitutil.get_top_level() function to return
None in this case. Ensure that the warning is not shown, since it creates
about 1000 lines of output.

For checkpatch, the same warning is produced even though --no-tree is
given. Suppress that as well.

Signed-off-by: Simon Glass <sjg@chromium.org>
diff --git a/tools/u_boot_pylib/gitutil.py b/tools/u_boot_pylib/gitutil.py
index cfcfeff..7d001d0 100644
--- a/tools/u_boot_pylib/gitutil.py
+++ b/tools/u_boot_pylib/gitutil.py
@@ -644,7 +644,7 @@
     """Return name of top-level directory for this git repo.
 
     Returns:
-        str: Full path to git top-level directory
+        str: Full path to git top-level directory, or None if not found
 
     This test makes sure that we are running tests in the right subdir
 
@@ -652,7 +652,12 @@
             os.path.join(get_top_level(), 'tools', 'patman')
     True
     """
-    return command.output_one_line('git', 'rev-parse', '--show-toplevel')
+    result = command.run_one(
+        'git', 'rev-parse', '--show-toplevel', oneline=True, capture=True,
+        capture_stderr=True, raise_on_error=False)
+    if result.return_code:
+        return None
+    return result.stdout.strip()
 
 
 def get_alias_file():
@@ -670,7 +675,7 @@
     if os.path.isabs(fname):
         return fname
 
-    return os.path.join(get_top_level(), fname)
+    return os.path.join(get_top_level() or '', fname)
 
 
 def get_default_user_name():