[DEV] update the sync-local action

This commit is contained in:
Edouard DUPIN 2019-07-30 23:38:06 +02:00
parent 833792cd81
commit 42a432a004
2 changed files with 54 additions and 18 deletions

View File

@ -51,36 +51,50 @@ def execute(_arguments):
reset_instead_of_rebase = True
debug.info("==> Request reset instead of rebase")
else:
"""
debug.error("SYNC Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'")
debug.error("SYNC Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'", ret_value=env.ret_action_wrong_parameters)
# check if .XXX exist (create it if needed)
if os.path.exists(env.get_island_path()) == False \
or os.path.exists(env.get_island_path_config()) == False \
or os.path.exists(env.get_island_path_manifest()) == False:
debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'")
debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'", ret_value=env.ret_manifest_is_not_existing)
configuration = config.Config()
# TODO: Load Old manifect to check diff ...
#debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
#is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest())
#if is_modify_manifest == True:
# commands.fetch(env.get_island_path_manifest(), "origin")
#else:
# commands.pull(env.get_island_path_manifest(), "origin")
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
is_modify_manifest = commands.check_repository_is_modify(env.get_island_path_manifest())
if is_modify_manifest == True:
debug.warning("Manifest is modify")
else:
ret_track = commands.get_current_tracking_branch(env.get_island_path_manifest())
is_forward = commands.is_forward(env.get_island_path_manifest(), ret_track)
if is_forward == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the MANIFEST is forward the remote branch " + str(commands.get_forward(env.get_island_path_manifest(), ret_track)))
else:
debug.verbose("Check behind:")
is_behind = commands.is_behind(env.get_island_path_manifest(), ret_track)
if is_behind == False:
# fetch the repository
debug.info("sync-local: MANIFEST is up-to-date")
else:
if reset_instead_of_rebase == True:
debug.info("sync-local: MANIFEST Reset to " + ret_track)
commands.reset_hard(env.get_island_path_manifest(), ret_track)
else:
debug.info("sync-local: MANIFEST Rebase to " + ret_track)
commands.rebase(env.get_island_path_manifest(), ret_track)
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration.get_manifest_name())
if os.path.exists(file_source_manifest) == False:
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'")
debug.error("Missing manifest file : '" + str(file_source_manifest) + "'", ret_value=env.ret_manifest_is_not_existing)
mani = manifest.Manifest(file_source_manifest)
all_project = mani.get_all_configs()
debug.info("synchronize : " + str(len(all_project)) + " projects")
id_element = 0
count_error = 0
for elem in all_project:
id_element += 1
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
@ -91,28 +105,34 @@ def execute(_arguments):
if os.path.exists(git_repo_path) == False:
# The Repository does not exist ==> Nothing to do...
debug.warning("sync-local: ==> Not download")
count_error += 1
continue
if os.path.exists(os.path.join(git_repo_path,".git")) == False:
# path already exist but it is not used to as a git repo ==> this is an error
debug.warning("sync-local: is already existing but not used for a git repository. Remove it and sync")
count_error += 1
continue
# simply update the repository ...
debug.verbose("Check modify:")
is_modify = commands.check_repository_is_modify(git_repo_path)
if is_modify == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the repository is modified (pass through)")
count_error += 1
continue
debug.verbose("Check tracking and local branch:")
# get tracking branch
ret_track = commands.get_current_tracking_branch(git_repo_path)
select_branch = commands.get_current_branch(git_repo_path)
debug.info("sync-local: check: " + select_branch + " ==> " + ret_track)
debug.debug("sync-local: check: " + select_branch + " ==> " + ret_track)
debug.verbose("Check forward:")
is_forward = commands.is_forward(git_repo_path, ret_track)
if is_forward == True:
# fetch the repository
debug.warning("sync-local: Not update ==> the repository is forward the remote branch " + str(commands.get_forward(git_repo_path, ret_track)))
count_error += 1
continue
debug.verbose("Check behind:")
is_behind = commands.is_behind(git_repo_path, ret_track)
@ -120,7 +140,18 @@ def execute(_arguments):
# fetch the repository
debug.info("sync-local: Nothing to do.")
continue
if reset_instead_of_rebase == True:
debug.info("sync-local: Reset to " + ret_track)
commands.reset_hard(git_repo_path, ret_track)
else:
debug.info("sync-local: Reset to " + ret_track)
commands.rebase(git_repo_path, ret_track)
if count_error != 0:
debug.info(" ***********************************************************")
debug.info(" ** local sync partial warning on " + str(count_error) + " repository")
debug.info(" ***********************************************************")
return env.ret_action_partial_done
return None
debug.info("sync-local: Reset to " + ret_track)
commands.reset_hard(git_repo_path, ret_track)

View File

@ -130,3 +130,8 @@ def get_island_path_user_config():
return island_path_user_config
ret_manifest_is_not_existing = -5
ret_action_is_not_existing = -10
ret_action_executing_system_error = -11
ret_action_wrong_parameters = -12
ret_action_partial_done = -13