3 final class PhabricatorRepositoryManagementMovePathsWorkflow
4 extends PhabricatorRepositoryManagementWorkflow
{
6 protected function didConstruct() {
8 ->setName('move-paths')
9 ->setSynopsis(pht('Move repository local paths.'))
15 'help' => pht('Move paths with this prefix.'),
20 'help' => pht('Replace matching prefixes with this string.'),
24 'help' => pht('Apply changes without prompting.'),
29 public function execute(PhutilArgumentParser
$args) {
30 $console = PhutilConsole
::getConsole();
32 $repos = id(new PhabricatorRepositoryQuery())
33 ->setViewer($this->getViewer())
36 $console->writeErr("%s\n", pht('There are no repositories.'));
40 $from = $args->getArg('from');
44 'You must specify a path prefix to move from with --from.'));
47 $to = $args->getArg('to');
51 'You must specify a path prefix to move to with --to.'));
54 $is_force = $args->getArg('force');
59 foreach ($repos as $repo) {
60 $src = $repo->getLocalPath();
63 'repository' => $repo,
65 'monogram' => $repo->getMonogram(),
70 if (strncmp($src, $from, strlen($from))) {
71 $row['action'] = pht('Ignore');
73 $dst = $to.substr($src, strlen($from));
75 $row['action'] = tsprintf('**%s**', pht('Move'));
84 $table = id(new PhutilConsoleTable())
88 'title' => pht('Action'),
93 'title' => pht('Repository'),
98 'title' => pht('Src'),
103 'title' => pht('Dst'),
107 foreach ($rows as $row) {
108 $display = array_select_keys(
116 $table->addRow($display);
122 $console->writeOut(pht('No matching repositories.')."\n");
126 $prompt = pht('Apply these changes?');
127 if (!$is_force && !phutil_console_confirm($prompt)) {
128 throw new Exception(pht('Declining to apply changes.'));
131 foreach ($rows as $row) {
132 if (empty($row['move'])) {
136 $repo = $row['repository'];
139 $repo->establishConnection('w'),
140 'UPDATE %T SET localPath = %s WHERE id = %d',
141 $repo->getTableName(),
146 $console->writeOut(pht('Applied changes.')."\n");