Created
December 24, 2014 01:41
-
-
Save kiang/9224e139320c230fedc5 to your computer and use it in GitHub Desktop.
batch push files into git repo with size limitation in each commit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$limit = 838860800; | |
exec('git status ' . __DIR__, $lines); | |
$lineCount = $currentFileSize = $pushCount = 0; | |
$sw = false; | |
foreach ($lines AS $line) { | |
if ($sw) { | |
++$lineCount; | |
if ($lineCount > 2) { | |
if (!empty($line)) { | |
$line = trim($line); | |
$path = __DIR__ . '/' . $line; | |
if (is_file($path)) { | |
addFile($path); | |
} else { | |
foreach (glob($path . '/*') AS $file) { | |
addFile($file); | |
} | |
} | |
} else { | |
$sw = false; | |
} | |
} | |
} elseif ($line === 'Untracked files:') { | |
$sw = true; | |
} | |
} | |
function addFile($file) { | |
global $limit, $currentFileSize, $pushCount; | |
$currentFileSize += filesize($file); | |
if ($currentFileSize < $limit) { | |
exec("git add {$file}"); | |
} else { | |
exec("git add {$file}"); | |
++$pushCount; | |
exec("git commit -m 'batch push files part {$pushCount}'"); | |
exec("git push"); | |
$currentFileSize = 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment