Skip to content

Commit 6cbf2c0

Browse files
committed
Update submodule to change branch in submodule fetching rather cause it still fetches the main branch's last commit AGAIN!
1 parent 6313889 commit 6cbf2c0

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

.github/workflows/submodule_listener.yaml

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,35 @@ jobs:
3434
git submodule init
3535
TARGET_REPO="${{ github.event.client_payload.repo }}"
3636
TARGET_BRANCH="${{ github.event.client_payload.branch }}"
37-
echo "Looking for submodule matching repo: $TARGET_REPO"
38-
SUB_PATH=$(git config --file .gitmodules --get-regexp url | grep "$TARGET_REPO" | awk '{print $1}' | sed 'submodule\.\(.*\)\.url/\1/')
39-
if [ -z "$SUB_PATH" ]; then
40-
SUB_PATH=$(git config --file .gitmodules --get-regexp path | grep -i "bora" | head -n 1 | awk '{print $2}')
37+
REPO_NAME=$(basename "$TARGET_REPO")
38+
echo "Searching .gitmodules for a URL containing: $REPO_NAME"
39+
40+
# Finds the 'submodule.NAME.url' that matches our repo,
41+
# Or gets the 'submodule.NAME.path' for that same NAME.
42+
SUB_NAME=$(git config --file .gitmodules --get-regexp url | grep -i "$REPO_NAME" | head -n 1 | cut -d'.' -f2)
43+
44+
if [ -z "$SUB_NAME" ]; then
45+
echo "Direct URL match failed. Trying a case-insensitive path search..."
46+
SUB_PATH=$(git config --file .gitmodules --get-regexp path | grep -i "$REPO_NAME" | head -n 1 | awk '{print $2}')
4147
else
42-
SUB_PATH=$(git config --file .gitmodules --get "submodule.$SUB_PATH.path")
48+
SUB_PATH=$(git config --file .gitmodules --get "submodule.$SUB_NAME.path")
4349
fi
4450
4551
if [ -n "$SUB_PATH" ]; then
46-
echo "Found submodule at path: $SUB_PATH. Updating to branch: $TARGET_BRANCH"
52+
echo "Found submodule at path: $SUB_PATH"
53+
echo "Updating to branch: $TARGET_BRANCH"
54+
4755
git submodule update --init "$SUB_PATH"
4856
cd "$SUB_PATH"
4957
git fetch origin "$TARGET_BRANCH"
50-
git checkout "$TARGET_BRANCH"
58+
git checkout "$TARGET_BRANCH" || git checkout -b "$TARGET_BRANCH" origin/"$TARGET_BRANCH"
5159
git pull origin "$TARGET_BRANCH"
5260
cd -
5361
else
54-
echo "ERROR: Could not find a submodule path matching $TARGET_REPO in .gitmodules!"
55-
echo "Current .gitmodules content:"
62+
echo "ERROR: Could not map $TARGET_REPO to a local path in .gitmodules."
63+
echo "--- Current .gitmodules ---"
5664
cat .gitmodules
57-
exit 1 # Fail the build so you can see the log
65+
exit 1
5866
fi
5967
6068
- name: Commit and Push

global

Submodule global updated 1 file

0 commit comments

Comments
 (0)