]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/safe-directory-leading-path'
authorJunio C Hamano <gitster@pobox.com>
Wed, 12 Jun 2024 20:37:16 +0000 (13:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 12 Jun 2024 20:37:16 +0000 (13:37 -0700)
The safe.directory configuration knob has been updated to
optionally allow leading path matches.

* jc/safe-directory-leading-path:
  safe.directory: allow "lead/ing/path/*" match

1  2 
setup.c
t/t0033-safe-directory.sh

diff --cc setup.c
index e47946d0e71c26ea592f3c722fca9c01024d1f15,4c5de0960bf11b887e4e7b573f505b9eb3964f79..e112545f71bb046cb0214df035837211e137d418
+++ b/setup.c
@@@ -1230,13 -1176,21 +1230,20 @@@ static int safe_directory_cb(const cha
        } else if (!strcmp(value, "*")) {
                data->is_safe = 1;
        } else {
-               char *interpolated = NULL;
-               if (!git_config_pathname(&interpolated, key, value) &&
-                   !fspathcmp(data->path, interpolated ? interpolated : value))
-                       data->is_safe = 1;
-               free(interpolated);
 -              const char *allowed = NULL;
++              char *allowed = NULL;
+               if (!git_config_pathname(&allowed, key, value)) {
 -                      if (!allowed)
 -                              allowed = value;
 -                      if (ends_with(allowed, "/*")) {
 -                              size_t len = strlen(allowed);
 -                              if (!fspathncmp(allowed, data->path, len - 1))
++                      const char *check = allowed ? allowed : value;
++                      if (ends_with(check, "/*")) {
++                              size_t len = strlen(check);
++                              if (!fspathncmp(check, data->path, len - 1))
+                                       data->is_safe = 1;
 -                      } else if (!fspathcmp(data->path, allowed)) {
++                      } else if (!fspathcmp(data->path, check)) {
+                               data->is_safe = 1;
+                       }
+               }
+               if (allowed != value)
 -                      free((char *)allowed);
++                      free(allowed);
        }
  
        return 0;
Simple merge