假设我有以下清单文件repo https://source.android.com/setup/develop/repo tool (MCVE https://stackoverflow.com/help/minimal-reproducible-example%20MCVE脚本包含在本文末尾):
<?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>
我能跑repo init ...
其次是repo sync
成为一个品牌
新目录(即没有任何先前内容)。但是当我进入
所结果的repo1
子目录(例如,/tmp/standalone_repo_expt/work_area/myproject/repo1/
),并做一个git status
我看到这个:
$ git status
Not currently on any branch.
nothing to commit, working tree clean
然后显示我看到的可用分支:
$ git branch -a
* (no branch)
remotes/m/master -> repo1/master
remotes/repo1/master
Why did repo sync
不签出到默认分支(master
) 我
中已指定default
清单文件中的标记?
类似问题
这类似于为什么 git repo 不签出指定的分支? https://stackoverflow.com/q/60921066/257924但是
不完全相同的问题。我的问题是没有分支机构已检查
出来,这似乎是错误的。我不应该做任何其他事情
除了repo sync
,我不应该跑git checkout master
在该清单文件管理的所有存储库中。
这似乎也类似于https://stackoverflow.com/a/66264612/257924 https://stackoverflow.com/a/66264612/257924但使用repo init -b master
也不做我想做的事(没有
未签出存储库对这个问题的影响
指定的分支)。
https://stackoverflow.com/a/16917618/257924 https://stackoverflow.com/a/16917618/257924接近回答
这个问题,但没有解释为什么git branch -a
才不是
包含master
紧随其后的分支repo sync
.
回购工具版本
The repo https://source.android.com/setup/develop/repo该工具于 2021 年 11 月 15 日通过以下方式直接从源中提取:
curl https://storage.googleapis.com/git-repo-downloads/repo https://storage.googleapis.com/git-repo-downloads/repo> /tmp/standalone_repo_expt/bin/repo
并将 PATH 设置为包括/tmp/standalone_repo_expt/bin
.
MCVE https://stackoverflow.com/help/minimal-reproducible-example 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