1 | <?php |
||
27 | class StatusFile |
||
28 | { |
||
29 | const UNTRACKED = '?'; |
||
30 | const IGNORED = '!'; |
||
31 | const UNMODIFIED = ''; |
||
32 | const MODIFIED = 'M'; |
||
33 | const ADDED = 'A'; |
||
34 | const DELETED = 'D'; |
||
35 | const RENAMED = 'R'; |
||
36 | const COPIED = 'C'; |
||
37 | const UPDATED_BUT_UNMERGED = 'U'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | private $x; |
||
43 | |||
44 | /** |
||
45 | * @var string |
||
46 | */ |
||
47 | private $y; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | */ |
||
52 | private $name; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $renamed; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | private $type; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $description; |
||
68 | |||
69 | /** |
||
70 | * @param string $x X section of the status --porcelain output |
||
71 | * @param string $y Y section of the status --porcelain output |
||
72 | * @param string $name file name |
||
73 | * @param string $renamed new file name (if renamed) |
||
74 | */ |
||
75 | 8 | private function __construct($x, $y, $name, $renamed) |
|
76 | { |
||
77 | 8 | $this->x = ' ' === $x ? null : $x; |
|
78 | 8 | $this->y = ' ' === $y ? null : $y; |
|
79 | 8 | $this->name = $name; |
|
80 | 8 | $this->renamed = $renamed; |
|
81 | 8 | $this->calculateDescription(); |
|
82 | 8 | } |
|
83 | |||
84 | /** |
||
85 | * @param string $x X section of the status --porcelain output |
||
86 | * @param string $y Y section of the status --porcelain output |
||
87 | * @param string $name file name |
||
88 | * @param string $renamed new file name (if renamed) |
||
89 | * |
||
90 | * @return StatusFile |
||
91 | */ |
||
92 | 8 | public static function create($x, $y, $name, $renamed) |
|
96 | |||
97 | /** |
||
98 | * @return bool |
||
99 | */ |
||
100 | 5 | public function isRenamed() |
|
104 | |||
105 | /** |
||
106 | * Get Name |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | public function getName() |
||
114 | |||
115 | /** |
||
116 | * Get the status of the index |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | 5 | public function getIndexStatus() |
|
124 | |||
125 | /** |
||
126 | * Get the status of the working tree |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | 6 | public function getWorkingTreeStatus() |
|
134 | |||
135 | /** |
||
136 | * description of the status |
||
137 | * |
||
138 | * @return string |
||
139 | */ |
||
140 | 8 | public function calculateDescription() |
|
141 | { |
||
142 | 8 | $status = $this->x.$this->y; |
|
143 | $matching = array( |
||
144 | 8 | '/ [MD]/' => 'not updated', |
|
145 | 8 | '/M[MD]/' => 'updated in index', |
|
146 | 8 | '/A[MD]/' => 'added to index', |
|
147 | 8 | '/D[M]/' => 'deleted from index', |
|
148 | 8 | '/R[MD]/' => 'renamed in index', |
|
149 | 8 | '/C[MD]/' => 'copied in index', |
|
150 | 8 | '/[MARC] /' => 'index and work tree matches', |
|
151 | 8 | '/[MARC]M/' => 'work tree changed since index', |
|
152 | 8 | '/[MARC]D/' => 'deleted in work tree', |
|
153 | 8 | '/DD/' => 'unmerged, both deleted', |
|
154 | 8 | '/AU/' => 'unmerged, added by us', |
|
155 | 8 | '/UD/' => 'unmerged, deleted by them', |
|
156 | 8 | '/UA/' => 'unmerged, added by them', |
|
157 | 8 | '/DU/' => 'unmerged, deleted by us', |
|
158 | 8 | '/AA/' => 'unmerged, both added', |
|
159 | 8 | '/UU/' => 'unmerged, both modified', |
|
160 | 8 | '/\?\?/' => 'untracked', |
|
161 | 8 | '/!!/' => 'ignored', |
|
162 | 8 | ); |
|
163 | 8 | $out = array(); |
|
164 | 8 | foreach ($matching as $pattern => $label) { |
|
165 | 8 | if (preg_match($pattern, $status)) { |
|
166 | 4 | $out[] = $label; |
|
167 | 4 | } |
|
168 | 8 | } |
|
169 | |||
170 | 8 | $this->description = implode(', ', $out); |
|
171 | 8 | } |
|
172 | |||
173 | /** |
||
174 | * Set Description |
||
175 | * |
||
176 | * @param string $description the description variable |
||
177 | */ |
||
178 | public function setDescription($description) |
||
182 | |||
183 | /** |
||
184 | * Get Description |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | 1 | public function getDescription() |
|
192 | |||
193 | /** |
||
194 | * Set Type |
||
195 | * |
||
196 | * @param string $type the type variable |
||
197 | */ |
||
198 | public function setType($type) |
||
202 | |||
203 | /** |
||
204 | * Get Type |
||
205 | * |
||
206 | * @return string |
||
207 | */ |
||
208 | public function getType() |
||
212 | } |
||
213 |