Skip to content

Instantly share code, notes, and snippets.

@mahelbir
Created July 16, 2022 12:22
Show Gist options
  • Save mahelbir/479a06a5142b187bda5d58668472225f to your computer and use it in GitHub Desktop.
Save mahelbir/479a06a5142b187bda5d58668472225f to your computer and use it in GitHub Desktop.
PHP file to zip changed files (differences between working directory and staging area)
#!/usr/bin/env php
<?php
exec("git diff --name-only --diff-filter=d", $out);
exec("git ls-files --others --exclude-standard", $out2);
if (count($out) > 0 || count($out2) > 0) {
$zip = new ZipArchive();
$zipName = "patch-" . date("YmdHi") . ".zip";
if ($zip->open($zipName, ZipArchive::CREATE)) {
foreach ($out as $line) {
if (file_exists($line))
$zip->addFile($line);
}
foreach ($out2 as $line) {
if (file_exists($line))
$zip->addFile($line);
}
$zip->close();
}
exit("New patch: $zipName");
} else {
exit("No patch!");
}
@mahelbir
Copy link
Author

Usage : php patch.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment