1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of SebastianFeldmann\Git. |
4
|
|
|
* |
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace SebastianFeldmann\Git\Command\Diff; |
11
|
|
|
|
12
|
|
|
use SebastianFeldmann\Git\Command\Base; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class Between |
16
|
|
|
* |
17
|
|
|
* @package SebastianFeldmann\Git |
18
|
|
|
* @author Sebastian Feldmann <[email protected]> |
19
|
|
|
* @link https://github.com/sebastianfeldmann/git |
20
|
|
|
* @since Class available since Release 1.2.0 |
21
|
|
|
*/ |
22
|
|
|
class Compare extends Base |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* Compare A/B command snippet. |
26
|
|
|
* |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
protected $compare = ''; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Ignore line endings. |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
protected $ignoreEOL = ''; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Show statistics only. |
40
|
|
|
* |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
protected $stats = ''; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Compare two given revisions. |
47
|
|
|
* |
48
|
|
|
* @param string $from |
49
|
|
|
* @param string $to |
50
|
|
|
* @return \SebastianFeldmann\Git\Command\Diff\Compare |
51
|
|
|
*/ |
52
|
4 |
|
public function revisions(string $from, string $to) : Compare |
53
|
|
|
{ |
54
|
4 |
|
$this->compare = escapeshellarg($from) . ' ' . escapeshellarg($to); |
55
|
4 |
|
return $this; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Set diff statistics option. |
60
|
|
|
* |
61
|
|
|
* @param bool $bool |
62
|
|
|
* @return \SebastianFeldmann\Git\Command\Diff\Compare |
63
|
|
|
*/ |
64
|
1 |
|
public function statsOnly(bool $bool = true) : Compare |
65
|
|
|
{ |
66
|
1 |
|
$this->stats = $this->useOption('--numstat', $bool); |
67
|
1 |
|
return $this; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Set ignore spaces at end of line. |
72
|
|
|
* |
73
|
|
|
* @param bool $bool |
74
|
|
|
* @return \SebastianFeldmann\Git\Command\Diff\Compare |
75
|
|
|
*/ |
76
|
1 |
|
public function ignoreWhitespacesAtEndOfLine(bool $bool = true) : Compare |
77
|
|
|
{ |
78
|
1 |
|
$this->ignoreEOL = $this->useOption('--ignore-space-at-eol', $bool); |
|
|
|
|
79
|
1 |
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Set ignore all whitespaces. |
84
|
|
|
* |
85
|
|
|
* @param bool $bool |
86
|
|
|
* @return \SebastianFeldmann\Git\Command\Diff\Compare |
87
|
|
|
*/ |
88
|
1 |
|
public function ignoreWhitespaces(bool $bool = true) : Compare |
89
|
|
|
{ |
90
|
1 |
|
$this->ignoreEOL = $this->useOption('-w', $bool); |
|
|
|
|
91
|
1 |
|
return $this; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return the command to execute. |
96
|
|
|
* |
97
|
|
|
* @return string |
98
|
|
|
* @throws \RuntimeException |
99
|
|
|
*/ |
100
|
4 |
|
protected function getGitCommand(): string |
101
|
|
|
{ |
102
|
4 |
|
return 'diff' . $this->ignoreEOL . $this->stats . ' ' . $this->compare; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.