if (!is_dir($gitWorkingCopyDir)) { printf("Unable to read from provided directory '%s'\n\n", $gitWorkingCopyDir); echo $opts->getUsageMessage(); exit(2); } $list = Branch::enlist($gitWorkingCopyDir, isset($opts->remote), isset($opts->merged)); $charInput = new SttyCharInput(); $confirmed = true; foreach (new PregMatchIterator('~^(.*)/task-([0-9]+)(-.+)?$~', $list) as $matches) { $issueId = $matches[2]; if (isset($opts->before) && $issueId >= $opts->before) { continue; } $branchFullName = $matches[0]; echo $issueId . ': ' . $branchFullName . ' '; $branch = new Branch($gitWorkingCopyDir, $branchFullName); $issue = new Issue(); $issue->find($issueId); if ($issue->count()) { echo '[' . $issue->status['name'] . '] '; if (in_array($issue->status['id'], Naf::config('redmine.closed_issue_status_ids'))) { if (!$opts->force) { echo 'Delete ' . ($branch->isRemote() ? 'remote' : 'local') . ' branch? (y/N) '; $confirmed = $charInput->confirm(); } if ($confirmed) { try { $branch->delete(); echo ' Deleted'; } catch (ShellCmd\Fault $e) { echo $e->getMessage();
} // Help requested if ($opts->getOption('h')) { echo $opts->getUsageMessage(); exit; } if (!isset($opts->dir)) { echo "Must provide a path to git working copy via the -d or --dir option\n\n"; echo $opts->getUsageMessage(); exit(2); } $gitWorkingCopyDir = $opts->dir; if (!is_dir($gitWorkingCopyDir)) { printf("Unable to read from provided directory '%s'\n\n", $gitWorkingCopyDir); echo $opts->getUsageMessage(); exit(2); } $list = Branch::enlist($gitWorkingCopyDir, isset($opts->remote), isset($opts->merged)); foreach (new PregMatchIterator('~task-([0-9]+)(-.+)?$~', $list) as $matches) { $issueId = $matches[1]; $branchName = $matches[0]; echo $issueId . ': ' . $branchName . ' '; $issue = new Issue(); $issue->find($issueId); if ($issue->count()) { echo '[' . $issue->status['name'] . '(' . $issue->status['id'] . ')]'; } else { echo 'Issue not found'; } echo "\n"; }