1

I am using git repo tool and I am using this bash script to create the manifest file:

repo manifest -r -o default.xml

The output in the created default.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <remote name="REMOTE_NAME" fetch="https://github.com/ORGANIZATION_NAME"/>
  
  <project name="PNG_MCU" remote="REMOTE_NAME" revision="f7815add324ea221e9e8e2cc1e13e350e9d5b461" upstream="main" dest-branch="main"/>
  <project name="PNG_Middlewares" remote="REMOTE_NAME" revision="9a2d3faa78730684295c31d193e00225fa29fe42" upstream="main" dest-branch="main"/>
  <project name="PNG_APPLICATION" remote="REMOTE_NAME" revision="b237708997e0127914d7a4364e51169540f780e5" upstream="main" dest-branch="main"/>
  <project name="PNG_HAL" remote="REMOTE_NAME" revision="b01bfbf496d8fb8bd83821f6cd3aa46c15814671" upstream="main" dest-branch="main"/>
  <project name="PNG_RTOS" remote="REMOTE_NAME" revision="1d7f4fe8d3860dc1262f85d341a0949467ce48c5" upstream="main" dest-branch="main"/>
  <project name="PNG_Drivers" remote="REMOTE_NAME" revision="29bc3f4f2f232b5af66e2f87d4d155737eac57ad" upstream="main" dest-branch="main"/>
</manifest>

My question is that I would expect that if for a certain subrepo (such as PNG_MCU for example) I was checked out on a branch that was NOT 'main' then I would expect to see that in the manifest file in the PNG_MCU row. But when I update the manifest file then it still shows 'main' as the branch under "upstream" even though the commit ID SHA that it is pointing to is NOT on main.

When I do repo sync all works well because the SHA are always correct but the branch part bothers me. I simply need this as part of a test script I am writing with github actions.

Any idea how to get the branch upstream to correlate with the commit SHA?

Eyal Gerber
  • 1,026
  • 10
  • 27

1 Answers1

0

So I got no answer to this question and I was not able to figure this out myself. Therefore, I did a workaround that served me well. I created a script that captured each subrepo status (branch,commit ID,repository name) and logged it in a txt file (called manifest_helper.txt) to be read later by my GitHub Actions script.

#!/bin/bash

#Check if manifest_helper.txt exists. If not then create it. 
if [[ -e manifest_helper.txt ]]; then
    echo "file manifest_helper.txt found."
    > manifest_helper.txt   #erase all contents of the file
else
    echo "file manifest_helper.txt not found. Creating file..."
    echo >> manifest_helper.txt
fi


echo "Capturing status of each subrepo..."
for directory in */; do #assuming the only directories are of the subrepos
    cd $directory;
            Current_Branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')    #taken from https://stackoverflow.com/a/2111099/4441211

            BRANCH_NAME=$(git branch --show-current)
            COMMIT_ID=$(git rev-parse --verify HEAD)
            SUBREPO_NAME=$directory
            echo "$BRANCH_NAME,$COMMIT_ID,${SUBREPO_NAME%?}" >> ../manifest_helper.txt # writing ${SUBREPO_NAME%?} insures that the last character of "\" is removed
        
    cd ..; 
done

echo "Updating manifest file:"
repo manifest -r -o default.xml

read -p "Repo Capture Script Done. Press any key to continue ..."
Eyal Gerber
  • 1,026
  • 10
  • 27