@@ -784,23 +784,19 @@ def fromlib(cls, lib=None):
784
784
@classmethod
785
785
def fromrepo (cls , path = None ):
786
786
repo = cls ()
787
- repo .is_cwd = True
788
787
if path is None :
789
- path = Repo .findrepo (os .getcwd ())
790
- if path :
791
- repo .is_cwd = False
792
- else :
793
- path = os .getcwd ()
794
- warning (
795
- "Could not find mbed program in current path. Assuming current dir.\n "
796
- "You can fix this by calling \" mbed new .\" or \" mbed default root .\" in the root of your program." )
788
+ path = Repo .findparent (os .getcwd ())
789
+ if path is None :
790
+ error (
791
+ "Could not find mbed program in current path \" %s\" .\n "
792
+ "You can fix this by calling \" mbed new .\" or \" mbed default root .\" in the root of your program." % os .getcwd ())
797
793
798
794
repo .path = os .path .abspath (path )
799
795
repo .name = os .path .basename (repo .path )
800
796
801
797
repo .sync ()
802
798
803
- if not repo . is_cwd and repo .scm is None :
799
+ if repo .scm is None :
804
800
warning (
805
801
"Program \" %s\" in \" %s\" does not use source control management.\n "
806
802
"To fix this you should use \" mbed new .\" in the root of your program." % (repo .name , repo .path ))
@@ -816,7 +812,7 @@ def isrepo(cls, path=None):
816
812
return False
817
813
818
814
@classmethod
819
- def findrepo (cls , path = None ):
815
+ def findparent (cls , path = None ):
820
816
path = os .path .abspath (path or os .getcwd ())
821
817
822
818
while cd (path ):
@@ -837,7 +833,7 @@ def pathtype(cls, path=None):
837
833
depth = 0
838
834
while cd (path ):
839
835
tpath = path
840
- path = Repo .findrepo (path )
836
+ path = Repo .findparent (path )
841
837
if path :
842
838
depth += 1
843
839
path = os .path .split (path )[0 ]
@@ -883,7 +879,7 @@ def sync(self):
883
879
self .url = self .geturl ()
884
880
if not self .url :
885
881
self .is_local = True
886
- ppath = self .findrepo (os .path .split (self .path )[0 ])
882
+ ppath = self .findparent (os .path .split (self .path )[0 ])
887
883
self .url = relpath (ppath , self .path ).replace ("\\ " , "/" ) if ppath else os .path .basename (self .path )
888
884
except ProcessException :
889
885
pass
@@ -927,7 +923,7 @@ def remove(self, dest, *args, **kwargs):
927
923
os .remove (dest )
928
924
except OSError :
929
925
pass
930
- return self .__scm_call ( ' remove' , dest , * args , ** kwargs )
926
+ return self .scm . remove ( dest , * args , ** kwargs )
931
927
932
928
def getlibs (self ):
933
929
for root , dirs , files in os .walk (self .path ):
@@ -1034,9 +1030,9 @@ def __init__(self, path=None, print_warning=False):
1034
1030
# is_cwd flag indicates that current dir is assumed to be root, not root repo
1035
1031
if self .is_cwd and print_warning :
1036
1032
warning (
1037
- "Could not find mbed program in current path. Assuming current dir .\n "
1038
- "You can fix this by calling \" mbed new .\" or \" mbed default root .\" in the root of your program." )
1039
-
1033
+ "Could not find mbed program in current path \" %s \" .\n "
1034
+ "You can fix this by calling \" mbed new .\" or \" mbed default root .\" in the root of your program." % self . path )
1035
+
1040
1036
# Sets config value
1041
1037
def set_cfg (self , var , val ):
1042
1038
fl = os .path .join (self .path , self .config_file )
@@ -1276,7 +1272,7 @@ def new(name, scm='git', program=False, library=False, mbedlib=False, create_onl
1276
1272
global cwd_root
1277
1273
1278
1274
d_path = name or os .getcwd ()
1279
- p_path = Repo .findrepo (d_path ) or d_path
1275
+ p_path = Repo .findparent (d_path ) or d_path
1280
1276
if program and library :
1281
1277
error ("Cannot use both --program and --library options." , 1 )
1282
1278
elif not program and not library :
@@ -1515,6 +1511,8 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
1515
1511
sync ()
1516
1512
1517
1513
repo = Repo .fromrepo ()
1514
+ # A copy of repo containing the .lib layout before updating
1515
+ repo_orig = Repo .fromrepo ()
1518
1516
1519
1517
if top and not rev and repo .isdetached ():
1520
1518
error (
@@ -1549,7 +1547,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
1549
1547
repo .write ()
1550
1548
1551
1549
# Compare library references (.lib) before and after update, and remove libraries that do not have references in the current revision
1552
- for lib in repo .libs :
1550
+ for lib in repo_orig .libs :
1553
1551
if not os .path .isfile (lib .lib ) and os .path .isdir (lib .path ): # Library reference doesn't exist in the new revision. Will try to remove library to reproduce original structure
1554
1552
gc = False
1555
1553
with cd (lib .path ):
0 commit comments