1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Command; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\SVNBuddy\Config\AbstractConfigSetting; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Config\ArrayConfigSetting; |
16
|
|
|
use ConsoleHelpers\SVNBuddy\Repository\WorkingCopyConflictTracker; |
17
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
18
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
19
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
20
|
|
|
use Symfony\Component\Console\Input\InputOption; |
21
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
22
|
|
|
|
23
|
|
|
class ConflictsCommand extends AbstractCommand implements IAggregatorAwareCommand, IConfigAwareCommand |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
const SETTING_CONFLICTS_RECORDED_CONFLICTS = 'conflicts.recorded-conflicts'; |
27
|
|
|
|
28
|
|
|
const MODE_SHOW = 'show'; |
29
|
|
|
|
30
|
|
|
const MODE_ADD = 'add'; |
31
|
|
|
|
32
|
|
|
const MODE_REPLACE = 'replace'; |
33
|
|
|
|
34
|
|
|
const MODE_ERASE = 'erase'; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Working copy conflict tracker. |
38
|
|
|
* |
39
|
|
|
* @var WorkingCopyConflictTracker |
40
|
|
|
*/ |
41
|
|
|
private $_workingCopyConflictTracker; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritdoc} |
45
|
|
|
*/ |
46
|
11 |
|
protected function configure() |
47
|
|
|
{ |
48
|
11 |
|
$mode_string = '<comment>' . implode('</comment>, <comment>', $this->getModes()) . '</comment>'; |
49
|
|
|
|
50
|
|
|
$this |
51
|
11 |
|
->setName('conflicts') |
52
|
11 |
|
->setDescription( |
53
|
11 |
|
'Manage recorded conflicts in a working copy' |
54
|
|
|
) |
55
|
11 |
|
->setAliases(array('cf')) |
56
|
11 |
|
->addArgument( |
57
|
11 |
|
'path', |
58
|
11 |
|
InputArgument::OPTIONAL, |
59
|
11 |
|
'Working copy path', |
60
|
11 |
|
'.' |
61
|
|
|
) |
62
|
11 |
|
->addOption( |
63
|
11 |
|
'mode', |
64
|
11 |
|
'm', |
65
|
11 |
|
InputOption::VALUE_REQUIRED, |
66
|
11 |
|
'Operation mode, e.g. ' . $mode_string, |
67
|
11 |
|
self::MODE_SHOW |
68
|
|
|
); |
69
|
|
|
|
70
|
11 |
|
parent::configure(); |
71
|
11 |
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Prepare dependencies. |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
protected function prepareDependencies() |
79
|
|
|
{ |
80
|
|
|
parent::prepareDependencies(); |
81
|
|
|
|
82
|
|
|
$container = $this->getContainer(); |
83
|
|
|
|
84
|
|
|
$this->_workingCopyConflictTracker = $container['working_copy_conflict_tracker']; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Return possible values for the named option |
89
|
|
|
* |
90
|
|
|
* @param string $optionName Option name. |
91
|
|
|
* @param CompletionContext $context Completion context. |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) |
96
|
|
|
{ |
97
|
|
|
$ret = parent::completeOptionValues($optionName, $context); |
98
|
|
|
|
99
|
|
|
if ( $optionName === 'mode' ) { |
100
|
|
|
return $this->getModes(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return $ret; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* {@inheritdoc} |
108
|
|
|
* |
109
|
|
|
* @throws \RuntimeException When invalid mode is specified. |
110
|
|
|
*/ |
111
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
112
|
|
|
{ |
113
|
|
|
$mode = $this->io->getOption('mode'); |
114
|
|
|
|
115
|
|
|
if ( !in_array($mode, $this->getModes()) ) { |
116
|
|
|
throw new \RuntimeException( |
117
|
|
|
'The "' . $mode . '" mode is unknown.' |
118
|
|
|
); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
$wc_path = $this->getWorkingCopyPath(); |
122
|
|
|
|
123
|
|
|
switch ( $mode ) { |
124
|
|
|
case self::MODE_SHOW: |
125
|
|
|
$recorded_conflicts = $this->_workingCopyConflictTracker->getRecordedConflicts($wc_path); |
126
|
|
|
|
127
|
|
|
if ( !$recorded_conflicts ) { |
|
|
|
|
128
|
|
|
$this->io->writeln('<info>The working copy doesn\'t have any recorded conflicts.</info>'); |
129
|
|
|
} |
130
|
|
|
else { |
131
|
|
|
$this->io->writeln( |
132
|
|
|
'<error>Recorded Conflicts (' . count($recorded_conflicts) . ' paths):</error>' |
133
|
|
|
); |
134
|
|
|
|
135
|
|
|
foreach ( $recorded_conflicts as $conflicted_path ) { |
136
|
|
|
$this->io->writeln(' * ' . $conflicted_path); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
break; |
140
|
|
|
|
141
|
|
|
case self::MODE_ADD: |
142
|
|
|
$this->_workingCopyConflictTracker->add($wc_path); |
143
|
|
|
$this->io->writeln('<info>Conflicts updated.</info>'); |
144
|
|
|
break; |
145
|
|
|
|
146
|
|
|
case self::MODE_REPLACE: |
147
|
|
|
$this->_workingCopyConflictTracker->replace($wc_path); |
148
|
|
|
$this->io->writeln('<info>Conflicts updated.</info>'); |
149
|
|
|
break; |
150
|
|
|
|
151
|
|
|
case self::MODE_ERASE: |
152
|
|
|
$this->_workingCopyConflictTracker->erase($wc_path); |
153
|
|
|
$this->io->writeln('<info>Conflicts erased.</info>'); |
154
|
|
|
break; |
155
|
|
|
} |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Returns allowed modes. |
160
|
|
|
* |
161
|
|
|
* @return array |
162
|
|
|
*/ |
163
|
11 |
|
protected function getModes() |
164
|
|
|
{ |
165
|
11 |
|
return array(self::MODE_SHOW, self::MODE_ADD, self::MODE_REPLACE, self::MODE_ERASE); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Returns list of config settings. |
170
|
|
|
* |
171
|
|
|
* @return AbstractConfigSetting[] |
172
|
|
|
*/ |
173
|
|
|
public function getConfigSettings() |
174
|
|
|
{ |
175
|
|
|
return array( |
176
|
|
|
new ArrayConfigSetting(self::SETTING_CONFLICTS_RECORDED_CONFLICTS, array()), |
177
|
|
|
); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns option names, that makes sense to use in aggregation mode. |
182
|
|
|
* |
183
|
|
|
* @return array |
184
|
|
|
*/ |
185
|
|
|
public function getAggregatedOptions() |
186
|
|
|
{ |
187
|
|
|
return array(); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
} |
191
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.