@@ -233,7 +233,7 @@ def init(path, url):
233
233
with cd (path ):
234
234
Bld .seturl (url )
235
235
236
- def clone (url , path = None , rev = None , depth = None , protocol = None ):
236
+ def clone (url , path = None , depth = None , protocol = None ):
237
237
m = Bld .isurl (url )
238
238
if not m :
239
239
raise ProcessException (1 , "Not an mbed library build URL" )
@@ -244,7 +244,21 @@ def clone(url, path=None, rev=None, depth=None, protocol=None):
244
244
except Exception as e :
245
245
error (e [1 ], e [0 ])
246
246
247
- def dlunzip (url , rev ):
247
+ def add (dest ):
248
+ return True
249
+
250
+ def remove (dest ):
251
+ if os .path .isfile (dest ):
252
+ os .remove (dest )
253
+ return True
254
+
255
+ def commit ():
256
+ error ("mbed library builds do not support committing" )
257
+
258
+ def publish (all = None ):
259
+ return False
260
+
261
+ def fetch (url , rev ):
248
262
tmp_file = '.rev-' + rev + '.zip'
249
263
arch_dir = 'mbed-' + rev
250
264
try :
@@ -267,54 +281,38 @@ def dlunzip(url, rev):
267
281
rmtree_readonly (arch_dir )
268
282
raise Exception (128 , "An error occurred while unpacking mbed library archive \" %s\" in \" %s\" " % (tmp_file , os .getcwd ()))
269
283
270
- def add (dest ):
271
- return True
272
-
273
- def remove (dest ):
274
- if os .path .isfile (dest ):
275
- os .remove (dest )
276
- return True
277
-
278
- def commit ():
279
- error ("mbed library builds do not support committing" )
280
-
281
- def publish (repo , all = None ):
282
- error ("mbed library builds do not support pushing" )
283
-
284
- def fetch (repo ):
285
- error ("mbed library builds do not support pushing" )
286
-
287
- def checkout (repo , rev , clean = False ):
284
+ def checkout (rev ):
288
285
url = Bld .geturl ()
289
286
m = Bld .isurl (url )
290
287
if not m :
291
288
raise ProcessException (1 , "Not an mbed library build URL" )
292
289
return False
293
290
291
+ log ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
294
292
arch_url = m .group (1 ) + '/archive/' + rev + '.zip'
295
293
arch_dir = m .group (7 ) + '-' + rev
296
-
297
294
try :
298
295
if not os .path .exists (arch_dir ):
299
- Bld .dlunzip (arch_url , rev )
296
+ Bld .fetch (arch_url , rev )
300
297
except Exception as e :
301
298
if os .path .exists (arch_dir ):
302
299
rmtree_readonly (arch_dir )
303
300
error (e [1 ], e [0 ])
304
301
Bld .seturl (url + '/' + rev )
305
302
306
- def update (repo , rev = None , clean = False ):
307
- m = Bld .isurl (repo .url )
303
+ def update (rev = None , clean = False , is_local = False ):
304
+ url = Bld .geturl ()
305
+ m = Bld .isurl (url )
308
306
rev = Hg .remoteid (m .group (1 ), rev )
309
307
if not rev :
310
308
error ("Unable to fetch late mbed library revision" )
311
309
312
- if rev != repo . rev :
310
+ if rev != Bld . getrev () :
313
311
log ("Cleaning up library build folder" )
314
312
for fl in os .listdir ('.' ):
315
313
if not fl .startswith ('.' ):
316
314
os .remove (fl ) if os .path .isfile (fl ) else shutil .rmtree (fl )
317
- return Bld .checkout (repo , rev )
315
+ return Bld .checkout (rev )
318
316
319
317
def status ():
320
318
return False
@@ -384,14 +382,8 @@ def isurl(url):
384
382
def init (path = None ):
385
383
popen ([hg_cmd , 'init' ] + ([path ] if path else []) + (['-v' ] if verbose else ['-q' ]))
386
384
387
- def clone (url , name = None , rev = None , depth = None , protocol = None ):
385
+ def clone (url , name = None , depth = None , protocol = None ):
388
386
popen ([hg_cmd , 'clone' , formaturl (url , protocol ), name ] + (['-v' ] if verbose else ['-q' ]))
389
- if rev :
390
- with cd (name ):
391
- try :
392
- Hg .checkout (None , rev )
393
- except ProcessException :
394
- error ("Unable to update to revision \" %s\" " % rev , 1 )
395
387
396
388
def add (dest ):
397
389
log ("Adding reference \" %s\" " % dest )
@@ -414,24 +406,27 @@ def remove(dest):
414
406
def commit ():
415
407
popen ([hg_cmd , 'commit' ] + (['-v' ] if verbose else ['-q' ]))
416
408
417
- def publish (repo , all = None ):
409
+ def publish (all = None ):
418
410
popen ([hg_cmd , 'push' ] + (['--new-branch' ] if all else []) + (['-v' ] if verbose else ['-q' ]))
419
411
420
- def fetch (repo ):
421
- log ("Pulling remote repository \" %s \" to local \" %s\" " % ( repo . url , repo . name ))
412
+ def fetch ():
413
+ log ("Fetching revisions from remote repository to \" %s\" " % os . path . basename ( os . getcwd () ))
422
414
popen ([hg_cmd , 'pull' ] + (['-v' ] if verbose else ['-q' ]))
423
415
424
- def checkout (repo , rev , clean = False ):
425
- if not rev :
426
- return False
427
- if repo :
428
- log ("Checkout \" %s\" to %s" % (repo .name , repo .revtype (rev , True )))
429
- popen ([hg_cmd , 'update' ] + (['-r' , rev ] if rev else []) + (['-C' ] if clean else []) + (['-v' ] if verbose else ['-q' ]))
416
+ def discard ():
417
+ log ("Discarding local changes in \" %s\" " % os .path .basename (os .getcwd ()))
418
+ popen ([hg_cmd , 'update' , '-C' ] + (['-v' ] if verbose else ['-q' ]))
430
419
431
- def update (repo , rev = None , clean = False ):
432
- if not repo .is_local :
433
- Hg .fetch (repo )
434
- Hg .checkout (repo , rev , clean )
420
+ def checkout (rev ):
421
+ log ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
422
+ popen ([hg_cmd , 'update' ] + (['-r' , rev ] if rev else []) + (['-v' ] if verbose else ['-q' ]))
423
+
424
+ def update (rev = None , clean = False , is_local = False ):
425
+ if clean :
426
+ Hg .discard ()
427
+ if not is_local :
428
+ Hg .fetch ()
429
+ Hg .checkout (rev )
435
430
436
431
def status ():
437
432
return pquery ([hg_cmd , 'status' ] + (['-v' ] if verbose else ['-q' ]))
@@ -563,14 +558,8 @@ def isurl(url):
563
558
def init (path = None ):
564
559
popen ([git_cmd , 'init' ] + ([path ] if path else []) + ([] if verbose else ['-q' ]))
565
560
566
- def clone (url , name = None , rev = None , depth = None , protocol = None ):
561
+ def clone (url , name = None , depth = None , protocol = None ):
567
562
popen ([git_cmd , 'clone' , formaturl (url , protocol ), name ] + (['--depth' , depth ] if depth else []) + (['-v' ] if verbose else ['-q' ]))
568
- if rev :
569
- with cd (name ):
570
- try :
571
- Git .checkout (None , rev )
572
- except ProcessException :
573
- error ("Unable to update to revision \" %s\" " % rev , 1 )
574
563
575
564
def add (dest ):
576
565
log ("Adding reference " + dest )
@@ -593,11 +582,7 @@ def remove(dest):
593
582
def commit ():
594
583
popen ([git_cmd , 'commit' , '-a' ] + (['-v' ] if verbose else ['-q' ]))
595
584
596
- def merge (repo , dest ):
597
- log ("Merging \" %s\" with \" %s\" " % (repo .name , dest ))
598
- popen ([git_cmd , 'merge' , dest ] + (['-v' ] if verbose else ['-q' ]))
599
-
600
- def publish (repo , all = None ):
585
+ def publish (all = None ):
601
586
if all :
602
587
popen ([git_cmd , 'push' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
603
588
else :
@@ -606,27 +591,28 @@ def publish(repo, all=None):
606
591
if remote and branch :
607
592
popen ([git_cmd , 'push' , remote , branch ] + (['-v' ] if verbose else ['-q' ]))
608
593
else :
609
- err = "Unable to publish outgoing changes for \" %s\" in \" %s\" .\n " % (repo . name , repo . path )
594
+ err = "Unable to publish outgoing changes for \" %s\" in \" %s\" .\n " % (os . path . basename ( os . getcwd ()), os . getcwd () )
610
595
if not remote :
611
596
error (err + "The local repository is not associated with a remote one." , 1 )
612
597
if not branch :
613
598
error (err + "Working set is not on a branch." , 1 )
614
599
615
- def fetch (repo ):
616
- log ("Fetching remote repository \" %s \" to local \" %s\" " % ( repo . url , repo . name ))
600
+ def fetch ():
601
+ log ("Fetching revisions from remote repository to \" %s\" " % os . path . basename ( os . getcwd () ))
617
602
popen ([git_cmd , 'fetch' , '--all' ] + (['-v' ] if verbose else ['-q' ]))
618
603
619
- def discard (repo ):
620
- log ("Discarding local changes in \" %s\" " % repo . name )
604
+ def discard ():
605
+ log ("Discarding local changes in \" %s\" " % os . path . basename ( os . getcwd ()) )
621
606
popen ([git_cmd , 'reset' , 'HEAD' ] + ([] if verbose else ['-q' ])) # unmarks files for commit
622
607
popen ([git_cmd , 'checkout' , '.' ] + ([] if verbose else ['-q' ])) # undo modified files
623
608
popen ([git_cmd , 'clean' , '-fdq' ] + ([] if verbose else ['-q' ])) # cleans up untracked files and folders
624
609
625
- def checkout (repo , rev , clean = False ):
626
- if not rev :
627
- return False
628
- if repo :
629
- log ("Checkout \" %s\" to %s" % (repo .name , repo .revtype (rev , True )))
610
+ def merge (dest ):
611
+ log ("Merging \" %s\" with \" %s\" " % (os .path .basename (os .getcwd ()), dest ))
612
+ popen ([git_cmd , 'merge' , dest ] + (['-v' ] if verbose else ['-q' ]))
613
+
614
+ def checkout (rev ):
615
+ log ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
630
616
popen ([git_cmd , 'checkout' , rev ] + ([] if verbose else ['-q' ]))
631
617
if Git .isdetached (): # try to find associated refs to avoid detached state
632
618
refs = Git .getrefs (rev )
@@ -636,20 +622,20 @@ def checkout(repo, rev, clean=False):
636
622
popen ([git_cmd , 'checkout' , branch ] + ([] if verbose else ['-q' ]))
637
623
break
638
624
639
- def update (repo , rev = None , clean = False ):
625
+ def update (rev = None , clean = False , is_local = False ):
640
626
if clean :
641
- Git .discard (repo )
642
- if not repo . is_local :
643
- Git .fetch (repo )
627
+ Git .discard ()
628
+ if not is_local :
629
+ Git .fetch ()
644
630
if rev :
645
- Git .checkout (repo , rev , clean )
631
+ Git .checkout (rev )
646
632
else :
647
633
remote = Git .getremote ()
648
634
branch = Git .getbranch ()
649
635
if remote and branch :
650
- Git .merge (repo , '%s/%s' % (remote , branch ))
636
+ Git .merge ('%s/%s' % (remote , branch ))
651
637
else :
652
- err = "Unable to update \" %s\" in \" %s\" .\n " % (repo . name , repo . path )
638
+ err = "Unable to update \" %s\" in \" %s\" .\n " % (os . path . basename ( os . getcwd ()), os . getcwd () )
653
639
if not remote :
654
640
log (err + "The local repository is not associated with a remote one." )
655
641
if not branch :
@@ -1347,9 +1333,9 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1347
1333
scm .clone (repo .url , repo .path , depth = depth , protocol = protocol )
1348
1334
with cd (repo .path ):
1349
1335
try :
1350
- scm .checkout ( repo , repo .rev , True )
1336
+ scm .update ( repo .rev , True )
1351
1337
except ProcessException as e :
1352
- err = "Unable to checkout \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
1338
+ err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (repo .rev , True ))
1353
1339
if depth :
1354
1340
err = err + ("\n The --depth option might prevent fetching the whole revision tree and checking out %s." % (repo .revtype (repo .rev , True )))
1355
1341
warning (err ) if ignore else error (err , e [0 ])
@@ -1358,7 +1344,8 @@ def import_(url, path=None, ignore=False, depth=None, protocol=None, top=True):
1358
1344
if os .path .isdir (repo .path ):
1359
1345
rmtree_readonly (repo .path )
1360
1346
else :
1361
- error ("Unable to clone repository (%s)" % url , 1 )
1347
+ err = "Unable to clone repository (%s)" % url
1348
+ warning (err ) if ignore else error (err , e [0 ])
1362
1349
1363
1350
repo .sync ()
1364
1351
@@ -1464,7 +1451,7 @@ def publish(all=None, top=True):
1464
1451
outgoing = repo .scm .outgoing ()
1465
1452
if outgoing > 0 :
1466
1453
action ("Pushing local repository \" %s\" to remote \" %s\" " % (repo .name , repo .url ))
1467
- repo .scm .publish (repo , all )
1454
+ repo .scm .publish (all )
1468
1455
except ProcessException as e :
1469
1456
if e [0 ] != 1 :
1470
1457
raise e
@@ -1502,7 +1489,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
1502
1489
repo .revtype (rev , True )))
1503
1490
1504
1491
try :
1505
- repo .scm .update (repo , rev , clean )
1492
+ repo .scm .update (rev , clean , repo . is_local )
1506
1493
except ProcessException as e :
1507
1494
err = "Unable to update \" %s\" to %s" % (repo .name , repo .revtype (rev , True ))
1508
1495
if depth :
0 commit comments