gitinfo

package module
v0.0.0-...-8bf0e53 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2017 License: MIT Imports: 8 Imported by: 0

README

go-gitinfo

Package gitinfo provides an interface to high-level git information for a git working copy. gitinfo attempts to use the locally installed git executable using go-gittools.

import "github.com/denormal/go-gitinfo"

// load git information for a particular working copy
info, err := gitinfo.NewWithPath("/my/git/working/copy")
if err != nil {
    panic(err)
}

// is this working copy modified?
modified, err := info.Modified()
if err != nil {
    panic(err)
} else if modified {
    fmt.Printf("%s is modified\n", info.Root())
}

// what is the head commit hash?
commit, err := info.Commit()
if err != nil {
    panic(err)
} else if commit != nil {
    fmt.Printf("%s HEAD is at commit %s\n", info.Root(), commit.Prefix(8))
}

For more information see godoc github.com/denormal/go-gitinfo.

Installation

go-gitinfo can be installed using the standard Go approach:

go install github.com/denormal/go-gitinfo

go-gitinfo also provides a command-line tool for extracting git information:

go install github.com/denormal/go-gitinfo/cmd/gitinfo

Command help may be accessed using

% gitinfo --help

License

Copyright (c) 2016 Denormal Limited

MIT License

Documentation

Overview

Package gitinfo provides an interface to high-level git information for a git working copy. gitinfo attempts to use the locally installed "git" executable using https://github.com/denormal/go-gittools.

Index

Constants

View Source
const (
	BRANCH     = "branch"
	COMMIT     = "commit"
	EDITOR     = "editor"
	GIT        = "git"
	MODIFIED   = "modified"
	PATH       = "path"
	ROOT       = "root"
	USER_NAME  = "user.name"
	USER_EMAIL = "user.email"
)

Variables

View Source
var (
	MissingGitError         = gittools.MissingGitError
	MissingWorkingCopyError = gittools.MissingWorkingCopyError
	UnknownCallerError      = errors.New("unable to determine caller")
)

Functions

This section is empty.

Types

type Commit

type Commit interface {
	// String returns the full commit hash.
	String() string

	// Prefix returns the first n characters of the commit hash.
	Prefix(n int) string
}

Commit represents a git commit hash.

type GitInfo

type GitInfo interface {
	// Branch returns the current branch name for the working copy. If the
	// GitInfo instance was initialised for a path not within a working copy,
	// Branch will return the empty string. An error is returned if there is
	// a problem determining the branch name.
	Branch() (string, error)

	// Commit returns the most recent Commit details for the working
	// copy. If the GitInfo instance was initialised for a path not within a
	// working copy, Commit will return nil. An error is returned if there is
	// a problem determining the commit details.
	Commit() (Commit, error)

	// Config returns the git configuration details for the working copy.
	// see https://github.com/denormal/go-gitconfig for more details.
	Config() gitconfig.GitConfig

	// Editor returns the git editor configured for working copy.
	Editor() string

	// Modified returns true if the working copy has been modified, either
	// through locally made changes, or untracked files. Modified returns an
	// error if a problem is encountered determining the modified state.
	Modified() (bool, error)

	// Path returns the absolute path used to initialised this GitInfo.
	Path() string

	// Root returns the root directory of the working copy. If the GitInfo
	// instance was initialised for a path not within a working copy, Root
	// returns the empty string.
	Root() string

	// User returns details of the git user for this working copy.
	User() User

	// Deprecated: Version returns the version string for the installed git
	// executable, or an error if this cannot be determined.
	//
	// Version is deprecated and will be removed in a future release. Please
	// use Git() for extracting the git executable version.
	Version() (string, error)

	// Git returns the version string for the installed git executable,
	// or an error if this cannot be determined.
	Git() (string, error)

	// Map returns the git information as a map of strings.
	Map() map[string]string
}

GitInfo represents basic information about a git working copy.

func Build

func Build(kv map[string]string) GitInfo

func Here

func Here() (GitInfo, error)

Here returns the GitInfo instance referencing the caller's location. If the caller cannot be determined, Here returns the UnknownCallerError.

func New

func New() (GitInfo, error)

New returns the GitInfo instance for the current process working directory, or an error if the directory cannot be resolved, or the git executable cannot be found.

func NewWithPath

func NewWithPath(path string) (GitInfo, error)

NewWithPath returns the GitInfo instance for the given path, or an error if the path cannot be resolved or the git executable cannot be found. If path is "", NewWithPath examines the current process working directory.

type User

type User interface {
	// Name returns the name of the current git user, or the empty string
	// if no name is configured.
	Name() string

	// Email returns the e-mail addrdd of the current git user, or the empty
	// string if no e-mail address is configured.
	Email() string

	// String() returns a string representation of the git user's name and
	// e-mail address, or the empty string if neither are defined.
	String() string
}

User is the interface representing the git user.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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