'Why is repo sync not checking out the branch I had specified in the manifest file?
Suppose I have the following manifest file for the repo tool (MCVE script is included at the end of this post):
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="repo1" fetch="/tmp/standalone_repo_expt/git.repos" />
<remote name="repo2" fetch="/tmp/standalone_repo_expt/git.repos" />
<default remote="repo1" revision="master" />
<project name="repo1" path="repo1" />
<project name="repo2" path="repo2" />
</manifest>
I'm able to run repo init ...
followed by repo sync
into a brand
new directory (i.e., without any prior contents). But when I cd into
the resulting repo1
subdirectory (e.g.,
/tmp/standalone_repo_expt/work_area/myproject/repo1/
), and do a git status
I see this:
$ git status
Not currently on any branch.
nothing to commit, working tree clean
And then showing what branches are available I see:
$ git branch -a
* (no branch)
remotes/m/master -> repo1/master
remotes/repo1/master
Why did repo sync
not check out to the default branch (master
) that I
had specified in the default
tag in the manifest file?
Similar questions
This is similar to Why doesn't git repo checkout the branch specified? but is
not quite the same issue. My issue is that no branch is checked
out, and that seems wrong. I should not have to do anything else
other than the repo sync
, and I should not have to run git checkout master
in all of the repositories managed by that manifest file.
This also seems similar to https://stackoverflow.com/a/66264612/257924
but using repo init -b master
does not do what I want either (has no
effect on this problem of the repositories not being checked out to
the specified branch).
https://stackoverflow.com/a/16917618/257924 gets close to answering
this question, but does not explain why git branch -a
does not
contain the master
branch right after the repo sync
.
Repo tool version
The repo tool was pulled from source directly on 2021-11-15 via:
curl https://storage.googleapis.com/git-repo-downloads/repo > /tmp/standalone_repo_expt/bin/repo
and the PATH set to include /tmp/standalone_repo_expt/bin
.
MCVE script
#!/bin/bash
function generate_repo {
local repo_num="$1"
mkdir -p /tmp/standalone_repo_expt/git.repos/repo$repo_num.git
cd /tmp/standalone_repo_expt/git.repos/repo$repo_num.git
git init --bare
mkdir -p /tmp/standalone_repo_expt/work_area
git clone /tmp/standalone_repo_expt/git.repos/repo$repo_num.git || {
echo ERROR: git clone /tmp/standalone_repo_expt/git.repos/repo$repo_num.git
exit 1
}
(
cd repo$repo_num
touch repo$repo_num.README
git add repo$repo_num.README
git commit -m "Add repo$repo_num.README"
git push origin
)
(
mkdir -p /tmp/standalone_repo_expt/work_area/repo$repo_num.test_clone
cd /tmp/standalone_repo_expt/work_area/repo$repo_num.test_clone
git clone /tmp/standalone_repo_expt/git.repos/repo$repo_num.git
ls -ld repo$repo_num/*
cd repo$repo_num
git status
)
}
# Remove the entire set of git repos for reproducable execution:
rm -rf /tmp/standalone_repo_expt
# Generate the git repositories, that we wish to combine into one
# larger directory, using the repo tool:
generate_repo 1
generate_repo 2
# Install the repo tool from source, not using any package managers:
mkdir -p /tmp/standalone_repo_expt/bin
curl https://storage.googleapis.com/git-repo-downloads/repo > /tmp/standalone_repo_expt/bin/repo
test -s /tmp/standalone_repo_expt/bin/repo || {
echo "ERROR: Failed to download repo tool into /tmp/standalone_repo_expt/bin/repo"
exit 1
}
chmod a+rx /tmp/standalone_repo_expt/bin/repo
PATH="/tmp/standalone_repo_expt/bin:${PATH}"
which repo >& /dev/null || {
echo "ASSERTION FAILED: Failed to install the repo tool."
exit 1
}
# Create the git repository that houses the manifest that are needed
# by the repo tool that reference the git repositories generated
# above:
mkdir -p /tmp/standalone_repo_expt/git.repos/manifests.git
cd /tmp/standalone_repo_expt/git.repos/manifests.git
git init --bare
# Clone the manifest bare repo so we can add the manifest file, and
# push it back:
cd /tmp/standalone_repo_expt/work_area
git clone /tmp/standalone_repo_expt/git.repos/manifests.git || {
echo ERROR: git clone /tmp/standalone_repo_expt/git.repos/manifests.git failed
exit 1
}
cd manifests
cat > default.xml <<EOF.manifest
<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="repo1" fetch="/tmp/standalone_repo_expt/git.repos" />
<remote name="repo2" fetch="/tmp/standalone_repo_expt/git.repos" />
<default remote="repo1" revision="master" />
<project name="repo1" path="repo1" />
<project name="repo2" path="repo2" />
</manifest>
EOF.manifest
cat default.xml
git add default.xml
git commit -m "Manifest file used by the repo tool"
git push origin || {
echo ERROR: git push origin failed
exit 1
}
set -x
mkdir -p /tmp/standalone_repo_expt/work_area/myproject
cd /tmp/standalone_repo_expt/work_area/myproject
repo init /tmp/standalone_repo_expt/git.repos/manifests.git
repo sync
cd repo1
pwd
ls -l
git status
Solution 1:[1]
repo
doesn't create a local branch for you. When you check out a remote branch you'll end up with a detached head (since you can't make commits on the remote branch anyway).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Silon |