fix: Get parent branch the right way

This commit is contained in:
Tracey Clark 2025-12-07 17:25:28 -06:00
commit 7156b7ff01

View file

@ -3,6 +3,7 @@
current_date=$(date -I) current_date=$(date -I)
pr_dirs=() pr_dirs=()
src_dir=$HOME/kde/src
# Function to display script usage UPDATE # Function to display script usage UPDATE
usage() { usage() {
@ -23,27 +24,32 @@ popd () {
command popd "$@" > /dev/null command popd "$@" > /dev/null
} }
# TODO add fix variable --fix / -f and only run fix function if passed
# TODO add fix variable --fix / -f and function get_top_branch () {
top_branch_untrimmed=$(git log --oneline --graph --decorate | grep -o 'HEAD -> .*' | awk '/>\s/{ print $3 }')
# get_branch() top_branch="${top_branch_untrimmed%?}"
# { }
# $(git rev-parse --abbrev-ref HEAD)
# }
get_branch_per_dir () { get_branch_per_dir () {
for dir in $(ls $HOME/kde/src); for dir in $(find ${src_dir} -maxdepth 1 -type d);
do do
# cd or cd ${dir}
pushd . if [[ "${dir}" == *"src/log" || "${dir}" == "${src_dir}" ]]; then
# printf "Checking directory %s\n" ${dir} printf "Skipping directory %s\n" ${dir}
continue
fi
dir_branch=$(git rev-parse --abbrev-ref HEAD) dir_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "${dir_branch}" -ne "master" ]]; then get_top_branch
printf "%s not on master\n" "${dir}" if [[ ! "${dir_branch}" == "${top_branch}" ]]; then
printf "%s not on its main branch\n" "${dir}"
pr_dirs+=("${dir}") pr_dirs+=("${dir}")
fi fi
popd
cd ${src_dir}
done done
echo "Done checking branches"
} }
print_array () { print_array () {
@ -54,22 +60,35 @@ print_array () {
done done
} }
# TODO fix_branches () {
# fix_branches () { a=("$@")
# a=("$@") for b in "${a[@]}";
# for b in "${a[@]}"; do
# do echo "Fixing $b"
# echo "Fixing $b" cd ${b}
# done get_top_branch
# } git reset --hard
git switch ${top_branch}
git fetch && git pull
done
}
if [[ ( $@ == "--help") || $@ == "-h" ]] if [[ ( $@ == "--help") || $@ == "-h" ]]; then
then usage
usage exit 0
exit 0
fi fi
printf "Getting KDE source directory branches...\n" printf "Getting KDE source directory branches...\n"
get_branch_per_dir get_branch_per_dir
printf "\nNot on master:\n"
print_array "${pr_dirs[@]}" if [[ ${#pr_dirs[@]} -eq 0 ]]; then
echo "[INFO] No directories need to switch branches"
exit 0
else
printf "\n[INFO] Directories not on the top branch:\n"
print_array "${pr_dirs[@]}"
printf "\n[INFO] Switching branches to top branch\n"
fix_branches "${pr_dirs[@]}"
fi
printf "[INFO] Directories are up to date"