summaryrefslogtreecommitdiff
path: root/index.php
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-10-23 13:32:52 +0200
committerDaniel Weipert <git@mail.dweipert.de>2024-10-23 13:32:52 +0200
commitb60a706cd38327471dba489bcc100b32c0955a6f (patch)
treef5e2ff1821079208a8a7fa1966f191d02517353b /index.php
parentbf24c721a3f49cc0b8ac87bca3b5c66b329e67bb (diff)
parse status
Diffstat (limited to 'index.php')
-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>";
}
}