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
@linusnorton I wasn't able to replicate this - what is your bower version? Could you create a sample git project to show this off?
Oh dear, it only appears to be an issue inside vagrant where the path to the parent git project is not available. My mistake, I'll close this off.
ah! great investigating :D
thanks a lot for reaching out with the report, its always very much appreciated
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
+1 Thanks :)
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'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. โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
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).
Even though this issue is marked as closed, the same error (#128) occurs when running a bower install during a docker build. The workaround by @linusnorton works here, too.
I'd recommend taking a look at the new nodejs Dockerfiles. This worked like a charm.
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?
This workaround doesn't work for me and I'm not sure why, as I've just gotten it down to testing something like GIT_DIR=/my/submodule/path && git log --oneline; and even the git --git-dir=... log --online form; and neither work. I understand this is might be classified as a git (and/or VM) issue but the problem is actually architectural and affects BowerJS and NPM: using SCCS as a dependency repository has been tried before and proven to be problematic.
UPDATE: the workaround works. I was testing within Vagrant. The full workaround in vagrant is to share the .git parent directory to the vagrant client and then use GIT_DIR, and finally I had to export GIT_DIR to the environment for bower. In other words, from the VM, GIT_DIR=/vagrant-dot-git/ && git status works; but GIT_DIR=/vagrant-dot-git/ && bower install fails without export.
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
For those who use docker-compose.yml with volume mounts to make development easy ... I wanted to use the tips provided here like so:
docker-compose run builder GIT_DIR=. ./node_modules/.bin/bower install --allow-root
But that wouldn't work because docker is expecting the first argument (GIT_DIR in this case) to be an executable command.
So instead I placed GIT_DIR in the compose file to accomplish what everyone's recommended here and it worked:
# inside my docker-compose.yml file
# ...
image: node:7.10.0
environment:
# https://github.com/bower/bower/issues/1492#issuecomment-193305102
GIT_DIR: .
and then ran the command:
docker-compose run builder ./node_modules/.bin/bower install --allow-root
Most helpful comment
Just in case anyone ever comes across this rather obscure problem it can be solved by changing GIT_DIR before running bower: