@@ -100,3 +100,49 @@ then
100100 fi
101101 popd . > /dev/null
102102fi
103+
104+ # --- Root repo details ---
105+ # Retrieve current branch (or tag) and commit SHA.
106+ git_branch=$( git symbolic-ref --short -q HEAD || echo " " )
107+ git_tag=$( git describe --tags --exact-match 2> /dev/null || echo " " )
108+ git_commit_sha=$( git log -1 --format=" %h" --abbrev=7)
109+ git_branch_or_tag=" ${git_branch:- ${git_tag} } "
110+ if [ -z " ${git_branch_or_tag} " ]; then
111+ git_branch_or_tag=" detached"
112+ fi
113+
114+ plutil -replace com-loopkit-Loop-branch -string " ${git_branch_or_tag} " " ${info_plist_path} "
115+ plutil -replace com-loopkit-Loop-commit-sha -string " ${git_commit_sha} " " ${info_plist_path} "
116+
117+ # --- Submodule details ---
118+ # Remove an existing submodules key if it exists, then create an empty dictionary.
119+ # (Using PlistBuddy, which is available on macOS)
120+ submodules_key=" com-loopkit-Loop-submodules"
121+ if /usr/libexec/PlistBuddy -c " Print :${submodules_key} " " ${info_plist_path} " 2> /dev/null; then
122+ /usr/libexec/PlistBuddy -c " Delete :${submodules_key} " " ${info_plist_path} "
123+ fi
124+ /usr/libexec/PlistBuddy -c " Add :${submodules_key} dict" " ${info_plist_path} "
125+
126+ # Gather submodule details.
127+ # We use git submodule foreach to output lines in the form:
128+ # submodule_name|branch_or_tag|commit_sha
129+ submodules_info=$( git submodule foreach --quiet '
130+ sub_git_branch=$(git symbolic-ref --short -q HEAD || echo "")
131+ sub_git_tag=$(git describe --tags --exact-match 2>/dev/null || echo "")
132+ sub_git_commit_sha=$(git log -1 --format="%h" --abbrev=7)
133+ sub_git_branch_or_tag="${sub_git_branch:-${sub_git_tag}}"
134+ if [ -z "${sub_git_branch_or_tag}" ]; then
135+ sub_git_branch_or_tag="detached"
136+ fi
137+ echo "$name|$sub_git_branch_or_tag|$sub_git_commit_sha"
138+ ' )
139+
140+ # For each line, add a dictionary entry for that submodule.
141+ echo " ${submodules_info} " | while IFS=" |" read -r submodule_name sub_branch sub_sha; do
142+ # Create a dictionary for this submodule
143+ /usr/libexec/PlistBuddy -c " Add :${submodules_key} :${submodule_name} dict" " ${info_plist_path} "
144+ /usr/libexec/PlistBuddy -c " Add :${submodules_key} :${submodule_name} :branch string ${sub_branch} " " ${info_plist_path} "
145+ /usr/libexec/PlistBuddy -c " Add :${submodules_key} :${submodule_name} :commit_sha string ${sub_sha} " " ${info_plist_path} "
146+ done
147+
148+ echo " BuildDetails.plist has been updated at: ${info_plist_path} "
0 commit comments