Skip to content

Commit

Permalink
implemented upgrade --undo
Browse files Browse the repository at this point in the history
  • Loading branch information
aho-dips committed Jan 29, 2024
1 parent 128a699 commit 091637f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
11 changes: 6 additions & 5 deletions smud-cli/functions-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ product_infos__find_latest_products_with_version()
product_names=()
fi

progressbar__init $line_numbers 50
progressbar__init $line_numbers 100

i=0
for line in "${changed_files[@]}"
Expand Down Expand Up @@ -216,9 +216,10 @@ product_infos__find_latest_products_with_version()

product_infos__find_latest_products_with_files()
{
if [ "$skip_files" ]; then
if [ ! "$show_files" ]; then
return
fi

product_name=""
if [ "$installed" ]; then
files_command="git ls-files -- $filter $no_app_files_filter"
Expand All @@ -241,7 +242,7 @@ product_infos__find_latest_products_with_files()
product_yaml_product_names=()
commit=""

progressbar__init $line_numbers 50
progressbar__init $line_numbers 100

i=0
start_time=$(date +"%Y-%m-%d %H:%M:%S")
Expand Down Expand Up @@ -393,7 +394,7 @@ product_infos__print()
current_version="$(get_current_version)"
fi

if [ ! "$skip_files" ]; then
if [ "$show_files" ]; then
product_info__get_latest_files product_info files
fi

Expand Down Expand Up @@ -436,7 +437,7 @@ product_infos__print()

if [ ! "$printed_product_header" ]; then
files_header=""
if [ ! "$skip_files" ]; then
if [ "$show_files" ]; then
files_header="FILES"
fi

Expand Down
35 changes: 34 additions & 1 deletion smud-cli/functions-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,39 @@ upgrade()
return
fi

if [ "$undo" ]; then
if [ "$undo" = "true" ]; then
print_error "You must add the commit to the --undo flag. Ex: --undo b3..."
return
fi
local has_undo_commit_command="git log $undo --max-count=1 --no-merges --oneline"
run_command --has-commits --command-var=has_undo_commit_command --return-var='has_undo_commit' --debug-title='Check if undo commit exists' ||
{
print_error "Unabled to find commit '$undo'.\nUndo terminated...\n"
return
}
if [ ! "$has_undo_commit" ]; then
print_gray "No commit '$$undo' found. Undo terminated..."
return
fi
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!"
if [ "$yes_no" = "yes" ]; then
local flag="--hard"
if [ "$soft" ]; then
local flag="--soft"
fi
local git_reset_hard_command="git reset $flag $undo"
run_command --reset-to-commit --command-var=git_reset_hard_command --return-var='reset_result' --debug-title="Reset '$default_branch' to commit '$undo'" ||
{
print_error "Failed to reset default branch '$default_branch' to commit '$undo'\n"
return
}
print_color $green "Default branch '$default_branch' successfully reset to commit '$undo'\n"
fi

return
fi

local context="products"
local upgrade_filter=$filter
local yes_no="y"
Expand All @@ -78,7 +111,7 @@ upgrade()
if [ ! "$silent" ]; then
ask yes_no $yellow "Do you want to upgrade the GitOps-model (Yes/No)?"
fi
if [ ! "$yes_no" = "yes" ]; then
if [ "$yes_no" = "yes" ]; then
local upgrade_filter=$devops_model_filter
local context="GitOps-model files"
print_gray "Swithced to '$context' context"
Expand Down
19 changes: 15 additions & 4 deletions smud-cli/include.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ ask()
print_color $color $question
read answer
lower answer
print_gray "You selected: $answer"

if [ "$1" = "yes_no" ]; then
if [ "$answer" = "yes" ] || [ "$answer" = "y" ] || [ "$answer" = "ja" ] || [ "$answer" = "j" ]; then
answer="yes"
elif [ "$answer" = "no" ] || [ "$answer" = "n" ] || [ "$answer" = "nei" ]; then
answer="no"
fi
fi
print_debug "You selected: $answer"
}


Expand Down Expand Up @@ -351,9 +357,14 @@ get_arg to_commit '--to-commit,-TC'
get_arg from_date '--from-date,-FD'
get_arg to_date '--to-date,-TD'
get_arg grep '--grep'
get_arg undo '--undo,--reset'
get_arg soft '--soft'
get_arg no_progress '--no-progress' "$silent"
get_arg skip_files '--skip-files'
get_arg files '--files'
get_arg skip_files '--skip-files,--no-files'
get_arg show_files '--show-files,--files'
if [ "$skip_files" ]; then
show_files=""
fi

get_arg development '--development,-D,-DEV'
get_arg external_test '--external-test,-ET'
Expand Down

0 comments on commit 091637f

Please sign in to comment.