Skip to content

Conversation

@bk2204
Copy link
Member

@bk2204 bk2204 commented Apr 28, 2025

Android's repo tool creates .git/objects as a symlink to a place outside the .git directory for unknown reasons. When that happens, Git operations where we set the working directory to that directory fail. This is because when Git performs discovery on the working directory, it first canonicalizes the path, which takes it outside of the .git directory and it then fails to find anything that looks like a Git repository.

In our codebase, we set the path to the object directory root in a couple of places which cause this problem. To avoid this problem, simply join the repository root with .., which is always applied before canonicalization and will result in the path being properly set to the .git directory, which results in git lfs migrate import working correctly in this configuration.

Fixes #5426
Fixes #6030

Android's `repo` tool creates `.git/objects` as a symlink to a place
outside the `.git` directory for unknown reasons.  When that happens,
Git operations where we set the working directory to that directory
fail.  This is because when Git performs discovery on the working
directory, it first canonicalizes the path, which takes it outside of
the `.git` directory and it then fails to find anything that looks like
a Git repository.

In our codebase, we set the path to the object directory root in a
couple of places which cause this problem.  To avoid this problem,
simply join the repository root with `..`, which is always applied
before canonicalization and will result in the path being properly set
to the `.git` directory, which results in `git lfs migrate import`
working correctly in this configuration.
@bk2204 bk2204 marked this pull request as ready for review April 29, 2025 13:03
@bk2204 bk2204 requested a review from a team as a code owner April 29, 2025 13:03
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks very much for jumping in with a fix for these issues!

I was puzzled for a few minutes as to how the existing code could have functioned at all, if adding a .. path segment at the end of a so-called "root" path also works without problems (and solves some others), until I realized what is meant by the term "root" in this context.

Thanks again very much for fixing these problems!

Reference Notes

For my own future reference, the "root" referred to here is not the top of the repository's working tree or the top of Git's internal directory structure (i.e., .git), but the top of Git's internal object database directory structure (i.e., .git/objects). So appending a .. path segment always takes us back up to the top of Git's internal directory structure.

We construct the path to the .git/objects directory by first calling the GitCommonDir() method of our git package, which usually runs git rev-parse --git-common-dir, and then passing that path to the ObjectDatabase() method, which appends the objects path segment, unless GIT_OBJECT_DIRECTORY is specified directly. The resultant path is what is then used in the call to create the ObjectDatabase using our git-lfs/gitobj package.

@chrisd8088 chrisd8088 added git-core migration Related to `git lfs migrate` labels Apr 30, 2025
@chrisd8088 chrisd8088 merged commit 4504241 into git-lfs:main May 2, 2025
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement git-core migration Related to `git lfs migrate`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git-lfs-migrate import doesn't work when .git/objects is a symlink Bad revision fatal error when .git is a symbolic link with symbolic links inside

3 participants