bower: Can't use bower inside a git submodule

I am trying to run bower inside a folder that is a git submodule. This causes the ‘git ls-remote --tags --heads …’ command to fail. The error I’m seeing is:

Failed to execute "git ls-remote --tags --heads git://github.com/less/less.js.git", exit code of #128

Steps to reproduce are a bit convoluted but:

  1. Create a git project
  2. Add a submodule (into folder test)
  3. Create bower.json in the test folder and add something like bootstrap
  4. Try to run bower install inside the test folder

Bower should then error with code 128 because it cannot execute a git command. Git will say something like

fatal: Not a git repository: ../test

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 5
  • Comments: 15 (2 by maintainers)

Most upvoted comments

Just in case anyone ever comes across this rather obscure problem it can be solved by changing GIT_DIR before running bower:

GIT_DIR=/path/to/valid/git/project bower install

Thanks @linusnorton! Was running bower install on a git submodule inside a docker container using VirtualBox (Mac OS X) and this fixed the problem. If anyone else runs into this problem with docker, set the following in your Dockerfile:

# git submodules reference fix
ENV GIT_DIR=/path/to/valid/git/project

while this is a workaround, it is quite problematic in some situations where one doesn’t want to share the whole parent repo and its submodule to the docker/vagrant container.

I also had the same issue (bower install inside git submodule directory mounted on a docker container) and did something similar to @asharpe as a workaround.

However, I am curious as to why this particular workaround works. What is bower using the .git file for? And since it seems to be “optional”, could we deactivate “using the .git file” with a parameter or something like that?

Running Docker container with the src repo (which is a submodule of the project) mounted to the docker container. This worked for me as I was running bower in the root of the submodule repo.

GIT_DIR=. ./path/to/bower install --allow-root

My workaround was to rename the .git file to .git-tmp, run bower, then restore the file (I also tried with the latest bower and had the same issue).

I’m also using a submodule in a vagrant VM where the repo parent is not shared. The workaround doesn’t always work (or I’m doing it wrong)

$ mkdir -p /tmp/git-dummy
$ git init /tmp/git-dummy
$ GIT_DIR=/tmp/git-dummy bower install
....
bower angular#1.2.28                  progress Receiving objects:  51% (11158/21877), 40.54 MiB | 2.25 MiB/s
bower angular-cookies#1.2.28           ECMDERR Failed to execute "git checkout 3bbaa39114fa18101a69ed368fb39bc2e1c2a78b", exit code of #128 fatal: Not a git repository: '/tmp/git-dummy'

Additional error details:
fatal: Not a git repository: '/tmp/git-dummy'


┌──────────────────────────────────────────┐
│ Update available: 1.7.9 (current: 1.7.1) │
│ Run npm install -g bower to update.      │
└──────────────────────────────────────────┘