[DEV] add sync-local
This commit is contained in:
parent
d5d52537bd
commit
d31e66ac73
107
island/actions/islandAction_sync-local.py
Normal file
107
island/actions/islandAction_sync-local.py
Normal file
@ -0,0 +1,107 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
##
|
||||
## @author Edouard DUPIN
|
||||
##
|
||||
## @copyright 2012, Edouard DUPIN, all right reserved
|
||||
##
|
||||
## @license MPL v2.0 (see license file)
|
||||
##
|
||||
|
||||
from realog import debug
|
||||
from island import tools
|
||||
from island import env
|
||||
from island import config
|
||||
from island import multiprocess
|
||||
from island import manifest
|
||||
from island import commands
|
||||
import os
|
||||
|
||||
|
||||
def help():
|
||||
return "Update all the branche to the trackin branch in local (no remote access)"
|
||||
|
||||
|
||||
def add_specific_arguments(my_args, section):
|
||||
#my_args.add("d", "download", haveParam=False, desc="Just download the 'not download' repository")
|
||||
pass
|
||||
|
||||
def execute(arguments):
|
||||
for elem in arguments:
|
||||
"""if elem.get_option_name() == "download":
|
||||
just_download = True
|
||||
debug.info("find remote name: '" + elem.get_arg() + "'")
|
||||
else:
|
||||
|
||||
"""
|
||||
debug.error("SYNC Wrong argument: '" + elem.get_option_name() + "' '" + elem.get_arg() + "'")
|
||||
|
||||
# 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()) + "'")
|
||||
|
||||
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")
|
||||
|
||||
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) + "'")
|
||||
|
||||
mani = manifest.Manifest(file_source_manifest)
|
||||
|
||||
all_project = mani.get_all_configs()
|
||||
debug.info("synchronize : " + str(len(all_project)) + " projects")
|
||||
id_element = 0
|
||||
for elem in all_project:
|
||||
id_element += 1
|
||||
base_display = tools.get_list_base_display(id_element, len(all_project), elem)
|
||||
debug.info("----------------------------------------------------------------")
|
||||
debug.info("sync-local: " + base_display)
|
||||
#debug.debug("elem : " + str(elem))
|
||||
git_repo_path = os.path.join(env.get_island_root_path(), elem.path)
|
||||
if os.path.exists(git_repo_path) == False:
|
||||
# The Repository does not exist ==> Nothing to do...
|
||||
debug.warning("sync-local: ==> Not download")
|
||||
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")
|
||||
# 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)")
|
||||
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.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)))
|
||||
continue
|
||||
debug.verbose("Check behind:")
|
||||
is_behind = commands.is_behind(git_repo_path, ret_track)
|
||||
if is_behind == False:
|
||||
# fetch the repository
|
||||
debug.info("sync-local: Nothing to do.")
|
||||
continue
|
||||
|
||||
debug.info("sync-local: Reset to " + ret_track)
|
||||
commands.reset_hard(git_repo_path, ret_track)
|
||||
|
@ -311,7 +311,6 @@ def push(path_repository, remote_name, elements):
|
||||
raise "Missing remote_name"
|
||||
if len(elements) == 0:
|
||||
raise "No elements to push on server"
|
||||
|
||||
cmd = 'git push ' + remote_name
|
||||
for elem in elements:
|
||||
cmd += " " + elem
|
||||
@ -338,3 +337,41 @@ def submodule_sync(path_repository, remote_name):
|
||||
"""
|
||||
|
||||
|
||||
|
||||
def get_forward(path_repository, branch_name):
|
||||
if branch_name == None or branch_name == "":
|
||||
raise "get_fast_forward: Missing branch_name"
|
||||
select_branch = get_current_branch(path_repository)
|
||||
# get tracking branch
|
||||
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch)
|
||||
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
|
||||
# count the number of commit fast forward
|
||||
forward_count = 0
|
||||
for elem_sha1 in ret_current_branch_sha1:
|
||||
if elem_sha1 not in ret_track_branch_sha1:
|
||||
forward_count += 1
|
||||
return forward_count
|
||||
|
||||
def is_forward(path_repository, branch_name):
|
||||
return get_forward(path_repository, branch_name) != 0;
|
||||
|
||||
|
||||
|
||||
def get_behind(path_repository, branch_name):
|
||||
if branch_name == None or branch_name == "":
|
||||
raise "get_fast_forward: Missing branch_name"
|
||||
select_branch = get_current_branch(path_repository)
|
||||
# get tracking branch
|
||||
ret_current_branch_sha1 = get_revision_list_to_branch(path_repository, select_branch)
|
||||
ret_track_branch_sha1 = get_revision_list_to_branch(path_repository, branch_name)
|
||||
# count the number of commit behind
|
||||
behind_count = 0
|
||||
for elem_sha1 in ret_track_branch_sha1:
|
||||
if elem_sha1 not in ret_current_branch_sha1:
|
||||
behind_count += 1
|
||||
return behind_count
|
||||
|
||||
def is_behind(path_repository, branch_name):
|
||||
return get_behind(path_repository, branch_name) != 0;
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user