Skip to content

Commit 1c4f3d7

Browse files
committed
Rename Repo.findrepo to Repo.findparent which is what the method doe.
Disallow execution of mbed commands without program root Fixed Repo.remove() routine Fixed corner case where `mbed update` won't remove obsolete libraries
1 parent 97cba11 commit 1c4f3d7

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

mbed/mbed.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -784,23 +784,19 @@ def fromlib(cls, lib=None):
784784
@classmethod
785785
def fromrepo(cls, path=None):
786786
repo = cls()
787-
repo.is_cwd = True
788787
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())
797793

798794
repo.path = os.path.abspath(path)
799795
repo.name = os.path.basename(repo.path)
800796

801797
repo.sync()
802798

803-
if not repo.is_cwd and repo.scm is None:
799+
if repo.scm is None:
804800
warning(
805801
"Program \"%s\" in \"%s\" does not use source control management.\n"
806802
"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):
816812
return False
817813

818814
@classmethod
819-
def findrepo(cls, path=None):
815+
def findparent(cls, path=None):
820816
path = os.path.abspath(path or os.getcwd())
821817

822818
while cd(path):
@@ -837,7 +833,7 @@ def pathtype(cls, path=None):
837833
depth = 0
838834
while cd(path):
839835
tpath = path
840-
path = Repo.findrepo(path)
836+
path = Repo.findparent(path)
841837
if path:
842838
depth += 1
843839
path = os.path.split(path)[0]
@@ -883,7 +879,7 @@ def sync(self):
883879
self.url = self.geturl()
884880
if not self.url:
885881
self.is_local = True
886-
ppath = self.findrepo(os.path.split(self.path)[0])
882+
ppath = self.findparent(os.path.split(self.path)[0])
887883
self.url = relpath(ppath, self.path).replace("\\", "/") if ppath else os.path.basename(self.path)
888884
except ProcessException:
889885
pass
@@ -927,7 +923,7 @@ def remove(self, dest, *args, **kwargs):
927923
os.remove(dest)
928924
except OSError:
929925
pass
930-
return self.__scm_call('remove', dest, *args, **kwargs)
926+
return self.scm.remove(dest, *args, **kwargs)
931927

932928
def getlibs(self):
933929
for root, dirs, files in os.walk(self.path):
@@ -1034,9 +1030,9 @@ def __init__(self, path=None, print_warning=False):
10341030
# is_cwd flag indicates that current dir is assumed to be root, not root repo
10351031
if self.is_cwd and print_warning:
10361032
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+
10401036
# Sets config value
10411037
def set_cfg(self, var, val):
10421038
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
12761272
global cwd_root
12771273

12781274
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
12801276
if program and library:
12811277
error("Cannot use both --program and --library options.", 1)
12821278
elif not program and not library:
@@ -1515,6 +1511,8 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
15151511
sync()
15161512

15171513
repo = Repo.fromrepo()
1514+
# A copy of repo containing the .lib layout before updating
1515+
repo_orig = Repo.fromrepo()
15181516

15191517
if top and not rev and repo.isdetached():
15201518
error(
@@ -1549,7 +1547,7 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
15491547
repo.write()
15501548

15511549
# 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:
15531551
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
15541552
gc = False
15551553
with cd(lib.path):

0 commit comments

Comments
 (0)