Failed Conditions
Push — master ( dd969d...42da22 )
by Alexander
10:30
created

UpdateCommand::prepareDependencies()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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\Repository\WorkingCopyConflictTracker;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
class UpdateCommand extends AbstractCommand implements IAggregatorAwareCommand
21
{
22
23
	/**
24
	 * Working copy conflict tracker.
25
	 *
26
	 * @var WorkingCopyConflictTracker
27
	 */
28
	private $_workingCopyConflictTracker;
29
30
	/**
31
	 * Prepare dependencies.
32
	 *
33
	 * @return void
34
	 */
35
	protected function prepareDependencies()
36
	{
37
		parent::prepareDependencies();
38
39
		$container = $this->getContainer();
40
41
		$this->_workingCopyConflictTracker = $container['working_copy_conflict_tracker'];
42
	}
43
44
	/**
45
	 * {@inheritdoc}
46
	 */
47
	protected function configure()
48
	{
49
		$this
50
			->setName('update')
51
			->setDescription('Bring changes from the repository into the working copy')
52
			->setAliases(array('up'))
53
			->addArgument(
54
				'path',
55
				InputArgument::OPTIONAL,
56
				'Working copy path',
57
				'.'
58
			)
59
			->addOption(
60
				'revision',
61
				'r',
62
				InputOption::VALUE_REQUIRED,
63
				'Update working copy to specified revision, e.g. <comment>NUMBER</comment>, <comment>{DATE}</comment>, <comment>HEAD</comment>, <comment>BASE</comment>, <comment>COMMITTED</comment>, <comment>PREV</comment>'
64
			)
65
			->addOption(
66
				'ignore-externals',
67
				null,
68
				InputOption::VALUE_NONE,
69
				'Ignore externals definitions'
70
			);
71
72
		parent::configure();
73
	}
74
75
	/**
76
	 * {@inheritdoc}
77
	 */
78
	protected function execute(InputInterface $input, OutputInterface $output)
79
	{
80
		$wc_path = $this->getWorkingCopyPath();
81
		$revision = $this->io->getOption('revision');
82
		$ignore_externals = $this->io->getOption('ignore-externals');
83
84
		$show_revision = $revision ? $revision : 'HEAD';
85
		$show_externals = $ignore_externals ? '(excluding externals)' : '(including externals)';
86
		$this->io->writeln(
87
			'Updating working copy to <info>' . $show_revision . '</info> revision ' . $show_externals . ' ... '
0 ignored issues
show
Bug introduced by
Are you sure $show_revision of type string|string[]|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

87
			'Updating working copy to <info>' . /** @scrutinizer ignore-type */ $show_revision . '</info> revision ' . $show_externals . ' ... '
Loading history...
88
		);
89
90
		$param_string = '{' . $wc_path . '}';
91
92
		if ( $revision ) {
93
			$param_string .= ' --revision ' . $revision;
0 ignored issues
show
Bug introduced by
Are you sure $revision of type string|string[]|true can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
			$param_string .= ' --revision ' . /** @scrutinizer ignore-type */ $revision;
Loading history...
94
		}
95
96
		if ( $ignore_externals ) {
97
			$param_string .= ' --ignore-externals';
98
		}
99
100
		$command = $this->repositoryConnector->getCommand('update', $param_string);
101
		$command->runLive(array(
102
			$wc_path => '.',
103
		));
104
105
		if ( $this->_workingCopyConflictTracker->getNewConflicts($wc_path) ) {
106
			$this->_workingCopyConflictTracker->add($wc_path);
107
		}
108
109
		$this->io->writeln('<info>Done</info>');
110
	}
111
112
	/**
113
	 * Returns option names, that makes sense to use in aggregation mode.
114
	 *
115
	 * @return array
116
	 */
117
	public function getAggregatedOptions()
118
	{
119
		return array('ignore-externals');
120
	}
121
122
}
123