[DEV] set every git command display error arriving in the call returns

This commit is contained in:
Edouard DUPIN 2019-06-12 15:50:41 +02:00
parent 0593274392
commit 88edb38d26

View File

@ -19,6 +19,35 @@ from . import env
from . import multiprocess
from . import debug
def generic_display_error(return_value, type_name, error_only=False):
debug.verbose(str(return_value))
if return_value[0] == 0:
if error_only == True:
return
display = False
if return_value[1] != "":
debug.info(return_value[1])
display = True
if return_value[2] != "":
debug.warning(return_value[2])
display = True
if display == False:
debug.verbose("GIT(" + type_name + "): All done OK")
else:
display = False
if return_value[1] != "":
debug.warning("ERROR GIT(" + type_name + ") 1:" + return_value[1])
display = True
if return_value[2] != "":
debug.warning("ERROR GIT(" + type_name + ") 2:" + return_value[2])
display = True
if display == False:
debug.warning("ERROR GIT(" + type_name + "): Unknow error return_value=" + str(return_value[0]))
"""
"""
@ -26,7 +55,9 @@ def check_repository_is_modify(path_repository):
# check if the repository is modify
cmd = "git diff --quiet"
debug.verbose("execute : " + cmd)
ret_diff = multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "check_repository_is_modify", error_only=True)
ret_diff = return_value
if ret_diff[0] == 0:
return False
return True
@ -35,7 +66,9 @@ def get_list_branch_meta(path_repository):
# get local branch
cmd = "git branch -a"
debug.verbose("execute : " + cmd)
ret_branch = multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_list_branch_meta", error_only=True)
ret_branch = return_value
list_branch = ret_branch[1].split('\n')
out = []
for elem_branch in list_branch:
@ -102,26 +135,35 @@ def get_current_tracking_branch(path_repository):
# get tracking branch
cmd = "git rev-parse --abbrev-ref --symbolic-full-name @{u}"
debug.verbose("execute : " + cmd)
return multiprocess.run_command(cmd, cwd=path_repository)[1]
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_current_tracking_branch", error_only=True)
return return_value[1]
def get_revision_list_to_branch(path_repository, branch):
cmd = "git rev-list " + branch
debug.verbose("execute : " + cmd)
return multiprocess.run_command(cmd, cwd=path_repository)[1].split('\n')
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_revision_list_to_branch", error_only=True)
return return_value[1].split('\n')
def get_specific_commit_message(path_repository, sha_1):
if sha_1 == None or sha_1 == "":
return ""
cmd = "git log --format=%B -n 1 " + sha_1
debug.verbose("execute : " + cmd)
return multiprocess.run_command(cmd, cwd=path_repository)[1].split('\n')[0]
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_specific_commit_message", error_only=True)
return return_value[1].split('\n')[0]
def get_sha1_for_branch(path_repository, branch_name):
if branch_name == None or branch_name == "":
return None
cmd = "git rev-parse" + sha_1
debug.verbose("execute : " + cmd)
return multiprocess.run_command(cmd, cwd=path_repository)[1].split('\n')[0]
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "get_sha1_for_branch", error_only=True)
return return_value[1].split('\n')[0]
def get_tracking_branch(path_repository, remote_name, select_branch):
@ -142,7 +184,9 @@ def merge_branch_on_master(path_repository, branch_name):
cmd = "git merge --no-ff " + branch_name + " --message \"Merge branch '" + branch_name + "' into 'master'\""
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "merge_branch_on_master", error_only=True)
return return_value
def add_file(path_repository, file_path):
@ -151,7 +195,9 @@ def add_file(path_repository, file_path):
cmd = "git add " + file_path
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "add_file", error_only=True)
return return_value
def commit_all(path_repository, comment):
@ -160,7 +206,9 @@ def commit_all(path_repository, comment):
cmd = 'git commit -a --message "' + comment +'"'
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "commit_all", error_only=True)
return return_value
def tag(path_repository, tag_name):
if tag_name == None or tag_name == "":
@ -169,7 +217,9 @@ def tag(path_repository, tag_name):
cmd = 'git tag ' + tag_name + ' --message "[TAG] create tag ' + tag_name +'"'
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "tag", error_only=True)
return return_value
def checkout(path_repository, branch_name):
if branch_name == None or branch_name == "":
@ -177,7 +227,9 @@ def checkout(path_repository, branch_name):
cmd = 'git checkout ' + branch_name
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "checkout", error_only=True)
return return_value
def reset_hard(path_repository, destination):
if destination == None or destination == "":
@ -185,4 +237,6 @@ def reset_hard(path_repository, destination):
cmd = 'git reset --hard ' + destination
debug.verbose("execute : " + cmd)
# TODO: check if the command work correctly
return multiprocess.run_command(cmd, cwd=path_repository)
return_value = multiprocess.run_command(cmd, cwd=path_repository)
generic_display_error(return_value, "reset_hard", error_only=True)
return return_value