androidgitsynchronizationandroid-sourcerepo

AOSP repo sync error, bad object HEAD


I have worked with and successfully compiled and installed AOSP about a year or two ago. I'm trying to get back up and running in it to do some development. However, I keep getting this error:

    Fetching projects: 100% (486/486), done.  
Traceback (most recent call last):
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/main.py", line 500, in <module>
    _Main(sys.argv[1:])
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/main.py", line 476, in _Main
    result = repo._Run(argv) or 0
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/main.py", line 155, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/subcmds/sync.py", line 675, in Execute
    project.Sync_LocalHalf(syncbuf)
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/project.py", line 1204, in Sync_LocalHalf
    lost = self._revlist(not_rev(revid), HEAD)
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/project.py", line 2241, in _revlist
    return self.work_git.rev_list(*a, **kw)
  File "/home/hoshi/WORKING_DIRECTORY/.repo/repo/project.py", line 2435, in rev_list
    p.stderr))
error.GitError: device/lge/mako-kernel rev-list ('^7bf237bdf8a8c6d516219dc09b3bc114aa0e863d', 'HEAD', '--'): fatal: bad object HEAD

This occurs after successfully "fetching all the packages" (first line of above terminal output). I've tried deleting the .repo folder in WORKING_DIRECTORY and re-initializing repo there. I thought it fixed the issue, but got the error again after probably a couple hours of syncing! I've tried several solutions from various discussions/forums and can't seem to figure it out.

Any help finding a solution would be much appreciated!


Solution

  • I know the question was posted over a year ago but this answer will hopefully help others. Plus it's frustrating when this happens as the fetching can take many minutes before you know the error still exists or is finally resolved.

    The solution is to purge the .git folders for the associated project named in the error message (in this case it was lge/mako-kernel)

    $ rm -rf .repo/project-objects/device/lge/mako-kernel.git
    $ rm -rf .repo/projects/device/lge/mako-kernel.git
    $ rm -rf device/lge/mako-kernel/.git
    

    Note if don't delete all three of the folders, the tree status will be inconsistent and the same error will occur.

    This was also reported in multiple projects so I applied this iteratively until the whole sync was successful.