Skip to content

Commit cd0c6b4

Browse files
authored
scripts: build-alsa-tools: handle detached HEAD update
1 parent 8a26adf commit cd0c6b4

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

scripts/build-alsa-tools.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,23 @@ declare -a TARGET_ARGS=(
5656
# Function to update the repository
5757
update_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

0 commit comments

Comments
 (0)