git

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2015 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultRemoteName = "origin"

	DefaultTrunkBranchName   = "develop"
	DefaultReleaseBranchName = "release"
	DefaultStageBranchName   = "stage"
	DefaultStableBranchName  = "master"
)
View Source
const ConfigKeyRemote = "salsaflow.remote"
View Source
const StoryIdUnassignedTagValue = "unassigned"
View Source
const ZeroHash = "0000000000000000000000000000000000000000"

Variables

View Source
var (
	ChangeIdTagPattern = regexp.MustCompile("^(?i)[ \t]*Change-Id:[ \t]+([^ \t]+)")
	StoryIdTagPattern  = regexp.MustCompile("^(?i)[ \t]*Story-Id:[ \t]+([^ \t]+)")
)
View Source
var ErrDirtyRepository = errors.New("the repository is dirty")

Functions

func Add

func Add(args ...string) error

func Branch

func Branch(args ...string) error

func BranchHexsha added in v0.7.0

func BranchHexsha(branch string) (hexsha string, err error)

func CheckOrCreateTrackingBranch added in v0.9.0

func CheckOrCreateTrackingBranch(branch, remote string) error

CheckOrCreateTrackingBranch tries to make sure that a local branch of the given name exists and is in sync with the given remote.

So, in case the right remote branch exists and the local does not, the local tracking branch is created. In case the local branch exists already, it is ensured that it is up to date.

func Checkout

func Checkout(args ...string) error

func CherryPick

func CherryPick(args ...string) error

func CoreBranchHashes added in v0.7.0

func CoreBranchHashes() (map[string]string, error)

CoreBranchHashes returns a map containing all core branches with their hashes, i.e. map[branchName]commitHash.

func CreateOrResetBranch

func CreateOrResetBranch(branch, target string) (action.Action, error)

func CurrentBranch

func CurrentBranch() (branch string, err error)

func DeleteTag

func DeleteTag(tag string) error

func EnsureBranchNotExist

func EnsureBranchNotExist(branch string, remote string) error

func EnsureBranchSynchronized

func EnsureBranchSynchronized(branch, remote string) error

func EnsureCleanWorkingTree

func EnsureCleanWorkingTree(includeUntracked bool) error

func EnsureFileClean

func EnsureFileClean(relativePath string) error

func FixCommitSources

func FixCommitSources(commits []*Commit) error

FixCommitSources can be used to set the Source field for the given commits to the right value in respect to the branching model.

We need this function becase using git log --all --source actually does not always yield the source values we want. It can set the source for the commits on the trunk branch and on the release branch to one of the feature branches that are branched off the given branch. That is not what we want, we want to have the Source field set to the trunk branch or the release branch in case the commit is reachable from one of these branches.

More precisely, the Source field is set in the following way:

commits on trunk                   -> refs/heads/trunk
commits on trunk..origin/trunk     -> refs/remotes/origin/trunk
commits on trunk..release          -> refs/heads/release
commits on release..origin/release -> refs/remotes/origin/release

func GetConfigString

func GetConfigString(key string) (value string, err error)

func Hexsha

func Hexsha(ref string) (hexsha string, err error)

func IsBranchSynchronized added in v0.7.0

func IsBranchSynchronized(branch, remote string) (bool, error)

IsBranchSynchronized returns true when the branch of the given name is up to date with the given remote. In case the branch does not exist in the remote repository, true is returned as well.

func IsCoreBranch added in v0.7.0

func IsCoreBranch(branch string) (bool, error)

func LocalBranchExists

func LocalBranchExists(branch string) (exists bool, err error)

func Log

func Log(args ...string) (stdout *bytes.Buffer, err error)

func ParseUpstreamURL added in v0.10.0

func ParseUpstreamURL() (owner, repo string, err error)

ParseUpstreamURL parses the URL of the git upstream being used by SalsaFlow and returns the given GitHub owner and repository.

func Push

func Push(remote string, args ...string) error

func PushForce

func PushForce(remote string, args ...string) error

func Rebase

func Rebase(args ...string) error

func RefExists

func RefExists(ref string) (exists bool, err error)

func RefExistsStrict

func RefExistsStrict(ref string) (exists bool, err error)

RefExistsStrict requires the whole ref path to be specified, e.g. refs/remotes/origin/master.

func RemoteBranchExists

func RemoteBranchExists(branch string, remote string) (exists bool, err error)

func Reset

func Reset(args ...string) error

func ResetKeep

func ResetKeep(branch, ref string) (err error)

func Run

func Run(args ...string) (stdout *bytes.Buffer, err error)

func RunCommand

func RunCommand(command string, args ...string) (stdout *bytes.Buffer, err error)

func SetConfigString

func SetConfigString(key string, value string) error

func Status

func Status(args ...string) (stdout *bytes.Buffer, err error)

func Tag

func Tag(args ...string) error

func UpdateRemotes

func UpdateRemotes(remotes ...string) error

Types

type Commit

type Commit struct {
	SHA          string
	Source       string
	Merge        string
	Author       string
	AuthorDate   time.Time
	Committer    string
	CommitDate   time.Time
	MessageTitle string
	Message      string
	ChangeIdTag  string
	StoryIdTag   string
}

func FilterCommits added in v0.9.0

func FilterCommits(commits []*Commit, filterFunc CommitFilterFunc) []*Commit

FilterCommits can be used to filter commits by the given filter function.

func GrepCommitsCaseInsensitive

func GrepCommitsCaseInsensitive(filter string, args ...string) ([]*Commit, error)

func ParseCommits

func ParseCommits(input []byte) (commits []*Commit, err error)

Parse git log output, which is a sequence of Git commits looking like

commit $hexsha $source Author: $author Date: $date

$title

$body

Change-Id: $changeId
Story-Id: $storyId

The reason why we are parsing the regular output (not using --pretty=format:) is that not all formatting options are supported. For example, log --all --source contains some information that cannot be easily taken by using --pretty=format:

func ShowCommitRange

func ShowCommitRange(revisionRange string) ([]*Commit, error)

ShowCommitRange returns the list of commits specified by the given Git revision range.

func ShowCommits

func ShowCommits(revisions ...string) ([]*Commit, error)

ShowCommits returns the list of commits associated with the given revisions.

func (*Commit) Dump

func (commit *Commit) Dump(wr io.Writer) error

Dump writes a human-friendly representation of the commit to the writer. The output closely resembles the output of git log.

type CommitFilterFunc added in v0.9.0

type CommitFilterFunc func(*Commit) bool

type Config

type Config interface {
	RemoteName() string
	TrunkBranchName() string
	ReleaseBranchName() string
	StagingBranchName() string
	StableBranchName() string
}

func LoadConfig

func LoadConfig() (Config, error)

type ErrDirtyFile

type ErrDirtyFile struct {
	// contains filtered or unexported fields
}

func (*ErrDirtyFile) Error

func (err *ErrDirtyFile) Error() string

type ErrRefNotFound added in v0.9.0

type ErrRefNotFound struct {
	// contains filtered or unexported fields
}

func (*ErrRefNotFound) Error added in v0.9.0

func (err *ErrRefNotFound) Error() string

func (*ErrRefNotFound) Ref added in v0.9.0

func (err *ErrRefNotFound) Ref() string

type LocalConfig

type LocalConfig struct {
	Git struct {
		Branches struct {
			Trunk   string `yaml:"trunk"`
			Release string `yaml:"release"`
			Stage   string `yaml:"stage"`
			Stable  string `yaml:"stable"`
		} `yaml:"branches"`
	} `yaml:"git"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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