git

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2016 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ConfigKey = "salsaflow.core.git"
View Source
const DefaultRemoteName = "origin"
View Source
const GitConfigKeyRemote = "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.

In case the remote branch does not exist, *ErrRefNotFound is returned. In case the branch is not up to date, *ErrRefNotInSync is returned.

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 CreateTrackingBranch added in v0.19.0

func CreateTrackingBranch(branch, remote string) error

func DeleteTag

func DeleteTag(tag string) error

func EnsureBranchNotExist

func EnsureBranchNotExist(branch string, remote string) error

func EnsureBranchSynchronized

func EnsureBranchSynchronized(branch, remote string) (err error)

EnsureBranchSynchronized makes sure the given branch is up to date. If that is not the case, *ErrRefNoInSync is returned.

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 origin/trunk..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 Merge added in v0.18.0

func Merge(args ...string) error

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 RevisionsToCommitList added in v0.20.0

func RevisionsToCommitList(revisions ...string) ([]string, error)

RevisionsToCommitList uses git rev-list --no-walk to turn given list of revision specifications into a list of commits.

The list is passed to git rev-list --no-walk unchanges, so check the docs to understand the exact behaviour of this function.

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 SetBranch added in v0.16.0

func SetBranch(branch, targetRef string) 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 commit objects specified by the given revisions.

Revision ranges can be used as well, the revision list is simply passed to git show, so check the associated docs.

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 struct {
	LocalConfig
	RemoteName string
}

Config holds the complete Git-related config needed by SalsaFlow.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig can be used to load Git-related configuration for SalsaFlow.

type ErrDirtyFile

type ErrDirtyFile struct {
	RelativePath string
}

func (*ErrDirtyFile) Error

func (err *ErrDirtyFile) Error() string

type ErrRefNotFound added in v0.9.0

type ErrRefNotFound struct {
	Ref string
}

func (*ErrRefNotFound) Error added in v0.9.0

func (err *ErrRefNotFound) Error() string

type ErrRefNotInSync added in v0.11.0

type ErrRefNotInSync struct {
	Ref string
}

func (*ErrRefNotInSync) Error added in v0.11.0

func (err *ErrRefNotInSync) Error() string

type GitBranch added in v0.13.0

type GitBranch struct {
	// Local branch name
	BranchName string

	// Name of the remote branch being tracked
	RemoteBranchName string

	// Name of remote the remote branch is associated with
	Remote string
}

Branch represents a Git branch.

func Branches added in v0.13.0

func Branches() ([]*GitBranch, error)

func (*GitBranch) CanonicalName added in v0.13.0

func (branch *GitBranch) CanonicalName() string

CanonicalName returns

"{{.BranchName}}" in case it is not empty, and
"{{.Remote}}/{{.RemoteBranchName}}" otherwise.

func (*GitBranch) FullRemoteBranchName added in v0.13.0

func (branch *GitBranch) FullRemoteBranchName() string

FullRemoteName returns "{{.Remote}}/{{.RemoteBranchName}}".

func (*GitBranch) IsUpToDate added in v0.13.0

func (branch *GitBranch) IsUpToDate() (bool, error)

IsUpToDate returns true when the local and remote references point to the same commit.

func (*GitBranch) LocalRef added in v0.13.0

func (branch *GitBranch) LocalRef() string

LocalRef returns "refs/heads/{{.BranchName}}".

func (*GitBranch) RemoteRef added in v0.13.0

func (branch *GitBranch) RemoteRef() string

RemoteRef returns "refs/remotes/{{.Remote}}/{{.RemoteBranchName}}".

type LocalConfig

type LocalConfig struct {
	TrunkBranchName   string `prompt:"trunk branch name"   default:"develop" json:"trunk_branch"`
	ReleaseBranchName string `prompt:"release branch name" default:"release" json:"release_branch"`
	StagingBranchName string `prompt:"staging branch name" default:"stage"   json:"staging_branch"`
	StableBranchName  string `prompt:"stable branch name"  default:"master"  json:"stable_branch"`
}

LocalConfig implements loader.ConfigContainer interface.

func (*LocalConfig) PromptUserForConfig added in v0.16.0

func (local *LocalConfig) PromptUserForConfig() error

PromptUserForConfig is a part of loader.ConfigContainer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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