Skip to content

Commit 41e2ec6

Browse files
committed
Fixes for local unpublished repos handling:
* do not attempt to fetch/pull for local unpublished repo * do not attempt to update local unpublished repos that do not have any commits Additionally provide a fix for a bug in can_update() that was introduced in df401d6
1 parent 070b195 commit 41e2ec6

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

mbed/mbed.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,10 @@ def pull(repo):
272272
popen([hg_cmd, 'pull'] + (['-v'] if verbose else ['-q']))
273273

274274
def update(repo, hash=None, clean=False):
275-
log("Pulling remote repository \"%s\" to local \"%s\"" % (repo.url, repo.name))
276-
popen([hg_cmd, 'pull'] + (['-v'] if verbose else ['-q']))
277-
log("Updating \"%s\" to %s" % (repo.name, repo.hashtype(hash, True) if hash else "latest revision in the current branch"))
275+
if not repo.is_local:
276+
log("Pulling remote repository \"%s\" to local \"%s\"" % (repo.url, repo.name))
277+
popen([hg_cmd, 'pull'] + (['-v'] if verbose else ['-q']))
278+
log("Updating \"%s\" to %s" % (repo.name, repo.hashtype(hash, True)))
278279
popen([hg_cmd, 'update'] + (['-r', hash] if hash else []) + (['-C'] if clean else []) + (['-v'] if verbose else ['-q']))
279280

280281
def status():
@@ -461,13 +462,15 @@ def update(repo, hash=None, clean=False):
461462
popen([git_cmd, 'checkout', '.'] + ([] if verbose else ['-q'])) # undo modified files
462463
popen([git_cmd, 'clean', '-fdq'] + ([] if verbose else ['-q'])) # cleans up untracked files and folders
463464
if hash:
464-
log("Fetching remote repository \"%s\" to local \"%s\"" % (repo.url, repo.name))
465-
popen([git_cmd, 'fetch', '-v', '--all'] + (['-v'] if verbose else ['-q']))
465+
if not repo.is_local:
466+
log("Fetching remote repository \"%s\" to local \"%s\"" % (repo.url, repo.name))
467+
popen([git_cmd, 'fetch', '-v', '--all'] + (['-v'] if verbose else ['-q']))
466468
log("Updating \"%s\" to %s" % (repo.name, repo.hashtype(hash, True)))
467469
popen([git_cmd, 'checkout'] + [hash] + ([] if verbose else ['-q']))
468470
else:
469-
log("Fetching remote repository \"%s\" to local \"%s\" and updating to latest revision in the current branch" % (repo.url, repo.name))
470-
popen([git_cmd, 'pull', '--all'] + (['-v'] if verbose else ['-q']))
471+
if not repo.is_local:
472+
log("Fetching remote repository \"%s\" to local \"%s\" and updating to latest revision in the current branch" % (repo.url, repo.name))
473+
popen([git_cmd, 'pull', '--all'] + (['-v'] if verbose else ['-q']))
471474

472475
def status():
473476
return pquery([git_cmd, 'status', '-s'] + (['-v'] if verbose else []))
@@ -650,6 +653,8 @@ def pathtype(cls, path=None):
650653

651654
@classmethod
652655
def hashtype(cls, hash, ret_hash=False):
656+
if hash is None or len(hash) == 0:
657+
return 'latest' + (' revision in the current branch' if ret_hash else '')
653658
if re.match(r'^([a-zA-Z0-9]{12,40})$', hash):
654659
return 'rev' + (' #'+hash if ret_hash else '')
655660
else:
@@ -750,11 +755,11 @@ def can_update(self, clean, force):
750755
"Preserving local library \"%s\" in \"%s\".\nPlease publish this library to a remote URL to be able to restore it at any time."
751756
"You can use --ignore switch to ignore all local libraries and update only the published ones.\n"
752757
"You can also use --force switch to remove all local libraries. WARNING: This action cannot be undone." % (self.name, self.path))
753-
if not clean and self.scm.dirty():
758+
elif not clean and self.scm.dirty():
754759
err = (
755760
"Uncommitted changes in \"%s\" in \"%s\".\nPlease discard or stash them first and then retry update.\n"
756761
"You can also use --clean switch to discard all uncommitted changes. WARNING: This action cannot be undone." % (self.name, self.path))
757-
if not force and self.scm.outgoing():
762+
elif not force and self.scm.outgoing():
758763
err = (
759764
"Unpublished changes in \"%s\" in \"%s\".\nPlease publish them first using the \"publish\" command.\n"
760765
"You can also use --force to discard all local commits and replace the library with the one included in this revision. WARNING: This action cannot be undone." % (self.name, self.path))
@@ -919,7 +924,7 @@ def import_(url, path=None, depth=None, protocol=None, top=True):
919924
sorted_scms = sorted(sorted_scms, key=lambda (m, _): not m)
920925

921926
text = "Importing program" if top else "Adding library"
922-
action("%s \"%s\" from \"%s/\"%s" % (text, relpath(cwd_root, repo.path), repo.url, ' at '+(repo.hashtype(repo.hash, True) if repo.hash else '')))
927+
action("%s \"%s\" from \"%s/\"%s" % (text, relpath(cwd_root, repo.path), repo.url, ' at '+(repo.hashtype(repo.hash, True))))
923928
for _, scm in sorted_scms:
924929
try:
925930
scm.clone(repo.url, repo.path, repo.hash, depth=depth, protocol=protocol)
@@ -1053,13 +1058,18 @@ def update(rev=None, clean=False, force=False, ignore=False, top=True, depth=Non
10531058
"This %s is in detached HEAD state, and you won't be able to receive updates from the remote repository until you either checkout a branch or create a new one.\n"
10541059
"You can checkout a branch using \"%s checkout <branch_name>\" command before running \"mbed update\"." % (cwd_type, repo.scm.name), 1)
10551060

1056-
# Fetch from remote repo
1057-
action("Updating %s \"%s\" to %s" % (
1058-
cwd_type if top else cwd_dest,
1059-
os.path.basename(repo.path) if top else relpath(cwd_root, repo.path),
1060-
repo.hashtype(rev, True) if rev else "latest revision in the current branch"))
1061-
repo.scm.update(repo, rev, clean)
1062-
repo.rm_untracked()
1061+
if repo.is_local and not repo.hash:
1062+
action("Skipping unpublished empty %s \"%s\"" % (
1063+
cwd_type if top else cwd_dest,
1064+
os.path.basename(repo.path) if top else relpath(cwd_root, repo.path)))
1065+
else:
1066+
# Fetch from remote repo
1067+
action("Updating %s \"%s\" to %s" % (
1068+
cwd_type if top else cwd_dest,
1069+
os.path.basename(repo.path) if top else relpath(cwd_root, repo.path),
1070+
repo.hashtype(rev, True)))
1071+
repo.scm.update(repo, rev, clean)
1072+
repo.rm_untracked()
10631073

10641074
# Compare library references (.lib) before and after update, and remove libraries that do not have references in the current revision
10651075
for lib in repo.libs:

0 commit comments

Comments
 (0)