git

package
v0.55.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Access Method git - Git Commit Access

Synopsis

type: Git/v1

Provided blobs use the following media type for: application/x-tgz

The artifact content is provided as a gzip-compressed tar archive. Both Git/v1 and its alias Git produce archives with the checked-out files and a .git directory containing a detached HEAD and the complete history reachable from that commit. The legacy type spellings (git, git/v1alpha1, and Git/v1alpha1) retain their files-only archive format.

Archive layout

The archive is byte-identical to the one OCM v2 builds for the same commit, so a resource created by either implementation verifies against the digest recorded by the other. It therefore depends on the commit alone, not on how the source repository stores its objects nor on the host the archive was built on: tar headers carry no owner and no modification time, directories are 0755, files 0644 or 0755, and symbolic links 0777.

Next to the checked-out files it holds exactly these entries:

.git/HEAD                                  the commit, detached, without refs
.git/config                                core defaults of an initialized repository
.git/objects/info/                         (empty)
.git/objects/pack/pack-<checksum>.pack     the objects reachable from the commit,
.git/objects/pack/pack-<checksum>.idx      in hash order, submodules excluded
.git/objects/pack/pack-<checksum>.rev
.git/refs/heads/                           (empty)
.git/refs/tags/                            (empty)

Everything else a clone holds - the source remote, its references, the index and the logs - stays out of the archive. The same archive is produced by the CLI git input type, so a local blob created with it can be uploaded back into a Git repository by OCM v2.

Description

This method implements the access of the content of a git commit stored in a git repository.

The current access type is Git/v1. The legacy specification version is v1alpha1.

Specification Versions
Version v1

The type specific specification fields are:

  • repository string

    Repository URL with or without scheme.

  • ref (optional) string

    Original ref used to get the commit from

  • commit string

    The sha/id of the git commit

Go Bindings

The Go binding is defined in method.go.

Example
package main

import (
  "archive/tar"
  "bytes"
  "compress/gzip"
  "fmt"
  "io"

  "ocm.software/ocm/api/ocm"
  "ocm.software/ocm/api/ocm/cpi"
  me "ocm.software/ocm/api/ocm/extensions/accessmethods/git"
)

func main() {
  ctx := ocm.New()
  accessSpec := me.New(
    "https://github.com/octocat/Hello-World.git",
    me.WithRef("refs/heads/master"),
  )
  method, err := accessSpec.AccessMethod(&cpi.DummyComponentVersionAccess{Context: ctx})
  if err != nil {
    panic(err)
  }
  content, err := method.GetContent()
  if err != nil {
    panic(err)
  }
  unzippedContent, err := gzip.NewReader(bytes.NewReader(content))

  r := tar.NewReader(unzippedContent)

  var file *tar.Header
  for {
    file, err = r.Next()
    if err != nil {
      panic(err)
    }
    if file.Name == "README.md" {
      break
    }
  }

  data, err := io.ReadAll(r)
  if err != nil {
    panic(err)
  }
  fmt.Println(string(data))
}

Documentation

Index

Constants

View Source
const (
	Type         = "git"
	TypeV1Alpha1 = Type + runtime.VersionSeparator + "v1alpha1"

	UpperType         = "Git"
	UpperTypeV1Alpha1 = UpperType + runtime.VersionSeparator + "v1alpha1"
	UpperTypeV1       = UpperType + runtime.VersionSeparator + "v1"
)

Variables

This section is empty.

Functions

func AddConfig

func AddConfig(opts flagsets.ConfigOptions, config flagsets.Config) error

func UpperConfigHandler added in v0.55.0

func UpperConfigHandler() flagsets.ConfigOptionTypeSetHandler

Types

type AccessSpec

type AccessSpec struct {
	runtime.ObjectVersionedType `json:",inline"`

	// Repository is the repository URL
	Repository string `json:"repository"`

	// Ref defines the hash of the commit
	Ref string `json:"ref,omitempty"`

	// Commit defines the hash of the commit in string format to checkout from the Ref
	Commit string `json:"commit,omitempty"`
}

AccessSpec describes the access for a GitHub registry.

func New

func New(url string, opts ...AccessSpecOptions) *AccessSpec

New creates a Git/v1 access spec whose archive includes the commit history.

func (*AccessSpec) AccessMethod

func (*AccessSpec) Describe

func (a *AccessSpec) Describe(internal.Context) string

func (*AccessSpec) GetType

func (a *AccessSpec) GetType() string

func (*AccessSpec) GlobalAccessSpec

func (a *AccessSpec) GlobalAccessSpec(accspeccpi.Context) accspeccpi.AccessSpec

func (*AccessSpec) IsLocal

func (*AccessSpec) IsLocal(internal.Context) bool

type AccessSpecOptions

type AccessSpecOptions func(s *AccessSpec)

AccessSpecOptions defines a set of options which can be applied to the access spec.

func WithCommit

func WithCommit(commit string) AccessSpecOptions

func WithRef

func WithRef(ref string) AccessSpecOptions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL