|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace uuf6429\ElderBrother\Change; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Process\Process; |
|
6
|
|
|
|
|
7
|
|
|
class GitChangeSet |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Returns all files that have been created, changed, moved or deleted. |
|
11
|
|
|
* |
|
12
|
|
|
* @return FileList |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function getAllChanges() |
|
15
|
|
|
{ |
|
16
|
|
|
return static::getFiltered(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Returns only the files created by this changeset. |
|
21
|
|
|
* |
|
22
|
|
|
* @return FileList |
|
23
|
|
|
*/ |
|
24
|
|
|
public static function getAdded() |
|
25
|
|
|
{ |
|
26
|
|
|
return static::getFiltered('A'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Returns files to be deleted by this changeset. |
|
31
|
|
|
* |
|
32
|
|
|
* @return FileList |
|
33
|
|
|
*/ |
|
34
|
|
|
public static function getRemoved() |
|
35
|
|
|
{ |
|
36
|
|
|
return static::getFiltered('D'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Returns all modified files. |
|
41
|
|
|
* |
|
42
|
|
|
* @return FileList |
|
43
|
|
|
*/ |
|
44
|
|
|
public static function getModified() |
|
45
|
|
|
{ |
|
46
|
|
|
return static::getFiltered('M'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Returns all files that have been copied or renmaed by this changeset. |
|
51
|
|
|
* |
|
52
|
|
|
* @return FileList |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function getCopiedOrMoved() |
|
55
|
|
|
{ |
|
56
|
|
|
return static::getFiltered('CR'); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns all changed files except those that have been deleted. |
|
61
|
|
|
* |
|
62
|
|
|
* @return FileList |
|
63
|
|
|
*/ |
|
64
|
|
|
public static function getAddedCopiedModified() |
|
65
|
|
|
{ |
|
66
|
|
|
return static::getFiltered('ACMR'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param string|null $filter See https://git-scm.com/docs/git-diff (--diff-filter) |
|
71
|
|
|
* |
|
72
|
|
|
* @return FileList |
|
73
|
|
|
*/ |
|
74
|
|
|
protected static function getFiltered($filter = null) |
|
75
|
|
|
{ |
|
76
|
|
|
return new FileList( |
|
77
|
|
|
__METHOD__ . '(' . $filter . ')', |
|
78
|
|
|
function () use (&$filter) { |
|
79
|
|
|
$command = 'git diff -z --cached --name-only'; |
|
80
|
|
|
|
|
81
|
|
|
if ($filter) { |
|
|
|
|
|
|
82
|
|
|
$command .= ' --diff-filter=' . escapeshellarg($filter); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$process = new Process($command); |
|
86
|
|
|
$process->mustRun(); |
|
87
|
|
|
|
|
88
|
|
|
return array_filter( |
|
89
|
|
|
array_unique( |
|
90
|
|
|
explode("\0", $process->getOutput()) |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: