6

I am writing a framework which is usable for my future projects. I would like to put the framework to a privately hosted git server, and load it with composer in my future projects.

May I know when I git init, should "--bare" be used? I used to create "bare" repo, but composer said the package is not found. I have searched around, and believe it is due to "missing of composer.json". However, without "--bare", I can't even push my code to server. I "git clone" the framework to another location, and load the location with composer, still failed.

I have tried the two versions below, both failed:

"repositories": [
    {
        "type": "vcs",
        "url": "https://server/git/sdk/"
    }
]

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "vendor/sdk",
            "version": "master",
            "source": {
                "url": "https://server/git/sdk/",
                "type": "git",
                "reference": "master"
            }
        }
    }
]

Thanks.

1 Answer 1

10

I'm referencing the offical docs on how to load a package from a VCS: https://getcomposer.org/doc/05-repositories.md#using-private-repositories

To require private project B you need two things in the composer.json file of public project A:

  1. define the repository as type vcs with the URL to the private repository at your server
  2. require it

    {
        "name": "project A",    
        "description": "public project A requiring private project B",
        "require": {
            "vendor/my-private-repo": "dev-master"
        },
        "repositories": [
            {
                "type": "vcs",
                "url":  "[email protected]:vendor/my-private-repo.git"
            }
        ]
    }
    

Then run Composer. It will fetch the private project B into the vendor folder of project A.


May I know when I git init, should "--bare" be used? I used to create "bare" repo, but composer said the package is not found. I have searched around, and believe it is due to "missing of composer.json".

git init --bare creates a repository without a working tree. That means the repository contains no working or checked out copy of your source files. Only the git revision history of your repo is stored in the root folder of your repository (instead of in a .git subfolder).

I "git clone" the framework to another location, and load the location with composer, still failed.

You don't need to git clone or git init the repository to store a local copy, just fetch directly from the private server with Composer.

We have the following situation:

  • project A with a composer.json should fetch project B from private repo.
  • we are leaving git out, let Composer do the fetching. Do not fetch manually.
  • and focus only on the composer.json side of to solve this issue (see above)

Sidenote: the second repository definition you posted defines a package. This is described in https://getcomposer.org/doc/05-repositories.md#package-2 You are free require the private repo as a package, but its not needed here because the above composer.jsonshould work just fine.

Sign up to request clarification or add additional context in comments.

3 Comments

"options": { "ssh2": { "username": "dummy", "privkey_file": "" } }
I need a key to enter the host. I am using Netbeans on Windows. How should I define the key file path? Does public key file needed as well? And may I know how to specify the port in the URL [email protected]:vendor/my-private-repo.git ? Thanks!
Okay I have got it work. I use the config as mentioned by Jens, but replace the url with a SSH one. I placed a "config" with SSH key path inside "C:\Users\yourname\.ssh\". And everything works fine now. FYR this is how the "config" should look like: nerderati.com/2011/03/17/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.