Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loading a custom git repository with composer

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.

like image 531
ロジャー Avatar asked Mar 12 '23 02:03

ロジャー


1 Answers

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.

like image 122
Jens A. Koch Avatar answered Mar 15 '23 06:03

Jens A. Koch