1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of SebastianFeldmann\Git. |
5
|
|
|
* |
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace SebastianFeldmann\Git\Operator; |
13
|
|
|
|
14
|
|
|
use SebastianFeldmann\Git\Command\Diff\Compare; |
15
|
|
|
use SebastianFeldmann\Git\Command\DiffTree\ChangedFiles; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Diff operator |
19
|
|
|
* |
20
|
|
|
* @package SebastianFeldmann\Git |
21
|
|
|
* @author Sebastian Feldmann <[email protected]> |
22
|
|
|
* @link https://github.com/sebastianfeldmann/git |
23
|
|
|
* @since Class available since Release 1.2.0 |
24
|
|
|
*/ |
25
|
|
|
class Diff extends Base |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* Returns a list of files and their changes. |
29
|
|
|
* |
30
|
|
|
* @param string $from |
31
|
|
|
* @param string $to |
32
|
1 |
|
* @return \SebastianFeldmann\Git\Diff\File[] |
33
|
|
|
*/ |
34
|
1 |
|
public function compare(string $from, string $to): array |
35
|
1 |
|
{ |
36
|
|
|
$compare = (new Compare($this->repo->getRoot()))->revisions($from, $to) |
37
|
1 |
|
->ignoreWhitespacesAtEndOfLine(); |
38
|
|
|
|
39
|
1 |
|
$result = $this->runner->run($compare, new Compare\FullDiffList()); |
40
|
|
|
|
41
|
|
|
return $result->getFormattedOutput(); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Returns a list of files and their changes |
46
|
|
|
* |
47
|
|
|
* @param string $to |
48
|
|
|
* @return \SebastianFeldmann\Git\Diff\File[] |
49
|
1 |
|
*/ |
50
|
|
|
public function compareIndexTo(string $to = 'head'): array |
51
|
1 |
|
{ |
52
|
1 |
|
$compare = (new Compare($this->repo->getRoot()))->indexTo($to) |
53
|
|
|
->withContextLines(0) |
54
|
1 |
|
->ignoreWhitespacesAtEndOfLine(); |
55
|
|
|
|
56
|
|
|
$result = $this->runner->run($compare, new Compare\FullDiffList()); |
57
|
|
|
|
58
|
|
|
return $result->getFormattedOutput(); |
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Uses 'diff-tree' to list the files that changed between two revisions |
63
|
|
|
* |
64
|
|
|
* @param string $from |
65
|
|
|
* @param string $to |
66
|
|
|
* @return string[] |
67
|
|
|
*/ |
68
|
|
|
public function getChangedFiles(string $from, string $to): array |
69
|
|
|
{ |
70
|
|
|
$cmd = (new ChangedFiles($this->repo->getRoot()))->fromRevision($from)->toRevision($to); |
71
|
|
|
$result = $this->runner->run($cmd); |
72
|
|
|
|
73
|
|
|
return $result->getBufferedOutput(); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|