您需要执行以下几个步骤:
每个文件夹都可以有一个,所以不要假设只有一个.
子模块有一个.git链接到主.git文件夹,所以要警惕过早停止.
它会像:
function find_gitignore_files($dir) {
$files = array();
while (true) {
$file = "$dir/.gitignore";
if (is_file($file)) $files[] = $file;
if (is_dir("$dir/.git") && !is_link("$dir/.git")) break; # stop here
if (dirname($dir) === '.') break; # and here
$dir = dirname($dir);
}
return $files;
}
Run Code Online (Sandbox Code Playgroud)
你需要忽略注释,注意否定运算符(!),并注意整体.
这个是,给予或采取,将会是这样的:
function parse_git_ignore_file($file) { # $file = '/absolute/path/to/.gitignore'
$dir = dirname($file);
$matches = array();
$lines = file($file);
foreach ($lines as $line) {
$line = trim($line);
if ($line === '') continue; # empty line
if (substr($line, 0, 1) == '#') continue; # a comment
if (substr($line, 0, 1) == '!') { # negated glob
$line = substr($line, 1);
$files = array_diff(glob("$dir/*"), glob("$dir/$line"));
} else { # normal glob
$files = glob("$dir/$line");
}
$matches = array_merge($matches, $files);
}
return $matches;
}
Run Code Online (Sandbox Code Playgroud)
(注意:以上都没有经过测试,但它们应该让你朝着正确的方向前进.)
| 归档时间: |
|
| 查看次数: |
1824 次 |
| 最近记录: |