Skip to content

Commit

Permalink
EdkRepo: Sync -u should support repository Local directory renames an…
Browse files Browse the repository at this point in the history
…d/or URL changes

Updated comments to better describe the process of updating the
local manifest file.

Removed the exception that was raised when a URL change was
detected.

Updated the calculation of sources_to_move, sources_to_remove
and sources_to_clone so that the inital repository is moved
to an archival location and the updated respository is cloned.

Signed-off-by: Ashley E Desimone <[email protected]>
  • Loading branch information
ashedesimone committed Jun 4, 2021
1 parent 94cd7ab commit 19fd597
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
37 changes: 23 additions & 14 deletions edkrepo/commands/sync_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from edkrepo.common.humble import NO_SYNC_DETACHED_HEAD, SYNC_COMMITS_ON_TARGET, SYNC_ERROR
from edkrepo.common.humble import MIRROR_BEHIND_PRIMARY_REPO, SYNC_NEEDS_REBASE, INCLUDED_FILE_NAME
from edkrepo.common.humble import SYNC_BRANCH_CHANGE_ON_LOCAL, SYNC_INCOMPATIBLE_COMBO
from edkrepo.common.humble import SYNC_REBASE_CALC_FAIL
from edkrepo.common.humble import SYNC_REBASE_CALC_FAIL, SYNC_MOVE_FAILED
from edkrepo.common.pathfix import get_actual_path, expanduser
from edkrepo.common.common_cache_functions import get_repo_cache_obj
from edkrepo.common.common_repo_functions import clone_repos, sparse_checkout_enabled
Expand Down Expand Up @@ -294,12 +294,6 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path
write_included_config(new_manifest_to_check.remotes, new_manifest_to_check.submodule_alternate_remotes, local_manifest_dir)

self.__check_submodule_config(workspace_path, new_manifest_to_check, new_sources_for_current_combo)
new_manifest_remotes = {name:url for name, url in new_manifest_to_check.remotes}
#check for changes to remote urls
for remote_name in initial_manifest_remotes.keys():
if remote_name in new_manifest_remotes.keys():
if initial_manifest_remotes[remote_name] != new_manifest_remotes[remote_name]:
raise EdkrepoManifestChangedException(SYNC_URL_CHANGE.format(remote_name))

# Check that the repo sources lists are the same. If they are not the same and the override flag is not set, throw an exception.
if not args.override and set(initial_sources) != set(new_sources):
Expand All @@ -315,10 +309,13 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path
if initial.root == new.root:
if initial.remote_name == new.remote_name:
if initial.remote_url == new.remote_url:
# If the source is unchanged between the old and the new manifest,
# add it to the common lists
common = True
initial_common.append(initial)
new_common.append(new)
break
# If the source is different between the old and the new manifest, add it to the uncommon list
if not common:
uncommon_sources.append(initial)
for new in new_sources:
Expand All @@ -329,6 +326,7 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path
if new.remote_url == initial.remote_url:
common = True
break
# If the source is different between the old and the new manifest, add it to the uncommon list
if not common:
uncommon_sources.append(new)
uncommon_sources = set(uncommon_sources)
Expand All @@ -345,23 +343,34 @@ def __update_local_manifest(self, args, config, initial_manifest, workspace_path
if source_to_check.remote_url == source.remote_url:
found_source = True
break
# If the source that is different came from the old manifest, then it is now outdated and either needs
# to be deleted or moved to a archival location.
if found_source:
sources_to_remove.append(source)
else:
roots = [s.root for s in initial_sources]
roots = [s.root for s in new_sources]
# If there is a source in the new manifest that goes into the same folder name as a source in the
# old manifest, then we need to move that old folder to an archival location.
if source.root in roots:
#In theory, this should never happen, we should hit the SYNC_URL_CHANGE error
#this is here as a catch all
sources_to_move.append(source)
else:
sources_to_clone.append(source)
# If it doesn't exist at all in the new manifest, tell the user it is old and no longer used.
sources_to_remove.append(source)
else:
# If the source that is different came from the new manifest, then we need to clone that new
# Git repository.
sources_to_clone.append(source)
init_color_console(False)
# Move the obsolete Git repositories to archival locations.
for source in sources_to_move:
old_dir = os.path.join(workspace_path, source.root)
new_dir = generate_name_for_obsolete_backup(old_dir)
print(SYNC_SOURCE_MOVE_WARNING.format(source.root, new_dir))
new_dir = os.path.join(workspace_path, new_dir)
shutil.move(old_dir, new_dir)
try:
shutil.move(old_dir, new_dir)
except:
print(SYNC_MOVE_FAILED.format(initial_dir=source.root, new_dir=new_dir))
raise
# Tell the user about any Git repositories that are no longer used.
if len(sources_to_remove) > 0:
print(SYNC_REMOVE_WARNING)
for source in sources_to_remove:
Expand Down
5 changes: 5 additions & 0 deletions edkrepo/common/humble.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@
NO_SYNC_DETACHED_HEAD = 'No need to sync repo {0} since it is in detached HEAD state'
SYNC_MANIFEST_UPDATE = 'To update to the latest manifest please run edkrepo sync --update-local-manifest. {}'.format(Fore.RESET)
SYNC_REMOVE_LIST_END_FORMATTING = '{}'.format(Style.RESET_ALL)
SYNC_MOVE_FAILED = '''{}{}WARNING:{}{} Moving {{initial_dir}} to {{new_dir}} failed.
{}{}{}Most likely files from the original directory are open in an editor or IDE.
It is likely that {{new_dir}} contains your original code now.
Please close any open editors to reconcile this problem.
You may need to manually rename {{new_dir}} to {{initial_dir}} in some circumstances.\n{}'''.format(Style.BRIGHT, Fore.RED, Style.RESET_ALL, Fore.RED, Style.RESET_ALL, Style.BRIGHT, Fore.YELLOW, Style.RESET_ALL)

#error messages for clone_command.py
CLONE_EXIT = '\nExiting without performing clone operation.'
Expand Down

0 comments on commit 19fd597

Please sign in to comment.