Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot use remote repository in a composer on windows

I have a repository with library. It could be successfully cloned.

$ git clone file:////remote/repo/library
$ cd library
$ composer validate
./composer.json is valid, but with a few warnings

But it seems that this repostory cannot be used via a composer inclusion.

...
"repositories": [
    {
        "type": "git",
        "url": "file:////remote/repo/library"
    }]
 ...

Trying to install

$ composer install -vvv
... 
Loading composer repositories with package information
Executing command (//remote/repo/library): git show-ref --tags
Executing command (//remote/repo/library): git branch --no-color --no-abbrev -v
Executing command (//remote/repo/library): git branch --no-color
Executing command (//remote/repo/library): git show "master":composer.json

  [Composer\Repository\InvalidRepositoryException]
  No valid composer.json was found in any branch or tag of 
  file:////remote/repo/library, could not load a package from it.
...

How to use a remote repository on windows with a composer?

like image 384
sectus Avatar asked May 10 '16 09:05

sectus


People also ask

How do you fix fatal could not read from remote repository please make sure you have the correct access rights and the repository exists?

The Git “fatal: Could not read from remote repository” error occurs when there is an issue authenticating with a Git repository. This is common if you have incorrectly set up SSH authentication. To solve this error, make sure your SSH key is in your keychain and you connecting to a repository using the correct URL.

What is repositories in composer JSON?

A repository is a package source. It's a list of packages/versions. Composer will look in all your repositories to find the packages your project requires. By default, only the Packagist.org repository is registered in Composer. You can add more repositories to your project by declaring them in composer.

Does composer use Git?

It's not uncommon to find ourselves wanting to use composer to include Git repositories within our PHP project. In many cases repositories have been created on packagist.org and requiring them with composer is very straight forward.


1 Answers

Composer will be able to work out what kind of VCS you're using, so instead of "type": "git", try "type": "vcs" (see Composer docs and this SO answer).

Rather than using a git clone, you could use it by path reference if you just want to point to the local repository instead of cloning it or using git-specific operations (like version tags, etc).

Also on Windows you may need to use Windows-style formatting for the repository/library path (see Composer - using a local repository SO comment), and if it's a Windows shared drive you may need to check permissions.

EDIT

I had a more in-depth look at this, and was able to reproduce both the git clone and composer install behavior pretty easily even by just looking at the network name of my own PC.

Attempting to use Windows-style syntax (i.e. file://\\\\remote\\repo\\library) did not work for me, as it fell over in the middle of the git process somewhere.

It looks like there are some issues around named network drives interacting inside composer itself: since you can load repositories on local disks using the file:// syntax described and it's possible to correctly clone and fetch files from a networked drive using the normal //drive/repo syntax and command-line git I'm not sure if this is necessarily solvable without delving into the composer source (which was what needed to happen for someone to get local Windows drive support).

This means that setting up your network drive location to map to a letter on your local machine (as per smcjones' answer) will work as well since it would be treated the same as a local windows drive. You can also add hooks as @smcjones points out if you want to automatically map/unmap the drive (although you'd have to remember not to assign that drive letter to anything else).

Assuming you have access to the relevant computer, setting up a git daemon on the local network computer you wish to serve it up from (using this answer is pretty straightforward) so you can use the git:// protocol version works pretty well, although depending on your setup you also may need to make sure that your "minimum-stability" flag is set to "dev" and if you're not transporting over HTTPS you may need to look up your local composer config file (probably in C:\Users\Username\AppData\Roaming\Composer\config.json) and add "secure-http": false to it to serve up over the network without setting up an SSL certificate (unless you want to set that up).

like image 53
Leith Avatar answered Oct 09 '22 17:10

Leith