summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--index.php90
1 files changed, 89 insertions, 1 deletions
diff --git a/index.php b/index.php
index e186d67..463af36 100644
--- a/index.php
+++ b/index.php
@@ -37,11 +37,99 @@ function parse_log(): array|null {
return $json;
}
+function parse_status(): array {
+ $process = proc_open(
+ "git status --porcelain=v2 --branch",
+ [
+ ["pipe", "r"],
+ ["pipe", "w"],
+ ["pipe", "w"],
+ ],
+ $pipes
+ );
+
+ $output = stream_get_contents($pipes[1]);
+
+ $status = ["files" => []];
+ foreach (explode("\n", $output) as $line) {
+ if (empty($line)) {
+ continue;
+ }
+
+ $start = substr($line, 0, 1);
+
+ if ($start == "#") {
+ if (str_contains($line, "branch.oid")) {
+ $status["oid"] = substr($line, strlen("# branch.oid "));
+ }
+ else if (str_contains($line, "branch.head")) {
+ $status["head"] = substr($line, strlen("# branch.head "));
+ }
+ else if (str_contains($line, "branch.upstream")) {
+ $status["upstream"] = substr($line, strlen("# branch.upstream "));
+ }
+ else if (str_contains($line, "branch.ab")) {
+ $status["ab"] = substr($line, strlen("# branch.ab "));
+ }
+ }
+
+ else {
+ $parts = explode(" ", $line);
+ $file = [
+ "filename" => $parts[count($parts) - 1],
+ "staged" => false,
+ "unstaged" => false,
+ "untracked" => false,
+ "new_file" => false,
+ "modified" => false,
+ ];
+
+ if ($start == "1") {
+ $track_status = $parts[1];
+ if (substr($track_status, 0, 1) == "A") {
+ $file["staged"] = true;
+ $file["new_file"] = true;
+ }
+ else if (substr($track_status, 0, 1) == "M") {
+ $file["staged"] = true;
+ $file["modified"] = true;
+ }
+
+ if (substr($track_status, 1, 1) == "M") {
+ $file["unstaged"] = true;
+ $file["modified"] = true;
+ }
+
+ $file = array_merge($file, [
+ "previous_mode" => $parts[3],
+ "new_mode" => $parts[4],
+ "previous_id" => $parts[6],
+ "new_id" => $parts[7],
+ ]);
+ }
+
+ else if ($start == "?") {
+ $file["untracked"] = true;
+ }
+
+ $status["files"][] = $file;
+ }
+ }
+
+ return $status;
+}
+
foreach ($projects as $project) {
chdir($project);
echo $project . "<br>";
+
+ $status = parse_status();
+ foreach ($status["files"] as $file) {
+ var_dump($file);
+ }
+
foreach (parse_log() as $commit) {
- echo "<a href=\"$commit[commit]\">$commit[message]</a><br>";
+ // echo "<a href=\"$commit[commit]\">$commit[message]</a><br>";
}
}