Skip to content

🔧 AddVcsRepository

Adds a version control system (VCS, e.g. Git, SVN) repository as a Composer package source, equivalent to adding a repository with type set to vcs in composer.json.

When to use

Use when you need to pull packages directly from VCS repositories such as GitHub / GitLab / Bitbucket, commonly used to install private packages or development branches that have not been published to Packagist.

Signature

go
func (c *Composer) AddVcsRepository(name string, url string) error

Parameters

ParameterTypeDescription
namestringRepository name, used as the key of repositories.<name> in composer.json
urlstringURL of the VCS repository, e.g. https://github.com/vendor/package

Return value

error: Returns the corresponding error message if an error occurs while adding the VCS repository; nil on success.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	// Add a VCS repository on GitHub
	if err := comp.AddVcsRepository("my-lib", "https://github.com/vendor/package"); err != nil {
		log.Fatalf("failed to add VCS repository: %v", err)
	}

	fmt.Println("VCS repository added")
}

Advanced

  • To add a private Composer repository source, use AddComposerRepository; to add a local path, use AddPathRepository.
  • After adding, you can view all configured repositories with ListRepositories.
  • When a repository is no longer needed, remove it with RemoveRepository.
  • The underlying implementation is AddRepository(name, Repository{Type: VcsRepository, URL: url}).

Released under the MIT License