Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't run git ls-remote in the project directory #6081

Open
Diggsey opened this issue Jul 10, 2018 · 5 comments
Open

Don't run git ls-remote in the project directory #6081

Diggsey opened this issue Jul 10, 2018 · 5 comments
Assignees

Comments

@Diggsey
Copy link

Diggsey commented Jul 10, 2018

What is the current behavior?

Currently, when installing a dependency from a git repo, yarn will at some point run git ls-remote <url> to find the tags in that repo.

Unfortunately, there is a bug/feature in git, where git ls-remote will fail if run in an invalid git repo, even though it will work fine without any git repo.

If the current behavior is a bug, please provide the steps to reproduce.

  • Create an invalid git repo
    Easiest way to do this is to create a file called .git with the contents gitdir: ../../.git/modules/something
  • Create a package.json with a git dependency
  • Try to run yarn

What is the expected behavior?

Install should succeed, taking no notice of invalid git repo.

Yarn should run git ls-remote in a different directory: one known to be outside any valid/invalid git repo. Where doesn't really matter.

@ghost ghost assigned rally25rs Jul 10, 2018
@ghost ghost added the triaged label Jul 10, 2018
@rally25rs
Copy link
Contributor

Why would you use a git dependency to include something that isn't a git repo, or isn't a valid git repo? This doesn't seem like a yarn problem, more like an invalid use case.

@Diggsey
Copy link
Author

Diggsey commented Jul 30, 2018

@rally25rs please re-read the description. The dependency is a perfectly valid git repo: the problem here is when the working directory is not a valid git repo. Yarn should not have any assumptions about the working directory being a valid git repo.

@davidroeca
Copy link

davidroeca commented Sep 10, 2018

@rally25rs this happens when the working directory is mounted as a docker volume:

meta-repo/
  .git/ # directory
  docker-compose.yml
  submodule-app/ #mounted as a volume
    .git # just a file
    Dockerfile
    .dockerignore # ignores .git in the COPY/ADD directive; volumes don't ignore 

For example, let's say I'm developing an app running in docker and want to add a new dependency; if the entire submodule directory is mounted as a volume, the .git file is also there.

I can hack this by making sure the parent directory contains the parent repository's .git directory, but it would be nice if yarn (and potentially git) were failure-tolerant with this approach.

@guillaume86
Copy link

I have the same use case as @davidroeca and the same issue.

@zavan
Copy link

zavan commented Mar 13, 2023

I also have the exact same problem as @davidroeca.

I found a work around. In your Dockerfile:

# Initialize an empty git repo.
RUN git init /fakegit

# Tell git to use that repo instead of the .git file in the submodule.
ENV GIT_DIR=/fakegit/.git

Ig you're using docker compose just add the env var to environment:

environment:
  GIT_DIR: /fakegit/.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants