6

how can I install an npm module from a bare git repo folder?

So I have a folder that contains a git repo. It was created with git init --bare. Now I want npm to fetch the latest version of the master branch, and there a package.json file is avaliable.

What is the right way to do this?

I tried stuff like:

npm install git+file:///W:/my/git/repo/ -g
npm install git+file:///W:/my/git/repo/#master -g
npm install file:///W:/my/git/repo/ -g --from-git

Is it even possible?

The npm log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'file:///W:/my/git/repo/',
1 verbose cli   '-g',
1 verbose cli   '--from-git' ]
2 info using npm@1.4.14
3 info using node@v0.10.29
4 verbose node symlink C:\Program Files\nodejs\\node.exe
5 verbose cache add [ 'file:///W:/my/git/repo/', null ]
6 verbose cache add name=undefined spec="file:///W:/my/git/repo/" args=["file:///W:/my/git/repo/",null]
7 verbose parsed url { protocol: 'file:',
7 verbose parsed url   slashes: true,
7 verbose parsed url   auth: null,
7 verbose parsed url   host: '',
7 verbose parsed url   port: null,
7 verbose parsed url   hostname: '',
7 verbose parsed url   hash: null,
7 verbose parsed url   search: null,
7 verbose parsed url   query: null,
7 verbose parsed url   pathname: '/W:/my/git/repo/',
7 verbose parsed url   path: '/W:/my/git/repo/',
7 verbose parsed url   href: 'file:///W:/my/git/repo/' }
8 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
9 verbose lock file:///W:/my/git/repo/ C:\Users\myusername\AppData\Roaming\npm-cache\cc42952a--W-my-git-repo.lock
10 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
11 silly lockFile cc42952a--W-my-git-repo file:///W:/my/git/repo/
12 error addLocal Could not install file:///W:/my/git/repo/
13 error Error: ENOENT, stat 'C:\test\file:\W:\my\git\repo'
14 error If you need help, you may report this *entire* log,
14 error including the npm and node versions, at:
14 error     <http://github.com/npm/npm/issues>
15 error System Windows_NT 6.2.9200
16 error command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "file:///W:/my/git/repo/" "-g" "--from-git"
17 error cwd C:\test
18 error node -v v0.10.29
19 error npm -v 1.4.14
20 error path C:\test\file:\W:\my\git\repo
21 error code ENOENT
22 error errno 34
23 verbose exit [ 34, true ]
Lux
  • 17,835
  • 5
  • 43
  • 73
  • 1
    The path `20 error path C:\test\file:\W:\my\git\repo` seems incorrect – Tim Jul 23 '14 at 12:38
  • well, `C:\test\` is the current working directory. I still dont understand why I get this error. – Lux Jul 23 '14 at 12:47
  • 2
    For what it's worth, as of this writing, I'm able to use `npm install git+file:///C:/my/favorite/bare/repository/` just fine. On a related note, dont forget about `npm link`, which makes development a bit easier. – Jthorpe Jan 19 '17 at 19:00

2 Answers2

6

I have a hacky answer, which might be better than no answer at all. Use Git's URL rewriting feature:

git config --global url.file://.insteadOf git+file://
npm install git+file:///c:\dev\code\mymod

It generates warnings about not being able to fetch remotes, etc., but it installs the module and npm exits with a success code.

This works because the git+ prefix makes NPM pass the whole path to Git, and then the URL rewrite rule turns git+file:// (an invalid Git protocol string) into file:// (a valid Git protocol string).

chris
  • 1,638
  • 2
  • 15
  • 17
-4

per https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Git URLs as Dependencies

Git urls can be of the form:

git://github.com/user/project.git#commit-ish
git+ssh://user@hostname:project.git#commit-ish
git+ssh://user@hostname/project.git#commit-ish
git+http://user@hostname/project/blah.git#commit-ish
git+https://user@hostname/project/blah.git#commit-ish

The commit-ish can be any tag, sha, or branch which can be supplied as an argument to git checkout. The default is master.

The documentation is specifically for the package.json file, but you can also do things like:
npm install git://github.com/user/project.git#develop_branch.

MetaSean
  • 881
  • 17
  • 25
  • 2
    This is absolutely not an answer. It does not answer how to use a git bare repo folder. – Lux Feb 16 '16 at 11:51