]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
patman: Deal with git safe-directory warning
authorSimon Glass <sjg@chromium.org>
Sat, 10 May 2025 11:04:55 +0000 (13:04 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 27 May 2025 09:07:42 +0000 (10:07 +0100)
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>
tools/patman/checkpatch.py
tools/patman/cmdline.py
tools/patman/get_maintainer.py
tools/patman/project.py
tools/patman/settings.py
tools/u_boot_pylib/gitutil.py

index 5df06b1095a0a9e73298e1c9dfa9369532240f72..f9204a907efd69b1ef3296baef22ceea33bf9064 100644 (file)
@@ -22,7 +22,7 @@ RE_NOTE = re.compile(r'NOTE: (.*)')
 
 
 def find_check_patch():
-    top_level = gitutil.get_top_level()
+    top_level = gitutil.get_top_level() or ''
     try_list = [
         os.getcwd(),
         os.path.join(os.getcwd(), '..', '..'),
@@ -219,8 +219,9 @@ def check_patch(fname, verbose=False, show_types=False, use_tree=False,
         args.append('--no-tree')
     if show_types:
         args.append('--show-types')
-    output = command.output(*args, os.path.join(cwd or '', fname),
-                            raise_on_error=False)
+    output = command.output(
+        *args, os.path.join(cwd or '', fname), raise_on_error=False,
+        capture_stderr=not use_tree)
 
     return check_patch_parse(output, verbose)
 
index 0ae92f88c4b5c1cd27e09e374d1d91cccaa20f52..108fa52d8200eb5d72d907c484e3ece3bf2d4f18 100644 (file)
@@ -44,11 +44,15 @@ def add_send_args(par):
         '-m', '--no-maintainers', action='store_false',
         dest='add_maintainers', default=True,
         help="Don't cc the file maintainers automatically")
+    default_arg = None
+    top_level = gitutil.get_top_level()
+    if top_level:
+        default_arg = os.path.join(top_level, 'scripts',
+                                   'get_maintainer.pl') + ' --norolestats'
     par.add_argument(
         '--get-maintainer-script', dest='get_maintainer_script', type=str,
         action='store',
-        default=os.path.join(gitutil.get_top_level(), 'scripts',
-                             'get_maintainer.pl') + ' --norolestats',
+        default=default_arg,
         help='File name of the get_maintainer.pl (or compatible) script.')
     par.add_argument(
         '-r', '--in-reply-to', type=str, action='store',
index 200ee96551d9d328800249f0173065a84345d918..1c8fa726573e0fd91c8e7d6fa676636553dbbfa4 100644 (file)
@@ -21,7 +21,7 @@ def find_get_maintainer(script_file_name):
     if get_maintainer:
         return get_maintainer
 
-    git_relative_script = os.path.join(gitutil.get_top_level(),
+    git_relative_script = os.path.join(gitutil.get_top_level() or '',
                                        script_file_name)
     if os.path.exists(git_relative_script):
         return git_relative_script
@@ -46,11 +46,14 @@ def get_maintainer(script_file_name, fname, verbose=False):
     """
     # Expand `script_file_name` into a file name and its arguments, if
     # any.
-    cmd_args = shlex.split(script_file_name)
-    file_name = cmd_args[0]
-    arguments = cmd_args[1:]
+    get_maintainer = None
+    arguments = None
+    if script_file_name:
+        cmd_args = shlex.split(script_file_name)
+        file_name = cmd_args[0]
+        arguments = cmd_args[1:]
 
-    get_maintainer = find_get_maintainer(file_name)
+        get_maintainer = find_get_maintainer(file_name)
     if not get_maintainer:
         if verbose:
             print("WARNING: Couldn't find get_maintainer.pl")
index d6143a670661e2f85dff34ba31352540726998b8..e633401e9d6172cef9ed5771e5cc15e5cc2d67f0 100644 (file)
@@ -18,7 +18,8 @@ def detect_project():
     """
     top_level = gitutil.get_top_level()
 
-    if os.path.exists(os.path.join(top_level, "include", "u-boot")):
+    if (not top_level or
+            os.path.exists(os.path.join(top_level, "include", "u-boot"))):
         return "u-boot"
     elif os.path.exists(os.path.join(top_level, "kernel")):
         return "linux"
index 7a0866cd370b36be9b7ca36ae81c08f06af8adab..def932db43a47fd6989e449a79389d042c48bbcb 100644 (file)
@@ -364,7 +364,8 @@ def Setup(parser, project_name, argv, config_fname=None):
 
     if config_fname is None:
         config_fname = '%s/.patman' % os.getenv('HOME')
-    git_local_config_fname = os.path.join(gitutil.get_top_level(), '.patman')
+    git_local_config_fname = os.path.join(gitutil.get_top_level() or '',
+                                          '.patman')
 
     has_config = False
     has_git_local_config = False
index cfcfeffe2f4134c218de5762f8d7466045340bf8..7d001d03bed6f75297e9443ee5106256241243f6 100644 (file)
@@ -644,7 +644,7 @@ def get_top_level():
     """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 @@ def get_top_level():
             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 @@ def get_alias_file():
     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():