windows下repo sync error: cannot initialize work tree

1. 問題描述

下載Android源代碼時,出現這個錯誤php

Traceback (most recent call last):
  File "E:\LocalProject\Oreo\.repo\repo/main.py", line 538, in <module>
    _Main(sys.argv[1:])
  File "E:\LocalProject\Oreo\.repo\repo/main.py", line 512, in _Main
    result = repo._Run(argv) or 0
  File "E:\LocalProject\Oreo\.repo\repo/main.py", line 185, in _Run
    result = cmd.Execute(copts, cargs)
  File "E:\LocalProject\Oreo\.repo\repo\subcmds\sync.py", line 823, in Execute
    project.Sync_LocalHalf(syncbuf, force_sync=opt.force_sync)
  File "E:\LocalProject\Oreo\.repo\repo\project.py", line 1335, in Sync_LocalHalf
    self._InitWorkTree(force_sync=force_sync)
  File "E:\LocalProject\Oreo\.repo\repo\project.py", line 2502, in _InitWorkTree
    raise GitError("cannot initialize work tree")
error.GitError: cannot initialize work tree

2. 問題分析

2.1 查看哪裏出了問題

從log來看,.repo/repo/project.py是要關注的地方,能夠定位到腳本:
raise GitError("cannot initialize work tree")
其所在的函數爲_InitWorkTreejava

_InitWorkTree完整的代碼以下:linux

def _InitWorkTree(self, force_sync=False):
    dotgit = os.path.join(self.worktree, '.git')
    print("dotgit is {0}".format(dotgit))
    print(self.gitdir)
    init_dotgit = not os.path.exists(dotgit)
    try:
      if init_dotgit:
        os.makedirs(dotgit)
        self._ReferenceGitDir(self.gitdir, dotgit, share_refs=True,
                              copy_all=False)

      try:
        self._CheckDirReference(self.gitdir, dotgit, share_refs=True)
      except GitError as e:
        if force_sync:
          try:
            shutil.rmtree(dotgit)
            return self._InitWorkTree(force_sync=False)
          except:
            raise e
        raise e

      if init_dotgit:
        _lwrite(os.path.join(dotgit, HEAD), '%s\n' % self.GetRevisionId())

        cmd = ['read-tree', '--reset', '-u']
        cmd.append('-v')
        cmd.append(HEAD)
        if GitCommand(self, cmd).Wait() != 0:
          raise GitError("cannot initialize work tree")

        self._CopyAndLinkFiles()
    except Exception:
      if init_dotgit:
        shutil.rmtree(dotgit)
      raise

可是此處並不能給咱們什麼有效信息,因此咱們要進一步繼續分析android

2.2 repo --trace sync

用 repo --trace sync -cdf 將repo的全部動做詳細輸出(這個過程可能會很長,須要咱們耐心等待),會發如今這裏出錯致使:git

: cd E:\LocalProject\Oreo\external\kmod
: git read-tree --reset -u -v HEAD 1>| 2>|
error: unable to create symlink testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb: File exists

至此,咱們就定位到了問題。github

2.3添加打印信息

固然,在不熟悉repo命令的時候,咱們也能夠添加log來了解當前卡在了哪裏。爲了找到當前出錯時,git正在處理哪一個目錄,我在_InitWorkTree
函數中加了2句log信息:apache

print("dotgit is {0}".format(dotgit))
    print(self.gitdir)
def _InitWorkTree(self, force_sync=False):
    dotgit = os.path.join(self.worktree, '.git')
    print("dotgit is {0}".format(dotgit))
    print(self.gitdir)
    init_dotgit = not os.path.exists(dotgit)
    try:
      if init_dotgit:
        os.makedirs(dotgit)
        ...
      ...
    ...

打印出來的log以下:segmentfault

dotgit is E:\LocalProject\Oreo\external\kmod\.git
E:/LocalProject/Oreo/.repo/projects/external/kmod.git

能夠看出當前是在處理E:\LocalProject\Oreo\external\kmod時出了問題。可是因爲log有限,咱們其實並不能真正的瞭解到當前發生了什麼。windows


3.解決方案

前面的log是說file沒法建立。緣由是是要建立的文件名字叫usb:btusb,這種命名是明顯違反Windows命名規則的。因此實際上是無解的。
因此我打算先繞過這個問題,先把源碼的其餘部分下載下來,對於這個問題,之後再解決。既然這個項目有問題,那我就先不下載了,不能因小失大嘛。
打開.repo/manifest/default.xmlapp

<!--<project path="external/kmod" name="platform/external/kmod" groups="pdk" />-->

在網上搜了一圈,好像不少網友在windows下下載代碼都遇到了"cannot initialize work tree"的問題。連Microsoft提供的win10下linux子系統的repo都有問題(最後參考連接裏邊有該問題的解決方案)。也是路徑名稱的問題。有興趣的網友能夠本身爬樓研究下。
Microsoft:https://github.com/Microsoft/...

我此次下載中還遇到了兩次"cannot initialize work tree"這樣的問題

下載「platform/libcore」出錯

error: unable to create file luni/src/test/resources/org/apache/harmony/tests/java/lang/test?.properties: Invalid argument

「test?.properties」這個也是違反了Windows文件命名問題

下載「external/libunwind」出錯

fatal: cannot create directory at 'aux': Invalid argument

這個是文件夾命名爲「aux」出錯,「aux」是Windows設備名文件夾。DOS上使用AUX,是auxiliary device的縮寫,輔助設備,在DOS系統手冊有聲明這是系統標識符的。AUX默認是異步端口的流名字,一般與Console連在一塊兒,屬於標準命名設備,因此不容許你建立使用了系統保留名字的文件,由於文件也屬於流設備。

若是你們想體驗下這個問題,能夠單獨下載這三個項目試試 git clone url
下載單個項目的方法 https://segmentfault.com/a/11...

$ git clone   https://aosp.tuna.tsinghua.edu.cn/platform/external/libunwind
Cloning into 'libunwind'...
remote: Counting objects: 16490, done.
remote: Compressing objects: 100% (5188/5188), done.
remote: Total 16490 (delta 11521), reused 15746 (delta 11246)
Receiving objects: 100% (16490/16490), 4.18 MiB | 4.01 MiB/s, done.
Resolving deltas: 100% (11521/11521), done.
fatal: cannot create directory at 'aux': Invalid argument
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'
$ git clone   https://aosp.tuna.tsinghua.edu.cn/platform/external/kmod
Cloning into 'kmod'...
remote: Counting objects: 6864, done.
remote: Compressing objects: 100% (1851/1851), done.
remote: Total 6864 (delta 4941), reused 6514 (delta 4746)
Receiving objects: 100% (6864/6864), 5.51 MiB | 420.00 KiB/s, done.
Resolving deltas: 100% (4941/4941), done.
error: unable to stat just-written file testsuite/rootfs-pristine/test-loaded/sys/module/btusb/drivers/usb:btusb: No such file or directory
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'
$ git clone   https://aosp.tuna.tsinghua.edu.cn/platform/libcore
Cloning into 'libcore'...
remote: Counting objects: 245949, done.
remote: Compressing objects: 100% (474/474), done.
remote: Total 245949 (delta 263), reused 83 (delta 32)
Receiving objects: 100% (245949/245949), 86.37 MiB | 3.97 MiB/s, done.
Resolving deltas: 100% (157977/157977), done.
error: unable to create file luni/src/test/resources/org/apache/harmony/tests/java/lang/test?.properties: Invalid argument
Checking out files: 100% (6121/6121), done.
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

5. 備註

我下載的是android_8.1.0_r17版本的代碼:
repo init -u https://aosp.tuna.tsinghua.ed... -b android_8.1.0_r1

repo的trace選項的做用
You can trace what really happens with repo

系統
Windows7

參考連接

repo和Git的關係 https://blog.csdn.net/qugenam...
WSL https://github.com/Microsoft/...
FixDownloadAnrdoid https://github.com/NyaSik/Fix...
repo sync error: cannot initialize work tree https://blog.csdn.net/ly89070...
出現error: unable to create file tests/P_str_escape/str\escape.rs的解決辦法 https://blog.csdn.net/u013553...
不能在 win7 下創建命爲 aux 的文件夾? http://bbs.bccn.net/m.thread....

相關文章
相關標籤/搜索