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