[DEBUG] correct the branch config and sync and add status forward and behind

This commit is contained in:
Edouard DUPIN 2017-04-10 23:36:12 +02:00
parent f90e5bc535
commit d362d47889
6 changed files with 138 additions and 42 deletions

View File

@ -11,6 +11,7 @@
from island import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
import os
@ -44,9 +45,13 @@ def execute(arguments):
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 = manifest.load_config()
configuration = config.Config()
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration["file"])
# update the local configuration file:
configuration.set_branch(branch_to_checkout)
configuration.store()
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) + "'")
@ -89,11 +94,9 @@ def execute(arguments):
list_branch2 = []
select_branch = ""
for elem_branch in list_branch:
list_branch2.append(elem_branch[2:])
if elem_branch[:2] == "* ":
list_branch2.append([elem_branch[2:], True])
select_branch = elem_branch[2:]
else:
list_branch2.append([elem_branch[2:], False])
# check if we are on the good branch:
@ -102,23 +105,36 @@ def execute(arguments):
continue
# check if we have already checkout the branch before
debug.verbose(" check : " + branch_to_checkout + " in " + str(list_branch2))
if branch_to_checkout in list_branch2:
cmd = "git checkout " + branch_to_checkout
debug.verbose("execute : " + cmd)
ret = multiprocess.run_command(cmd, cwd=git_repo_path)
if ret[1] != "" \
if ret[0] != 0 \
and ret[1] != "" \
and ret != False:
debug.info("'" + ret + "'")
debug.error("checkout " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + " ==> Can not checkout to the corest branch")
debug.info("'" + str(ret) + "'")
debug.error("checkout " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + " ==> Can not checkout to the correct branch")
continue
debug.info("checkout " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + " ==> switch branch")
# TODO : Check the number of commit to the origin/XXX branch ....
continue
# TODO: Check if the remote branch exist ...
# Check if the remote branch exist ...
cmd = "git branch -a"
debug.verbose("execute : " + cmd)
ret_branch_all = multiprocess.run_command(cmd, cwd=git_repo_path)
list_branch_all = ret_branch_all[1].split('\n')
exist = False
for elem_branch in list_branch_all:
debug.verbose(" check : '" + elem_branch + "' == '" + " remotes/" + elem.select_remote["name"] + "/" + branch_to_checkout + "'")
if elem_branch == " remotes/" + elem.select_remote["name"] + "/" + branch_to_checkout:
exist = True
debug.info(" ==> find ...")
break
if exist == False:
debug.info("checkout " + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + " ==> NO remote branch")
continue
# checkout the new branch:
cmd = "git checkout --quiet " + elem.select_remote["name"] + "/" + branch_to_checkout + " -b " + branch_to_checkout

View File

@ -11,6 +11,7 @@
from island import debug
from island import tools
from island import env
from island import config
from island import multiprocess
import os
@ -57,8 +58,11 @@ def execute(arguments):
# check if the git of the manifest if availlable
# create the file configuration:
data = "repo=" + address_manifest + "\nbranch=" + branch + "\nfile=" + manifest_name
tools.file_write_data(env.get_island_path_config(), data)
conf = config.Config()
conf.set_manifest(address_manifest)
conf.set_branch(branch)
conf.set_manifest_name(manifest_name)
conf.store()
#clone the manifest repository
cmd = "git clone " + address_manifest + " --branch " + branch + " " + env.get_island_path_manifest()

View File

@ -12,6 +12,7 @@ from island import debug
from island import tools
from island import env
from island import multiprocess
from island import config
from island import manifest
import os
@ -36,9 +37,9 @@ def execute(arguments):
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 = manifest.load_config()
configuration = config.Config()
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration["file"])
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) + "'")
@ -90,8 +91,31 @@ def execute(arguments):
debug.verbose("select branch = '" + select_branch + "' is modify : " + str(is_modify) + " track: '" + str(ret_track[1]) + "'")
cmd = "git rev-list " + select_branch
debug.verbose("execute : " + cmd)
ret_current_branch_sha1 = multiprocess.run_command(cmd, cwd=git_repo_path)[1].split('\n')
cmd = "git rev-list " + ret_track[1]
debug.verbose("execute : " + cmd)
ret_track_branch_sha1 = multiprocess.run_command(cmd, cwd=git_repo_path)[1].split('\n')
# remove all identical sha1 ==> not needed for this
in_forward = 0
for elem_sha1 in ret_current_branch_sha1:
if elem_sha1 not in ret_track_branch_sha1:
in_forward += 1
in_behind = 0
for elem_sha1 in ret_track_branch_sha1:
if elem_sha1 not in ret_current_branch_sha1:
in_behind += 1
behind_forward_comment = ""
if in_forward != 0:
behind_forward_comment += "forward=" + str(in_forward)
if in_behind != 0:
behind_forward_comment += "behind=" + str(in_behind)
if behind_forward_comment != "":
behind_forward_comment = "\r\t\t\t\t\t\t\t\t\t\t\t\t[" + behind_forward_comment + "]"
#debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + ret_track[1] + " -> " + elem.select_remote["name"] + "/" + elem.branch + ")")
debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + ret_track[1] + ")")
debug.info("" + str(id_element) + "/" + str(len(all_project)) + " : " + str(elem.name) + "\r\t\t\t\t\t\t\t" + modify_status + "(" + select_branch + " -> " + ret_track[1] + ")" + behind_forward_comment)
if is_modify == True:
cmd = "git status --short"
debug.verbose("execute : " + cmd)

View File

@ -11,6 +11,7 @@
from island import debug
from island import tools
from island import env
from island import config
from island import multiprocess
from island import manifest
import os
@ -37,14 +38,14 @@ def execute(arguments):
debug.error("System already init have an error: missing data: '" + str(env.get_island_path()) + "'")
configuration = manifest.load_config()
configuration = config.Config()
debug.info("update manifest : '" + str(env.get_island_path_manifest()) + "'")
# update manifest
cmd = "git fetch --all"
multiprocess.run_command_direct(cmd, cwd=env.get_island_path_manifest())
file_source_manifest = os.path.join(env.get_island_path_manifest(), configuration["file"])
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) + "'")
@ -153,11 +154,11 @@ def execute(arguments):
if is_modify == True:
debug.warning("[" + elem.name + "] Not update ==> the repository is modified")
continue
""" # TODO: this does not work ...
if ret_track[1] != elem.select_remote["name"] + "/" + elem.branch:
debug.warning("[" + elem.name + "] Not update ==> the current branch does not track the correct branch : track '" + ret_track[1] + "' instead of '" + elem.select_remote["name"] + "/" + elem.branch + "'")
continue
"""
debug.info("select branch = '" + select_branch + "' is modify : " + str(is_modify) + " track: '" + str(ret_track[1]) + "'")
# check submodule if requested:
if elem.select_remote["sync"] == True \

72
island/config.py Normal file
View File

@ -0,0 +1,72 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
##
## @author Edouard DUPIN
##
## @copyright 2012, Edouard DUPIN, all right reserved
##
## @license MPL v2.0 (see license file)
##
import platform
import sys
import os
import copy
# Local import
from . import debug
from . import tools
from . import env
from . import multiprocess
env.get_island_path_config()
class Config():
def __init__(self):
self._repo = ""
self._branch = "master"
self._manifest_name = "default.xml"
self.load()
def load(self):
config_property = tools.file_read_data(env.get_island_path_config())
element_config = config_property.split("\n")
for line in element_config:
if line[0] == "#" \
or len(line) == 0:
# simple comment line ==> pass
pass
elif line[:5] == "repo=":
self._repo = line[5:]
elif line[:7] == "branch=":
self._branch = line[7:]
elif line[:5] == "file=":
self._manifest_name = line[5:]
else:
debug.warning("island config error: can not parse: '" + str(line) + "'")
return True
def store(self):
data = "repo=" + self._repo + "\nbranch=" + self._branch + "\nfile=" + self._manifest_name
tools.file_write_data(env.get_island_path_config(), data)
def set_manifest(self, value):
self._repo = value
def get_manifest(self):
return self._repo
def set_branch(self, value):
self._branch = value
def get_branch(self):
return self._branch
def set_manifest_name(self, value):
self._manifest_name = value
def get_manifest_name(self):
return self._manifest_name

View File

@ -19,27 +19,6 @@ from . import multiprocess
from lxml import etree
def load_config():
config_property = tools.file_read_data(env.get_island_path_config())
element_config = config_property.split("\n")
if len(element_config) != 3:
debug.error("error in configuration property")
if element_config[0][:5] != "repo=":
debug.error("error in configuration property (2)")
if element_config[1][:7] != "branch=":
debug.error("error in configuration property (3)")
if element_config[2][:5] != "file=":
debug.error("error in configuration property (4)")
configuration = {
"repo":element_config[0][5:],
"branch":element_config[1][7:],
"file":element_config[2][5:]
}
debug.info("configuration property: " + str(configuration))
return configuration
class RepoConfig():
def __init__(self):
self.name = ""