php / web-doc

http://doc.php.net
33 stars 85 forks source link

fatal: detected dubious ownership #43

Closed nilgun closed 3 weeks ago

nilgun commented 1 year ago

If one day httpd gives an error like this (with git version 2.39.2, i got it):

error: Could not access '6a3090c77d6cf1aa777b8718b4caaadaa0d56632'
fatal: detected dubious ownership in repository at '/path/to/en'
To add an exception for this directory, call:

        git config --global --add safe.directory /path/to/en

Solution:

File: include/lib_revcheck.inc.php (Assuming PR#41 is applied)

@@ -247,15 +247,18 @@ function showdiff ()
         if (isset($_GET['hbp']))
             $h = $_GET['hbp'];
         if (isset($_GET['c']))
             $c = $_GET['c'];
         $cwd = getcwd();
+        $safedir = 'safe.directory=' . GIT_DIR . 'en';
         chdir( GIT_DIR . 'en' );
         $arg_h = escapeshellarg($h);
         $arg_f = escapeshellarg($gitfile);
-        $file = `git diff {$arg_h} -- {$arg_f}`;
-        $hash = `git log -n 1 --pretty=format:%H -- {$arg_f}`;
+        $file = `git -c {$safedir} diff --ignore-space-at-eol {$arg_h} -- {$arg_f}`;
+        if ($file == null)
+            $file = `git -c {$safedir} diff {$arg_h} -- {$arg_f}`;
+        $hash = `git -c {$safedir} log -n 1 --pretty=format:%H -- {$arg_f}`;
         chdir( $cwd );
         if (!$file) return;
         $raw = htmlspecialchars( $file, ENT_XML1, 'UTF-8' );
         $lines = explode ( "\n" , $raw );
         echo "<div style='font: .75rem monospace; overflow-wrap:break-word; line-height: 1.8; border: 1px solid #ccc; border-radius: 4px;'>";
jimwins commented 3 weeks ago

Fixed, thanks.