Completed
Push — master ( 4288f6...92f818 )
by Alexander
28s queued 15s
created

UpdateCommand::execute()   B

Complexity

Conditions 7
Paths 64

Size

Total Lines 36
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 21
c 3
b 0
f 0
dl 0
loc 36
ccs 0
cts 22
cp 0
rs 8.6506
cc 7
nc 64
nop 2
crap 56
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
			->addOption(
72
				'deploy',
73
				'd',
74
				InputOption::VALUE_NONE,
75
				'Perform local deployment after a successful update'
76
			);
77
78
		parent::configure();
79
	}
80
81
	/**
82
	 * {@inheritdoc}
83
	 */
84
	protected function execute(InputInterface $input, OutputInterface $output)
85
	{
86
		$wc_path = $this->getWorkingCopyPath();
87
		$revision = $this->io->getOption('revision');
88
		$ignore_externals = $this->io->getOption('ignore-externals');
89
90
		$show_revision = $revision ? $revision : 'HEAD';
91
		$show_externals = $ignore_externals ? '(excluding externals)' : '(including externals)';
92
		$this->io->writeln(
93
			'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

93
			'Updating working copy to <info>' . /** @scrutinizer ignore-type */ $show_revision . '</info> revision ' . $show_externals . ' ... '
Loading history...
94
		);
95
96
		$arguments = array($wc_path);
97
98
		if ( $revision ) {
99
			$arguments[] = '--revision';
100
			$arguments[] = $revision;
101
		}
102
103
		if ( $ignore_externals ) {
104
			$arguments[] = '--ignore-externals';
105
		}
106
107
		$command = $this->repositoryConnector->getCommand('update', $arguments);
108
		$command->runLive(array(
109
			$wc_path => '.',
110
		));
111
112
		if ( $this->_workingCopyConflictTracker->getNewConflicts($wc_path) ) {
113
			$this->_workingCopyConflictTracker->add($wc_path);
114
		}
115
116
		$this->io->writeln('<info>Done</info>');
117
118
		if ( $this->io->getOption('deploy') ) {
119
			$this->runOtherCommand('deploy', array('--local' => true));
120
		}
121
	}
122
123
	/**
124
	 * Returns option names, that makes sense to use in aggregation mode.
125
	 *
126
	 * @return array
127
	 */
128
	public function getAggregatedOptions()
129
	{
130
		return array('ignore-externals');
131
	}
132
133
}
134