Skip to content

Instantly share code, notes, and snippets.

@danieljpeter
Created May 4, 2012 00:45
Show Gist options
  • Save danieljpeter/2590737 to your computer and use it in GitHub Desktop.
Save danieljpeter/2590737 to your computer and use it in GitHub Desktop.
remove git files
//remove all the files from the local github repo which aren't in the metadata repo (in case these were objects which were deleted in salesforce)
//get the an array of each file listings, recursively. Strip off the beginning path from each entry in the array so we can do text comparison
$arrMetadata = stripBlanks(str_replace('/home/dpeter/sf/metadata', '', getFilesFromDir('/home/dpeter/sf/metadata')));
$arrGit = stripBlanks(str_replace('/home/dpeter/sf/git/salesforce-metadata', '', getFilesFromDir('/home/dpeter/sf/git/salesforce-metadata')));
//remove array entries in the /.git directory
$arrGit = stripGit($arrGit);
$arrDeleteFromGit = array();
$fileInGitAndMetadata = false;
foreach ($arrGit as $gitFile) {
$fileInGitAndMetadata = false;
foreach ($arrMetadata as $metadataFile) {
if ($gitFile == $metadataFile) {
$fileInGitAndMetadata = true;
}
}
if (!$fileInGitAndMetadata) {
array_push($arrDeleteFromGit, $gitFile);
}
}
//print_r($arrDeleteFromGit);
foreach ($arrDeleteFromGit as $gitFile) {
echo shell_exec('git --git-dir=/home/dpeter/sf/git/salesforce-metadata/.git --work-tree=/home/dpeter/sf/git/salesforce-metadata/ rm -r -f /home/dpeter/sf/git/salesforce-metadata'.$gitFile);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment