Skip to content
This repository was archived by the owner on Oct 17, 2025. It is now read-only.

Commit 1caa010

Browse files
committed
added --source-branch and --configs init parameters
1 parent df3cd64 commit 1caa010

File tree

3 files changed

+87
-23
lines changed

3 files changed

+87
-23
lines changed

smud-cli/functions-init.sh

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,21 @@ init()
115115
{
116116
if [ "$help" ]; then
117117
func=${1:-init}
118-
echo "${bold}smud $func${normal}: Initializes local repository and sets upstream and origin remotes"
119-
printf "With Only ${green}$func${normal}, Upstream '$default_upstream' will be configured if not configured yet. When configured the upstream will be fetched. \n"
120-
printf "With ${green}$func ${bold}<value>${normal}, Upstream '<value>' will be configured before upstream is fetched. \n"
121-
printf "With ${green}$func ${bold}--upstream-url <value>${normal}, Upstream '<value>' will be configured before upstream is fetched. \n"
122-
printf "With ${green}$func ${bold}-${normal}, Upstream will be removed. \n"
118+
echo "${bold}smud $func${normal}: Initializes local repository and sets upstream, origin remotes and source-branch"
119+
printf "Upstream: \n"
120+
printf " With Only ${green}$func${normal}, Upstream '$default_upstream' will be configured if not configured yet. When configured the upstream will be fetched. \n"
121+
printf " With ${green}$func ${bold}<value>${normal}, Upstream '<value>' will be configured before upstream is fetched. \n"
122+
printf " With ${green}$func ${bold}--upstream-url <value>${normal}, Upstream '<value>' will be configured before upstream is fetched. \n"
123+
printf " With ${green}$func ${bold}-${normal}, Upstream will be removed. \n"
124+
printf "source-branch: \n"
125+
printf " With Only ${green}$func${normal}, source-branch will be configured to 'upstream/$default_branch' . \n"
126+
printf " With ${green}$func ${bold}${green}--source-branch${normal} <value>${normal}, source-branch '<value>' will be configured. \n"
127+
printf "Show configs: \n"
128+
printf " ${green}$func${normal} ${green}--configs${normal} will list all repository config key/values. ${green}--show${normal} or ${green}--settings${normal} can be used as well. \n"
129+
printf " ${green}$func${normal} ${green}--show${normal} or ${green}--settings${normal} can be used as well. \n"
123130
return
124131
fi
132+
125133
if [ ! "$upstream_url" ]; then
126134
upstream_url="$1"
127135
if [ ! "$upstream_url" ]; then
@@ -156,10 +164,33 @@ init()
156164
fetch_upstream
157165
fi
158166

167+
if [ "$is_repo" ]; then
168+
if [ ! "$source_branch" ]; then
169+
source_branch=$(git config --get source.$current_branch)
170+
fi
171+
if [ ! "$source_branch" ]; then
172+
source_branch="upstream/$default_branch"
173+
fi
174+
175+
old=$(git config --get source.$current_branch)
176+
if [ ! "$old" = "$source_branch" ] || [ ! "$old" ] ; then
177+
if [ "$old" ]; then
178+
dummy=$(git config --unset source.$current_branch)
179+
fi
180+
dummy=$(git config --add source.$current_branch $source_branch)
181+
fi
182+
fi
183+
184+
159185
if [ ! "$remote_origin" ]; then
160186
print_not_silent "Setting and fetching origin"
161187
set_origin
162188
fetch_origin
163189
print_not_silent "${green}Initalization complete.\n${normal}"
164190
fi
191+
192+
if [ "$configs" ]; then
193+
config_command="git config -l"
194+
run_command config-list --command-var config_command --skip-error
195+
fi
165196
}

smud-cli/functions-upgrade.sh

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ upgrade()
130130
# git_range="${rev_list[@]}"
131131

132132
list
133-
133+
error_code=0
134134
yes_no="yes"
135135
if [ ! "$silent" ]; then
136136
ask yes_no "$yellow" "Do you want to continue upgrading the selected $context (Yes/No)?"
@@ -143,28 +143,30 @@ upgrade()
143143
print_debug "$commits"
144144
# If there are any current unapplied changes, cherry pick will fail. Catch this.
145145
cherrypick_commits_command="git cherry-pick $commits $cherrypick_options"
146-
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --skip-error --debug-title='Start cherry-pick' || error_message=$log
146+
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --skip-error --error-code error_code --debug-title='Start cherry-pick' || error_message=$log
147147

148148
# Check if cherry-pick in progress
149149
error_index="$(echo "$error_message" | grep "cherry-pick is already in progress" -c)"
150150
if [ $error_index -gt 0 ]; then
151+
error_code=0
151152
error_message=""
152153
cherrypick_commits_command="git cherry-pick --continue $cherrypick_options"
153-
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --debug-title='Continue cherry-pick' || error_message=$log
154+
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --error-code error_code --debug-title='Continue cherry-pick' || error_message=$log
154155
fi
155156

156157
# Check if cherry-pick was resolved
157158
error_index="$(echo "$error_message" | grep "The previous cherry-pick is now empty, possibly due to conflict resolution" -c)"
158159
if [ $error_index -gt 0 ]; then
159160
error_message=""
161+
error_code=0
160162
cherrypick_commits_command="git cherry-pick --skip $cherrypick_options"
161-
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --debug-title='Skip cherry-pick' || error_message=$log
163+
run_command cherry-pick --command-var=cherrypick_commits_command --return-var=log --error-code error_code --debug-title='Skip cherry-pick' || error_message=$log
162164
fi
163165

164166
# Loop until no conflicts
165167
# Print status in plain text after each file listing
166168
# If the conflict is UD (delete happened in remote) resolve it automatically using "merge-strategy theirs"
167-
if [ -n "$error_message" ]; then
169+
if [ "$error_message" ]; then
168170
errors_resolved="false"
169171
printf "${red}Cherry-pick ran into errors that must be resolved manually.\n${normal}"
170172
#echo "$error_message"
@@ -190,8 +192,12 @@ upgrade()
190192

191193
merge_conflict_status_codes="DD AU UD UA DU AA UU"
192194
untracked_status_code="??"
193-
194-
printf "${red}The follwing contains changes that must be resolved:\n${normal}"
195+
if [ "$silent" ]; then
196+
printf "${red}There is a merge conflict!"
197+
else
198+
printf "${red}The follwing contains changes that must be resolved:\n${normal}"
199+
fi
200+
195201
for status_code in "${!status_map[@]}"; do
196202
filenames="${status_map[$status_code]}"
197203
description=$(get_status_description "$status_code")
@@ -201,13 +207,26 @@ upgrade()
201207
printf "\t* ${gray}$filename\n${normal}"
202208
done
203209
done
204-
210+
211+
if [ "$silent" ]; then
212+
echo "Aborting the cherry-pick process."
213+
cherrypick_abort_command="git cherry-pick --abort"
214+
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-var=dummy --skip-error --debug-title='Abort cherry-pick'
215+
if [ ! "$error_code" ] || [ "$error_code" = "0" ]; then
216+
error_code=1
217+
fi
218+
219+
exit $error_code
220+
fi
221+
205222
printf "${red}After resolving the errors, "
206223
read -p "press [enter] to continue. To abort press [A][enter]. To skip commit press [S][enter]: " continue_or_abort
207224
lower continue_or_abort
208225
printf "${normal}\n"
209226
if [ "$continue_or_abort" = "a" ]; then
210-
log=$(git cherry-pick --abort > /dev/null 2>&1 )
227+
error_code=0
228+
cherrypick_abort_command="git cherry-pick --abort"
229+
run_command cherry-pick-abort --command-var=cherrypick_abort_command --return-var=dummy --skip-error --debug-title='Abort cherry-pick'
211230
exit
212231
fi
213232

@@ -398,7 +417,7 @@ correlate_against_already_cherripicked()
398417
fi
399418
done
400419
revision_list=("${rev_list_checked[@]}")
401-
if [ ${#revision_list[@]} -gt 0 ]; then
420+
if [ ${#revision_list[@]} -gt 0 ] && [ ! "$silent" ]; then
402421
print_gray "Number of revisions corrolated agains already cherry-picked commits: $normal${#revision_list[@]}"
403422
fi
404423
fi

smud-cli/include.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ first_param="$3"
353353
parse_arguments ARGS $@
354354
curr_dir=$(pwd)
355355
get_arg upstream_url '--upstream-url,--upstream,--up-url,-up-url'
356+
get_arg source_branch '--source-branch,--source'
357+
get_arg configs '--configs,--settings,--show'
356358
get_arg skip_auto_update '--skip-auto-update,--skip-auto'
357359
get_arg examples '--examples,--ex,-ex'
358360
get_arg help '--help,-?,-h' "$examples"
@@ -451,23 +453,29 @@ fi
451453
git_pretty_commit='--pretty=format:%H'
452454
git_pretty_commit_date='--pretty=format:%H|%ad'
453455
default_branch="main"
456+
current_branch="$default_branch"
454457
if [ "$has_args" ] && [ ! "$help" ] && [ "$is_repo" ]; then
455458
default_branch="$(git config --list | grep -E 'branch.(main|master).remote' | sed -e 's/branch\.//g' -e 's/\.remote//g' -e 's/=origin//g')"
456-
if [ ! "$upstream_url" ]; then
457-
upstream_url="$(git config --get remote.upstream.url)"
458-
fi
459-
460459
if [ ! "$default_branch" ]; then
461-
default_branch=$(git config --get init.defaultbranch)
460+
default_branch="$(git config --get init.defaultbranch)"
462461
fi
463-
464462
if [ ! "$default_branch" ]; then
465463
default_branch="main"
466464
can_do_git=""
467465
else
468466
can_do_git="$(git branch --list $default_branch)"
469467
fi
470468

469+
current_branch="$(git branch --show-current)"
470+
if [ ! "$current_branch" ]; then
471+
current_branch="$default_branch"
472+
fi
473+
474+
if [ ! "$upstream_url" ]; then
475+
upstream_url="$(git config --get remote.upstream.url)"
476+
fi
477+
478+
471479
if [ ! "$from_commit" ] && [ ! "$from_date" ] && [ "$can_do_git" ] ; then
472480
from_commit_command="git rev-list $default_branch -1"
473481
{
@@ -479,8 +487,14 @@ if [ "$has_args" ] && [ ! "$help" ] && [ "$is_repo" ]; then
479487
fi
480488

481489
if [ ! "$to_commit" ] && [ ! "$is_smud_dev_repo" ];then
482-
if [ "$upstream_url" ]; then
483-
to_commit_command="git rev-list upstream/$default_branch -1"
490+
if [ ! "$source_branch" ]; then
491+
source_branch=$(git config --get source.$current_branch)
492+
fi
493+
if [ ! "$source_branch" ]; then
494+
source_branch="upstream/$default_branch"
495+
fi
496+
if [ "$upstream_url" ] || [ ! "$source_branch" = "upstream/$default_branch" ]; then
497+
to_commit_command="git rev-list $source_branch -1"
484498
run_command to-commit --command-var to_commit_command --return-var to_commit --skip-error --debug-title "to-commit-command"
485499
fi
486500
fi

0 commit comments

Comments
 (0)