218 ! ! |
218 ! ! |
219 |
219 |
220 !HGCommand class methodsFor:'accessing'! |
220 !HGCommand class methodsFor:'accessing'! |
221 |
221 |
222 hgCommand |
222 hgCommand |
223 | h | |
223 "Returns absolute path to hg executable to use" |
224 |
224 |
225 HGExecutable notNil ifTrue:[ |
|
226 ^ HGExecutable |
|
227 ]. |
|
228 HGExecutable := UserPreferences current hgCommand. |
|
229 HGExecutable isNil ifTrue:[ |
225 HGExecutable isNil ifTrue:[ |
230 OperatingSystem isMSWINDOWSlike ifTrue:[ |
226 | executable | |
231 "/ h := Win32OperatingSystem registryEntry |
227 executable := UserPreferences current hgCommand. |
232 "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'. |
228 executable isNil ifTrue:[ |
233 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
229 OperatingSystem isMSWINDOWSlike ifTrue:[ |
234 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
230 "/ | h | |
235 HGExecutable := OperatingSystem pathOfCommand:'hg'. |
231 "/ |
236 ] ifFalse:[ |
232 "/ h := Win32OperatingSystem registryEntry |
237 OperatingSystem isUNIXlike ifTrue:[ |
233 "/ key:'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\App Paths\svn.exe'. |
238 HGExecutable := OperatingSystem pathOfCommand:'hg'. |
234 "/ h notNil ifTrue:[HGExecutable := h valueNamed:'']. |
239 ] |
235 "/ HGExecutable notEmptyOrNil ifTrue:[^HGExecutable] |
|
236 executable := OperatingSystem pathOfCommand:'hg'. |
|
237 ] ifFalse:[ |
|
238 OperatingSystem isUNIXlike ifTrue:[ |
|
239 executable := OperatingSystem pathOfCommand:'hg'. |
|
240 ] |
|
241 ]. |
240 ]. |
242 ]. |
241 ]. |
243 executable := self hgCommandValidate: executable. |
242 HGExecutable isNil ifTrue:[ |
244 HGExecutable := executable. |
243 self error:'''hg'' executable not found!!'. |
|
244 ]. |
245 ]. |
245 ^ HGExecutable |
246 ^ HGExecutable |
246 |
247 |
247 " |
248 " |
248 HGExecutable := nil. |
249 HGExecutable := nil. |
249 self basicNew executable" |
250 self basicNew executable |
|
251 " |
250 |
252 |
251 "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
253 "Created: / 19-11-2012 / 21:48:29 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
252 "Modified: / 19-11-2012 / 23:21:33 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
254 "Modified: / 21-02-2014 / 08:54:52 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
253 ! |
255 ! |
254 |
256 |
255 hgCommand: command |
257 hgCommand: command |
256 HGExecutable := command |
258 HGExecutable := command |
257 |
259 |
260 HGCommand hgCommand: '/usr/bin/hg' |
262 HGCommand hgCommand: '/usr/bin/hg' |
261 " |
263 " |
262 |
264 |
263 "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
265 "Created: / 19-11-2012 / 21:49:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
264 "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
266 "Modified (comment): / 03-03-2013 / 12:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
267 ! |
|
268 |
|
269 hgCommandValidate: executable |
|
270 "/ Given a `executable`, checks whether it is a valid hg binary. |
|
271 "/ Returns absolute path to hg binary or raise an |
|
272 "/ HGInvalidExecutableError or HGInvalidVersionError |
|
273 "/ if `executable` is not valid hg binary. |
|
274 "/ |
|
275 | path version | |
|
276 |
|
277 path := executable asFilename. |
|
278 path isAbsolute ifFalse:[ |
|
279 path := path asAbsoluteFilename. |
|
280 path exists ifFalse:[ |
|
281 "/ Also try to find specified command along PATH, maybe somebody |
|
282 "/ just typed 'hg' in... |
|
283 (executable includes: Filename separator) ifFalse:[ |
|
284 path := (OperatingSystem pathOfCommand: executable). |
|
285 path isNil ifTrue:[ |
|
286 HGInvalidExecutableError raiseErrorString:('''hg'' executable (%1) not found!!' bindWith: executable). |
|
287 ^ nil |
|
288 ]. |
|
289 ^ path |
|
290 ]. |
|
291 ]. |
|
292 ]. |
|
293 path exists ifFalse:[ |
|
294 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) does not exists!!' bindWith: path pathName). |
|
295 ^ nil |
|
296 ]. |
|
297 path isDirectory ifTrue:[ |
|
298 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is actually a directory!!' bindWith: path pathName). |
|
299 ^ nil |
|
300 ]. |
|
301 path isExecutable ifFalse:[ |
|
302 HGInvalidExecutableError raiseErrorString:('Specified ''hg'' executable (%1) is cannot be executed!!' bindWith: path pathName). |
|
303 ^ nil |
|
304 ]. |
|
305 [ |
|
306 version := self hgVersionOf: path pathName. |
|
307 ] on: Error do:[:ex | |
|
308 HGInvalidExecutableError newException |
|
309 parameter: ex; |
|
310 messageText: 'Failed to check version: ', ex description; |
|
311 raise. |
|
312 ^ nil |
|
313 ]. |
|
314 (self hgVersionIsSupported: version) ifFalse:[ |
|
315 HGInvalidVersionError newException |
|
316 parameter: version; |
|
317 messageText: ('Unsuported Mercurial version (%1)' bindWith: (version asStringWith:$.)); |
|
318 raise. |
|
319 ^ nil |
|
320 ]. |
|
321 ^ path pathName |
|
322 |
|
323 "Created: / 21-02-2014 / 08:50:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
324 "Modified: / 21-02-2014 / 10:31:02 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
265 ! |
325 ! |
266 |
326 |
267 hgVersion |
327 hgVersion |
268 "Return mercurial version installed on this compiter" |
328 "Return mercurial version installed on this compiter" |
269 |
329 |
1800 |
1860 |
1801 !HGCommand::version methodsFor:'private'! |
1861 !HGCommand::version methodsFor:'private'! |
1802 |
1862 |
1803 arguments |
1863 arguments |
1804 |
1864 |
1805 ^ Array with: HGExecutable with: '--version' |
1865 ^ Array with: self executable with: '--version' |
1806 |
1866 |
1807 "Created: / 19-11-2012 / 20:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1867 "Created: / 19-11-2012 / 20:01:15 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
1868 "Modified: / 21-02-2014 / 00:20:21 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1808 ! |
1869 ! |
1809 |
1870 |
1810 parseOutput:stream |
1871 parseOutput:stream |
1811 "Parses output of 'hg' command, i.e. commit, log, update, checkout, |
1872 "Parses output of 'hg' command, i.e. commit, log, update, checkout, |
1812 etc." |
1873 etc." |