repo sync时其他操作导致电脑死机,重启后继续repo时,出现如下错误:
$ repo sync -cdf
Syncing work tree: 67% (344/512) fatal: This operation must be run in a work tree
Traceback (most recent call last):
File "/home/panos/android/cm13/.repo/repo/main.py", line 531, in <module>
_Main(sys.argv[1:])
File "/home/panos/android/cm13/.repo/repo/main.py", line 507, in _Main
result = repo._Run(argv) or 0
File "/home/panos/android/cm13/.repo/repo/main.py", line 180, in _Run
result = cmd.Execute(copts, cargs)
File "/home/panos/android/cm13/.repo/repo/subcmds/sync.py", line 769, in Execute
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
File "/home/panos/android/cm13/.repo/repo/project.py", line 1247, in Sync_LocalHalf
self._InitWorkTree(force_sync=force_sync)
File "/home/panos/android/cm13/.repo/repo/project.py", line 2393, in _InitWorkTree
raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree
这是因为第一次repo sync到某个porject时,由于关机导致这个project的内容出现错误
解决方法:
1 先用repo --trace sync -cdf将repo的所有动作详细输出,
会发现在这里出错导致:
: export GIT_DIR=......./vendor/mediatek/proprietary/hardware/gsm0710muxd
: git rev-parse --verify refs/remotes/github/cm-13.0-caf-8996^0 1>| 2>|
: cd ......../vendor/mediatek/proprietary/hardware/gsm0710muxd
: git read-tree --reset -u -v HEAD 1>| 2>|
fatal: This operation must be run in a work tree
Traceback (most recent call last):
File "/home/panos/android/cm13/.repo/repo/main.py", line 531, in <module>
_Main(sys.argv[1:])
File "/home/panos/android/cm13/.repo/repo/main.py", line 507, in _Main
result = repo._Run(argv) or 0
File "/home/panos/android/cm13/.repo/repo/main.py", line 180, in _Run
result = cmd.Execute(copts, cargs)
File "/home/panos/android/cm13/.repo/repo/subcmds/sync.py", line 769, in Execute
project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
File "/home/panos/android/cm13/.repo/repo/project.py", line 1247, in Sync_LocalHalf
self._InitWorkTree(force_sync=force_sync)
File "/home/panos/android/cm13/.repo/repo/project.py", line 2393, in _InitWorkTree
raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree
2 因此,将vendor/mediatek/proprietary/hardware/gsm0710muxd这个文件夹删除,在manifest中查找这个路径对应的project是
<project name="alps/vendor/mediatek/proprietary/hardware/gsm0710muxd" path="vendor/mediatek/proprietary/hardware/gsm0710muxd" />
于是,在.repo/projects下删除.repo/projects/vendor/mediatek/proprietary/hardware/gsm0710muxd.git目录,以及
.repo/project-objects/vendor/mediatek/proprietary/hardware/gsm0710muxd.git目录
3 最后重新repo sync即可
repo的trace选项的作用
You can trace what really happens with repo --trace init ...