Skip to content

Commit

Permalink
## Version 1.0.15
Browse files Browse the repository at this point in the history
- Improved upgrade-cli
- Refactored include.sh into smud-main.sh and include.sh
  • Loading branch information
aho-dips committed Jun 13, 2024
1 parent 42292f5 commit 5833c53
Show file tree
Hide file tree
Showing 9 changed files with 485 additions and 360 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Version 1.0.15
- Improved upgrade-cli
- Refactored include.sh into smud-main.sh and include.sh

## Version 1.0.14
- Improved argument handling
- Improved array iteration
Expand Down
2 changes: 1 addition & 1 deletion smud-cli/download-and-install-cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ if [ -d $download_folder ]; then
fi

rm -rf $download_folder
. $destination_folder/install-cli.sh
. $destination_folder/install-cli.sh "$@"
fi

IFS=$old_SEP
125 changes: 61 additions & 64 deletions smud-cli/functions-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,17 @@ set_upstream()
i=0

if [ "$new_upstream" ]; then
remove_upstream_command="git remote rm upstream"
run_command remove-upstream --command-from-var=remove_upstream_command --debug-title='Removing upstream config URL'
run_command --command="git remote rm upstream" --force-debug-title='Removing upstream config URL'
if [ "$new_upstream" = "-" ]; then
println_not_silent "Upstream is removed" $gray
exit
else
add_upstream_command="git remote add upstream $new_upstream"
run_command add_upstream_command --command-from-var=add_upstream_command --debug-title='Adding upstream with user specified URL'
run_command --command="git remote add upstream $new_upstream" --force-debug-title='Adding upstream with user specified URL'
println_not_silent "Upstream configured with '$new_upstream' " $gray
fi
elif [ ! "$new_upstream" ]; then
new_upstream="$default_upstream"
add_upstream_command="git remote add upstream $new_upstream"
run_command add_upstream_command --command-from-var=add_upstream_command --debug-title='Adding upstream with default URL'
run_command --command="git remote add upstream $new_upstream" --force-debug-title='Adding upstream with default URL'
println_not_silent "Upstream configured with '$new_upstream' " $gray
elif [ ! "$caller" ]; then
println_not_silent "Upstream alredy configured with '$new_upstream' " $gray
Expand All @@ -64,33 +61,40 @@ set_origin()
fi

exit_if_is_not_a_git_repository "Setting remote.origin.url require a git repository!"

# Check if origin exists
check_origin_command="git config --get remote.origin.url"
run_command --check-origin --command-from-var=check_origin_command --return-var=remote_origin --debug-title='Checking if remote.origin.url exist in git config'
git_config_command="git config --get remote.origin.url"
run_command --command-in-var=git_config_command --return-var=remote_origin --debug-title='Checking if remote.origin.url exist in git config'
# If string is empty, set the remote origin url
if [ ! "$remote_origin" ]; then
ask remote_origin $yellow "Remote repository origin is not set, please enter URL for the remote origin.\nOrigin URL:" "true"
ask remote_origin $yellow "Remote repository origin is not set, please enter URL for the remote origin.\nOrigin URL:" "true"
if [ "$remote_origin" ]; then
add_origin_command="git remote add origin $remote_origin"
run_command --set-origin --command-from-var=add_origin_command --return-var=dummy --debug-title='Adding remote origin' || return
println_not_silent "Setting remote origin '$remote_origin'" $gray
run_command --command="git remote add origin $remote_origin" --force-debug-title='Setting remote origin'
fi
else
println_not_silent "Remote origin '$remote_origin' already set." $gray
fi
}

merge_upstream()
{
if [ "$skip_init_feature" ];then
if [ "$skip_init_feature" ] && [ ! "$merge" ];then
return
fi

if [ "$skip_auto_update" ]; then
if [ "$skip_auto_update" ] && [ ! "$merge" ]; then
return
fi
println_not_silent "Merging upstream into local branch..." $gray
merge_upstream_command="git merge upstream/main"
run_command merge-upstream --command-from-var=merge_upstream_command --return-var=dummy --debug-title='Merging upstream repository into local branch' || return

if [ "$merge" ] && [ "$merge" != "true" ]; then
git__setup_source_config "$merge"
fi
if [ "$source_branch" ]; then
msg="Merging upstream '$source_branch' into local branch '$current_branch' ..."
println_not_silent "Merging upstream '$source_branch' into local branch '$current_branch' ..." $gray
run_command --command="git merge $source_branch" --return-in-var=dev_null --debug-title="$msg"
fi
}

fetch_origin()
Expand All @@ -107,26 +111,36 @@ fetch_origin()
return
fi

println_not_silent "Fetching origin..." $gray
fetch_origin_command="git fetch origin"
run_command fetch-origin --command-from-var=fetch_origin_command --return-var=dummy --debug-title='Fetching origin' || return
println_not_silent "Fetching origin '$remote_origin' into branch '$current_branch'..." $gray
run_command --command="git fetch origin" --return-in-var=dev_null --debug-title='Fetching origin'
}

git_push()
{
if [ ! "$remote_origin" ]; then
println_not_silent "Missing remote-origin. Pushing skipped..." $gray
return
fi

println_not_silent "Push current branch '$current_branch' to origin-url '$remote_origin'..." $gray
run_command --command="git push origin $current_branch" --return-in-var=dev_null --debug-title='Push to remote'
}

init_repo()
{
init_command="git init"
if [ "$skip_init_feature" ];then
return
fi

if [ ! "$is_repo" ];then
run_command init-repo --command-from-var=init_command --return-var=dummy --debug-title='Initializing repository' || return
run_command --command="git init" --return-in-var=dev_null --debug-title='Initializing repository' || return
is_repo="true"

branches="$(git branch)"
if [ ! -n "$branches" ]; then
# "main" possibly not default branch name so create it
create_main_branch="git checkout -b main"
run_command checkout-main --command-from-var=create_main_branch --return-var=dummy --debug-title='Creating main branch' || return
git_checkout_command="git checkout -b main"
run_command --command-in-var git_checkout_command --return-in-var=dev_null --debug-title='Creating main branch' || return
fi
fi
git__setup 'true'
Expand All @@ -138,8 +152,7 @@ fetch_upstream()
return
fi

fetch_upstream_command="git fetch upstream"
run_command fetch-upstream --command-from-var=fetch_upstream_command --return-var=dummy --debug-title='Fetching upstream' || return
run_command --command="git fetch upstream" --return-in-var=dev_null --force-debug-title='Fetching upstream'
}

init_upstream_url()
Expand All @@ -160,7 +173,6 @@ init_upstream_url()
set_upstream "$upstream_url"
print_debug "upstream_url: $upstream_url"
fi

}

# Initalizes repo, upstream and origin if not configured. Will always fetch upstream when called.
Expand All @@ -184,6 +196,11 @@ init()
printf "${yellow}default-branch:${normal} \n"
printf " With Only ${green}$func${normal}, ${yellow}default-branch${normal} will be configured to '${bold}main${normal}' . \n"
printf " With ${green}$func ${yellow}${bold}--default-branch <value>${normal}${normal}, ${bold}default-branch '<value>'${normal} will be configured. \n"
printf "${yellow}merge upstream:${normal} \n"
printf " With ${green}$func ${yellow}${bold}--merge${normal} the '${bold}git merge upstream/main${normal}' command will be runned. \n"
printf " With ${green}$func ${yellow}${bold}--merge --push${normal} the ${gray}'git merge upstream/main; ${normal}${bold}git push${normal}' command will be runned. \n"
printf " With ${green}$func ${yellow}${bold}--merge <branch>${normal}${normal} the '${bold}git merge upstream/${yellow}${bold}<branch>${normal}' command will be runned. \n"
printf " With ${green}$func ${yellow}${bold}--merge <branch> --push${normal}${normal} the '${gray}git merge upstream/<branch>${normal}; ${bold}git push${normal}' command will be runned. \n"
printf "Show ${yellow}configs:${normal} \n"
printf " ${green}$func${normal} ${yellow}--configs${normal} will list all repository config key/values. ${yellow}--show${normal} or ${yellow}--settings${normal} can be used as well. \n"
printf " ${green}$func${normal} ${yellow}--show${normal} or ${yellow}--settings${normal} can be used as well. \n"
Expand All @@ -204,11 +221,10 @@ init()
set_upstream "-"
return
fi

if [ ! "$is_repo" ]; then
local yes_no="yes"
if [ ! "$silent" ]; then
ask yes_no $yellow "The current directory does not seem to be a git repository\nWould you like to initialize the repository and merge the remote upstream? (yes/no)"
ask yes_no $yellow "The current directory does not seem to be a git repository\nWould you like to initialize the repository and merge the remote upstream (Yes/No)?" "-" "yes"
fi
if [ ! "$yes_no" = "yes" ]; then
println_not_silent "Aborting" $yellow
Expand All @@ -220,53 +236,34 @@ init()
fetch_upstream
merge_upstream
init_repo
if [ "$merge" ]; then
run_push=$force_push
fi
else
init_upstream_url
fetch_upstream
fi

if [ "$is_repo" ]; then

if [ ! "$source_branch" ]; then

if [ "$current_branch" ]; then
source_branch="$(git config --get source.$current_branch)"
fi
fi


if [ ! "$source_branch" ]; then
source_branch="upstream/$default_branch"
fi


old=""
if [ "$current_branch" ]; then
old="$(git config --get source.$current_branch)"
fi

if [ ! "$old" = "$source_branch" ] || [ ! "$old" ] ; then

if [ "$old" ] && [ "$current_branch" ]; then
dummy="$(git config --unset source.$current_branch)"
fi

if [ "$current_branch" ] && [ "$source_branch" ]; then
dummy="$(git config --add source.$current_branch $source_branch)"
fi
if [ "$merge" ]; then
merge_upstream
run_push=$force_push
fi
fi

git__setup_source_config

if [ ! "$remote_origin" ]; then
println_not_silent "Setting and fetching origin" $gray
set_origin
fetch_origin
if [ ! "$run_push" ]; then
fetch_origin
fi
println_not_silent "Initalization complete." $green
fi

if [ "$run_push" ]; then
git_push
fi

if [ "$configs" ]; then
config_command="git config -l"
run_command config-list --command-var config_command --skip-error
git_config_command="git config -l"
run_command --command-in-var git_config_command --skip-error
fi
}
34 changes: 22 additions & 12 deletions smud-cli/functions-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -661,9 +661,9 @@ product_infos__print()
# echo "{ stage: '$product_stage', product_name: '$product_name', latest_version: '$latest_version', commit: '$commit', product_info: '${product_infos[${stage_product_name}]}' }"
if [ "$show_tags_in_list" ]; then
if [ "$show_tags_in_list" = "reverse" ]; then
tags="$(get_tags "'$latest_version'" "'$current_version'")"
get_tags tags "'$latest_version'" "'$current_version'"
else
tags="$(get_tags "'$current_version'" "'$latest_version'")"
get_tags tags "'$current_version'" "'$latest_version'"
fi

if [ "$major" ] && [ ! "$tags" = "MAJOR" ];then
Expand Down Expand Up @@ -865,33 +865,43 @@ get_next_stage_version()

get_tags()
{
local -n get_tags_tags="$1"

get_tags_tags=""
replace_reg_exp="s/'//g"
cur_ver="$(echo "$1" | sed -e $replace_reg_exp)"
latest_ver="$(echo "$2" | sed -e $replace_reg_exp)"
cur_ver="$(echo "$2" | sed -e $replace_reg_exp)"
latest_ver="$(echo "$3" | sed -e $replace_reg_exp)"
if [ ! "$cur_ver" ] && [ "$latest_ver" ]; then
echo "NEW"
get_tags_tags="NEW"
return
elif [ "$cur_ver" ] && [ "$latest_ver" ]; then
# cur_ver_array=$(echo "$cur_ver" | tr "." "\n")
# latest_ver_array=$(echo "$latest_ver" | tr "." "\n")
cur_ver_major="$(echo "$cur_ver" | cut -d "." -f 1)"
# cur_ver_major="${cur_ver_major%%[[:cntrl:]]}"
latest_ver_major="$(echo "$latest_ver" | cut -d "." -f 1)"
if [ ! "$cur_ver_major" = "$latest_ver_major" ];then
echo "MAJOR"
# latest_ver_major="${latest_ver_major%%[[:cntrl:]]}"
if [ "$cur_ver_major" != "$latest_ver_major" ];then
get_tags_tags="MAJOR"
return
fi

cur_ver_minor="$(echo "$cur_ver" | cut -d "." -f 2)"
# cur_ver_minor="${cur_ver_minor%%[[:cntrl:]]}"
latest_ver_minor="$(echo "$latest_ver" | cut -d "." -f 2)"
if [ ! "$cur_ver_minor" = "$latest_ver_minor" ];then
echo "MINOR"
# latest_ver_minor="${latest_ver_minor%%[[:cntrl:]]}"
if [ "$cur_ver_minor" != "$latest_ver_minor" ];then
get_tags_tags="MINOR"
return
fi

cur_ver_patch="$(echo "$cur_ver" | cut -d "." -f 3)"
latest_ver_patch="$(echo "$latest_ver" | cut -d "." -f 3)"
if [ ! "$cur_ver_patch" = "$latest_ver_patch" ];then
echo "patch"
return
if [ "$cur_ver_patch" != "$latest_ver_patch" ];then
if [ ! "${cur_ver_patch%%[[:cntrl:]]}" = "${latest_ver_patch%%[[:cntrl:]]}" ];then
get_tags_tags="patch"
return
fi
fi
fi
}
Expand Down
18 changes: 9 additions & 9 deletions smud-cli/functions-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ upgrade()
if [ ! "$product" ]; then
if [ ! "$silent" ]; then
echo "No Products specified by [--products=, --product=, -P=] or [--all, -A]."
ask yes_no $yellow "Do you want to upgrade the GitOps-model (Yes/No)?"
ask yes_no $yellow "Do you want to upgrade the GitOps-model (Yes/No)?" "-" "yes"
fi
if [ "$yes_no" = "yes" ]; then
local upgrade_filter="$devops_model_filter"
Expand Down Expand Up @@ -145,7 +145,7 @@ upgrade()
error_code=0
yes_no="yes"
if [ ! "$silent" ]; then
ask yes_no "$yellow" "Do you want to continue upgrading the selected $context (Yes/No)?"
ask yes_no "$yellow" "Do you want to continue upgrading the selected $context (Yes/No)?" "-" "y"
fi
local cherrypick__continue_options="--keep-redundant-commits --allow-empty"
local cherrypick_options="$cherrypick__continue_options -x"
Expand Down Expand Up @@ -270,7 +270,7 @@ upgrade()
if [ "$silent" ]; then
echo "Aborting the cherry-pick process."
cherrypick_abort_command="git cherry-pick --abort"
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-var=dummy --skip-error --debug-title='Abort cherry-pick'
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-in-var=dev_null --skip-error --debug-title='Abort cherry-pick'
if [ ! "$error_code" ] || [ "$error_code" = "0" ]; then
error_code=1
fi
Expand All @@ -285,7 +285,7 @@ upgrade()
if [ "$continue_or_abort" = "a" ]; then
error_code=0
cherrypick_abort_command="git cherry-pick --abort"
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-var=dummy --skip-error --debug-title='Abort cherry-pick'
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-in-var=dev_null --skip-error --debug-title='Abort cherry-pick'
exit
fi

Expand Down Expand Up @@ -423,7 +423,7 @@ reset_to_commit()
fi
yes_no="yes"
if [ ! "$silent" ]; then
ask yes_no $yellow "Do you really want to reset to [$has_undo_commit]?\nThis is a destructive command. All changes newer than that commit will be lost!"
ask yes_no $yellow "Do you really want to reset to [$has_undo_commit]?\nThis is a destructive command. All changes newer than that commit will be lost!\nReset (Yes/No)?" "-" "n"
fi
if [ "$yes_no" = "yes" ]; then
local flag="--hard"
Expand Down Expand Up @@ -517,10 +517,10 @@ ensure_git_cred_is_configured()
fi
fi

local dummy="$(git config --unset user.name)"
local dummy="$(git config --unset user.email)"
local dummy="$(git config --add user.name "$user_name_ask" )"
local dummy="$(git config --add user.email "$user_email_ask" )"
local dev_null="$(git config --unset user.name)"
local dev_null="$(git config --unset user.email)"
local dev_null="$(git config --add user.name "$user_name_ask" )"
local dev_null="$(git config --add user.email "$user_email_ask" )"
fi
}

Expand Down
Loading

0 comments on commit 5833c53

Please sign in to comment.