@@ -135,34 +135,12 @@ upgrade()
135135 if [ ! " $silent " ]; then
136136 ask yes_no " $yellow " " Do you want to continue upgrading the selected $context (Yes/No)?"
137137 fi
138- local cherrypick_options=" --keep-redundant-commits --allow-empty -x"
138+ local cherrypick__continue_options=" --keep-redundant-commits --allow-empty"
139+ local cherrypick_options=" $cherrypick__continue_options -x"
139140 local upgrade_error_code=0
140141 if [ " $yes_no " = " yes" ]; then
141142
142- local user_name=$( git config --get user.name)
143- local user_email=$( git config --get user.email)
144-
145- if [ ! " $user_name " ] || [ ! " $user_email " ]; then
146- local remote_origin_url=" $( git config --get remote.origin.url| sed -e ' s/https:\/\//' ) "
147- if [ ! " $user_name " ]; then
148- local user_name=" githubservicesmud"
149- fi
150-
151- if [ ! " $user_email " ]; then
152- local user_email=
" [email protected] " 153- fi
154- local user_name_ask=" $user_name "
155- local user_email_ask=" $user_email "
156- if [ ! " $silent " ]; then
157- ask user_name_ask $blue " Please configure git user.name: Push ENTER to use '$user_name_ask ': "
158- ask user_email_ask $blue " Please configure git user.email: Push ENTER to use '$user_email_ask ': "
159- fi
160-
161- local dummy=$( git config --unset user.name)
162- local dummy=$( git config --unset user.email)
163- local dummy=$( git config --add user.name " $user_name_ask " )
164- local dummy=$( git config --add user.email " $user_email_ask " )
165- fi
143+ ensure_git_cred_is_configured
166144
167145 commits=" ${rev_list[@]} "
168146 print_gray " Running: git cherry-pick [commits]...\n"
@@ -176,7 +154,7 @@ upgrade()
176154 if [ $error_index -gt 0 ]; then
177155 error_code=0
178156 error_message=" "
179- cherrypick_commits_command=" git cherry-pick --continue $cherrypick_options "
157+ cherrypick_commits_command=" git cherry-pick --continue $cherrypick__continue_options "
180158 run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --error-code error_code --debug-title=' Continue cherry-pick' || error_message=$log
181159 fi
182160
@@ -194,43 +172,79 @@ upgrade()
194172 # If the conflict is UD (delete happened in remote) resolve it automatically using "merge-strategy theirs"
195173 if [ " $error_message " ]; then
196174 errors_resolved=" false"
197- printf " ${red} Cherry-pick ran into errors that must be resolved manually.\n${normal} "
175+ if [ ! " $silent " ]; then
176+ printf " ${red} Cherry-pick ran into errors that must be resolved manually.\n${normal} "
177+ fi
198178 # echo "$error_message"
199179 while [ " $errors_resolved " == " false" ]; do
200180 files_status=$( git status -s)
201181
202182 declare -A status_map
203183
204184 while IFS= read -r line; do
185+
186+ # git diff --pretty=format:''|sed -e 's/+/\n/g' -e 's/\r//g'|xargs
187+ # echo "line:$line"
205188 # Extract the file status
206189 status_code=$( echo " $line " | cut -c -2)
207190 # Extract the file name
208- file=$( echo " $line " | cut -c -4)
191+ file=" $( git diff --pretty=format:' ' | grep " + \|- \|++==" | sed -e ' s/--- a\///g' -e ' s/+++ b\///g' | sed -e ' s/ +/+/g' -e ' s/ -/-/g' | uniq) "
192+ if [ ! " $file " ]; then
193+ file=" $( echo " $line " | cut -d ' ' -f 4| xargs) "
194+ if [ ! " $file " ]; then
195+ file=" $( echo " $line " | cut -d ' ' -f 3| xargs) "
196+ fi
197+ if [ ! " $file " ]; then
198+ file=" $( echo " $line " | cut -d ' ' -f 2| xargs) "
199+ fi
200+ fi
201+ # echo "status_code:$status_code"
202+ # echo "file:$file"
209203 # Add the file to the map where the status is the key
210204 if [[ -n " ${status_map["$status_code"]} " ]]; then
211205 # If it exists, append the current file to the existing array
212206 status_map[" $status_code " ]+=" $file "
213207 else
214208 # If it doesn't exist, create a new array with the current file
215- status_map[" $status_code " ]=$file
209+ status_map[" $status_code " ]=" $file "
216210 fi
217211 done < <( git status -s)
218212
219213 merge_conflict_status_codes=" DD AU UD UA DU AA UU"
220214 untracked_status_code=" ??"
221215 if [ " $silent " ]; then
222- printf " ${red} There is a merge conflict!"
216+ printf " ${red} There is a merge conflict!\n ${normal} "
223217 else
224218 printf " ${red} The follwing contains changes that must be resolved:\n${normal} "
225219 fi
226220
227221 for status_code in " ${! status_map[@]} " ; do
228222 filenames=" ${status_map[$status_code]} "
223+
229224 description=$( get_status_description " $status_code " )
230225 printf " \t${red} Status: ${gray} $description \n${normal} "
231- IFS=' ' read -ra filenames_array <<< " $filenames"
226+ IFS=$' \n ' ; read -rd ' ' -a filenames_array <<< " $filenames"
227+ label=" "
232228 for filename in " ${filenames_array[@]} " ; do
233- printf " \t* ${gray} $filename \n${normal} "
229+ filename=" $( echo " $filename " | xargs) "
230+ tab=" \t*"
231+ c=$( echo " $filename " | grep " :" -c)
232+ if [ " ${filename: 0: 1} " = " +" ] || [ " ${filename: 0: 1} " = " -" ] || [ $c -gt 0 ]; then
233+ tab=" \t\t"
234+ if [ ! " $label " ]; then
235+ label=" \t Diffs:"
236+ printf " $gray$label \n${normal} "
237+ elif [ " ${filename: 0: 4} " = " ++==" ]; then
238+ printf " $tab $gray$filename \n${normal} "
239+ color=" $green "
240+ continue
241+ fi
242+
243+ else
244+ color=" $red "
245+ label=" "
246+ fi
247+ printf " $tab $color$filename \n${normal} "
234248 done
235249 done
236250
@@ -265,7 +279,7 @@ upgrade()
265279 log=$( git cherry-pick --skip $cherrypick_options > /dev/null 2>&1 )
266280 errors_resolved=" true"
267281 else
268- cherrypick_commits_command=" git cherry-pick --continue $cherrypick_options "
282+ cherrypick_commits_command=" git cherry-pick --continue $cherrypick__continue_options "
269283 run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --error-code error_code --debug-title=' Continue cherry-pick' || error_message=$log
270284 if [ $error_code -eq 0 ]; then
271285 errors_resolved=" true"
@@ -448,4 +462,46 @@ correlate_against_already_cherripicked()
448462 fi
449463 fi
450464
465+ }
466+ ensure_git_cred_is_configured ()
467+ {
468+ local user_name=$( git config --get user.name)
469+ local user_email=$( git config --get user.email)
470+
471+ if [ ! " $user_name " ] || [ ! " $user_email " ]; then
472+ if [ ! " $user_name " ]; then
473+ local user_token=" $( git config --get remote.origin.url | sed -e ' s/https:\/\///g' | cut -d ' @' -f 1) "
474+ local c=" $( echo " $user_token " | grep ' :' -c) "
475+
476+ if [ $c -gt 0 ]; then
477+ local user_name=" $( echo " $user_token " | cut -d ' :' -f 1) "
478+ fi
479+ fi
480+
481+ if [ ! " $user_name " ]; then
482+ local user_name=" githubservicesmud"
483+ fi
484+
485+ if [ ! " $user_email " ]; then
486+ local user_email=" $user_name @dips.no"
487+ fi
488+
489+ local user_name_ask=" $user_name "
490+ local user_email_ask=" $user_email "
491+ if [ ! " $silent " ]; then
492+ ask user_name_ask $blue " Please configure git user.name (Push ENTER to use '$user_name_ask '): "
493+ ask user_email_ask $blue " Please configure git user.email (Push ENTER to use '$user_email_ask '): "
494+ if [ ! " $user_name_ask " ]; then
495+ local user_name_ask=" $user_name "
496+ fi
497+ if [ ! " $user_email_ask " ]; then
498+ local user_email_ask=" $user_email "
499+ fi
500+ fi
501+
502+ local dummy=$( git config --unset user.name)
503+ local dummy=$( git config --unset user.email)
504+ local dummy=$( git config --add user.name " $user_name_ask " )
505+ local dummy=$( git config --add user.email " $user_email_ask " )
506+ fi
451507}
0 commit comments