print "Verifiying checkout succeeded...\n"; $currHead = trim(kfShellExec("git rev-parse --verify HEAD")); if (!GitInfo::isSHA1($currHead)) { print "> rev-parse failed for HEAD: {$currHead}\n"; print "> Skipping {$remoteBranchName}...\n"; continue; } if ($branchHead !== $currHead) { // Checkout likely failed print "> ERROR: Current HEAD does not match remote branch pointer. Skipping...\n"; continue; } // Get AuthorDate of latest commit this branch (Author instead of Commit) $headTimestamp = kfShellExec("git show HEAD --format='%at' -s"); print "Generating new archive...\n"; $archiveFilePathEscaped = kfEscapeShellArg($archiveFilePath); // Toolserver's git doesn't support --format='tar.gz', using 'tar' and piping to gzip instead $execOut = kfShellExec("git archive HEAD --format='tar' | gzip > {$archiveFilePathEscaped}"); if (file_exists($archiveFilePath)) { print "> Done!\n"; } else { $archiveFilePath = false; print "> FAILED!\n"; } if ($branchName === 'master') { print "There is a new archive of the master branch, update '-latest' symlink...\n"; $masterSymlinkName = 'mediawiki-latest.tar.gz'; $masterSymlinkPath = "{$archiveDir}/{$masterSymlinkName}"; if (file_exists($masterSymlinkPath)) { if (!unlink($masterSymlinkPath)) { print "> ERROR: Could not remove old symlink";
/** * @param array $options (optional): * - string dir: Full path to where the git repository is. * By default it will assume the current directory is already the git repository. * - string checkout: Will be checked out and reset to its HEAD. Otherwise stays in * the current branch and resets to its head. * - unlock: Whether or not it should ensure there is no lock. * * @return bool|string Boolean false on failure, or a string * with the output of the commands. */ function kfGitCleanReset($options = array()) { $orgPath = __DIR__; if (isset($options['dir'])) { if (!is_dir($options['dir'])) { return false; } // Navigate to the repo so we can execute the git commands chdir($options['dir']); } $out = ''; $cmds = array(); if (isset($options['unlock']) && $options['unlock']) { $cmds[] = 'rm -f .git/index.lock'; } $cmds[] = 'git clean -q -d -x -f'; $cmds[] = 'git reset -q --hard'; if (isset($options['checkout'])) { $cmds[] = 'git checkout -q -f ' . kfEscapeShellArg($options['checkout']); } foreach ($cmds as $cmd) { $out .= "\$ {$cmd}\n"; $out .= kfShellExec($cmd) . "\n"; } // Go back to the original dir if we changed it if (isset($options['dir'])) { chdir($orgPath); } return $out; }