File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -56,8 +56,23 @@ declare -a TARGET_ARGS=(
5656# Function to update the repository
5757update_repo () {
5858 local repo_dir=" $1 "
59+ local default_branch
5960 echo " Updating repository: $repo_dir "
6061 git -C " $repo_dir " fetch --all
62+
63+ if ! git -C " $repo_dir " symbolic-ref -q HEAD > /dev/null; then
64+ default_branch=$( git -C " $repo_dir " symbolic-ref --quiet --short refs/remotes/origin/HEAD 2> /dev/null || true)
65+ default_branch=" ${default_branch# origin/ } "
66+
67+ if [[ -z " $default_branch " ]]; then
68+ echo " Error: unable to determine default branch in $repo_dir " >&2
69+ exit 1
70+ fi
71+
72+ git -C " $repo_dir " checkout " $default_branch " 2> /dev/null || \
73+ git -C " $repo_dir " checkout -b " $default_branch " --track " origin/$default_branch "
74+ fi
75+
6176 git -C " $repo_dir " pull
6277}
6378
You can’t perform that action at this time.
0 commit comments