1. 程式人生 > >repo sync error: cannot initialize work tree

repo sync error: cannot initialize work tree

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 ...