project

package
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package project implements operations on project and repository.

Index

Constants

View Source
const (
	// GIT is git command name
	GIT = config.GIT
)

Variables

This section is empty.

Functions

func IndexByName

func IndexByName(projects []*Project) map[string][]*Project

IndexByName returns a map using project name as index to group projects.

func IndexByPath

func IndexByPath(projects []*Project) map[string]*Project

IndexByPath returns a map using project path as index to group projects.

func IsClean

func IsClean(dir string) (bool, error)

IsClean indicates git worktree is clean.

func MatchGroups

func MatchGroups(match, groups string) bool

MatchGroups checks if project has matched groups.

Types

type Branch

type Branch struct {
	Name string
	Hash string
}

Branch wraps branch name and object ID.

func (Branch) ShortName

func (v Branch) ShortName() string

ShortName removes prefix "refs/heads/".

type CheckoutOptions

type CheckoutOptions struct {
	RepoSettings

	Quiet          bool
	DetachHead     bool
	IsManifest     bool
	CheckPublished bool
}

CheckoutOptions is options for git fetch.

type CmdExecResult

type CmdExecResult struct {
	Project *Project
	Out     []byte
	Error   error
}

CmdExecResult holds command output, and error.

func NewCmdExecResult

func NewCmdExecResult(p *Project) *CmdExecResult

NewCmdExecResult creates new instance of CmdExecResult.

func (*CmdExecResult) Empty

func (v *CmdExecResult) Empty() bool

Empty indicates output and error output is empty.

func (*CmdExecResult) Stderr

func (v *CmdExecResult) Stderr() string

Stderr is command output on stderr.

func (*CmdExecResult) Stdout

func (v *CmdExecResult) Stdout() string

Stdout is command output on stdout.

func (CmdExecResult) Success

func (v CmdExecResult) Success() bool

Success indicates command runs successfully or not.

type ConfigWithDefault

type ConfigWithDefault struct {
	Project *Project
}

ConfigWithDefault checks git config from both project and manifest project.

func (ConfigWithDefault) Get

func (v ConfigWithDefault) Get(key string) string

Get returns config of both project and manifest project.

func (ConfigWithDefault) GetBool

func (v ConfigWithDefault) GetBool(key string, defaultVal bool) bool

GetBool returns boolean config of both project and manifest project.

func (ConfigWithDefault) HasKey

func (v ConfigWithDefault) HasKey(key string) bool

HasKey checks whether key is set in both project and manifest project.

type FetchOptions

type FetchOptions struct {
	RepoSettings

	Quiet             bool
	IsNew             bool
	CurrentBranchOnly bool
	CloneBundle       bool
	ForceSync         bool
	NoTags            bool
	OptimizedFetch    bool
	Prune             bool
}

FetchOptions is options for git fetch.

type ManifestProject

type ManifestProject struct {
	Project
}

ManifestProject is a special type of project.

func NewManifestProject

func NewManifestProject(topDir, mURL string) *ManifestProject

NewManifestProject returns a manifest project: a worktree with a seperate repository.

func (ManifestProject) ArchiveEnabled

func (v ManifestProject) ArchiveEnabled() bool

ArchiveEnabled checks if config variable repo.archive is true.

func (ManifestProject) DissociateEnabled

func (v ManifestProject) DissociateEnabled() bool

DissociateEnabled checks if config variable repo.dissociate is true.

func (ManifestProject) MirrorEnabled

func (v ManifestProject) MirrorEnabled() bool

MirrorEnabled checks if config variable repo.mirror is true.

func (*ManifestProject) ReadSettings

func (v *ManifestProject) ReadSettings() *RepoSettings

ReadSettings reads settings from manifest project.

func (*ManifestProject) SaveSettings

func (v *ManifestProject) SaveSettings(s *RepoSettings) error

SaveSettings saves settings to manifest project.

func (*ManifestProject) SetRevision

func (v *ManifestProject) SetRevision(rev string)

SetRevision changes project default branch.

func (ManifestProject) SubmoduleEnabled

func (v ManifestProject) SubmoduleEnabled() bool

SubmoduleEnabled checks if config variable repo.submodules is true.

type PatchSet

type PatchSet struct {
	Reference string
	Commits   []string
	Commit    string
}

PatchSet contains code review reference and commits.

type Project

type Project struct {
	Repository

	WorkDir string
}

Project inherits manifest's Project and has two related repositories.

func Join

func Join(group1, group2 []*Project) []*Project

Join two group of projects, ignore duplicated projects.

func NewMirrorProject

func NewMirrorProject(mp *manifest.Project, s *RepoSettings, m *manifest.Manifest) *Project

NewMirrorProject returns a mirror project.

func NewProject

func NewProject(mp *manifest.Project, s *RepoSettings, m *manifest.Manifest) *Project

NewProject returns a project: project worktree with a bared repo and a seperate repository.

func (*Project) AddRemote

func (v *Project) AddRemote(mr *manifest.Remote, noCache bool) *Remote

AddRemote will add new Remote to project's Remotes.

func (Project) CheckoutRevision

func (v Project) CheckoutRevision(args ...string) error

CheckoutRevision runs git checkout.

func (Project) CherryPick

func (v Project) CherryPick(commits ...string) error

CherryPick runs cherry-pick on commits.

func (Project) CleanPublishedCache

func (v Project) CleanPublishedCache() error

CleanPublishedCache removes obsolete refs/published/ references.

func (*Project) ConfigWithDefault

func (v *Project) ConfigWithDefault() ConfigWithDefault

ConfigWithDefault returns git config file parser.

func (Project) CopyAndLinkFiles

func (v Project) CopyAndLinkFiles() error

CopyAndLinkFiles copies and links files.

func (Project) CopyFile

func (v Project) CopyFile(src, dest string) error

CopyFile copy files from src to dest.

func (Project) DetachHead

func (v Project) DetachHead() error

DetachHead makes detached HEAD.

func (Project) DownloadPatchSet

func (v Project) DownloadPatchSet(remoteName string, reviewID, patchID int) (*PatchSet, error)

DownloadPatchSet fetches code review and return the downloaded PatchSet.

func (Project) ExecuteCommand

func (v Project) ExecuteCommand(args ...string) *CmdExecResult

ExecuteCommand runs command.

func (Project) Exists

func (v Project) Exists() bool

Exists indicates whether project exists or not.

func (Project) FastForward

func (v Project) FastForward(args ...string) error

FastForward runs git merge

func (*Project) GetBranchRemote

func (v *Project) GetBranchRemote(branch string, useOrigin bool) *Remote

GetBranchRemote gets default remote for branch of the project.

func (*Project) GetDefaultRemote

func (v *Project) GetDefaultRemote(useOrigin bool) *Remote

GetDefaultRemote gets default remote for project.

func (*Project) GetRemotePushNameURL

func (v *Project) GetRemotePushNameURL(remote *Remote) (string, string)

GetRemotePushNameURL returns remote name and URL for push.

func (*Project) GetRemotePushURL

func (v *Project) GetRemotePushURL(remote *Remote) string

GetRemotePushURL returns URL for push.

func (*Project) GetRemoteURL

func (v *Project) GetRemoteURL() (string, error)

GetRemoteURL returns new remote url user provided or from manifest repo url

func (Project) GetSubmoduleProjects

func (v Project) GetSubmoduleProjects() []*Project

GetSubmoduleProjects returns submodule projects.

func (*Project) GetUploadableBranch

func (v *Project) GetUploadableBranch(branch string, remote *Remote, remoteBranch string) *ReviewableBranch

GetUploadableBranch returns branch which has commits ready for upload.

func (*Project) GetUploadableBranchForChange

func (v *Project) GetUploadableBranchForChange(branch string, remote *Remote, codeReview *config.CodeReview) *ReviewableBranch

GetUploadableBranchForChange returns branch which has commits ready for upload.

func (*Project) GetUploadableBranches

func (v *Project) GetUploadableBranches(branch string) []ReviewableBranch

GetUploadableBranches returns branches which has commits ready for upload.

func (*Project) GitInit

func (v *Project) GitInit() error

GitInit starts to init repositories.

func (*Project) GitRepository

func (v *Project) GitRepository() (*git.Repository, error)

GitRepository returns go-git's repository object for project worktree.

func (*Project) GitWorktree

func (v *Project) GitWorktree() (*git.Worktree, error)

GitWorktree returns go-git's worktree oject.

func (Project) HardReset

func (v Project) HardReset(args ...string) error

HardReset runs git reset --hard.

func (*Project) HeadBranch

func (v *Project) HeadBranch() Branch

HeadBranch returns current branch (name and oid) of project's workdir.

func (Project) InstallGerritHooks

func (v Project) InstallGerritHooks() error

InstallGerritHooks installs gerrit hooks if remote of current project is gerrit.

func (Project) IsClean

func (v Project) IsClean() bool

IsClean indicates git worktree is clean. TODO: cannot use go-git, because it is incompatible with git new index format.

func (Project) IsMirror

func (v Project) IsMirror() bool

IsMirror indicates project is a mirror repository, no checkout

func (Project) IsRepoInitialized

func (v Project) IsRepoInitialized() bool

IsRepoInitialized indicates repository is initialized or not.

func (Project) LinkFile

func (v Project) LinkFile(src, dest string) error

LinkFile copy files from src to dest.

func (*Project) LoadRemotes

func (v *Project) LoadRemotes(remoteMap *RemoteMap, noCache bool)

LoadRemotes reads git config to load remotes.

func (*Project) ManifestConfig

func (v *Project) ManifestConfig() goconfig.GitConfig

ManifestConfig returns git config of manifest project.

func (Project) ManifestURL

func (v Project) ManifestURL() string

ManifestURL returns manifest URL.

func (Project) MatchGroups

func (v Project) MatchGroups(expect string) bool

MatchGroups indecates if project belongs to special groups.

func (*Project) PrepareWorkdir

func (v *Project) PrepareWorkdir() error

PrepareWorkdir setup workdir layout: .git is gitdir file points to repository.

func (Project) PublishedReference

func (v Project) PublishedReference(branch string) string

PublishedReference forms published reference for specific branch.

func (Project) PublishedRevision

func (v Project) PublishedRevision(branch string) string

PublishedRevision resolves published reference to revision id.

func (Project) Rebase

func (v Project) Rebase(args ...string) error

Rebase runs git rebase.

func (Project) RemoteTracking

func (v Project) RemoteTracking(rev string) string

RemoteTracking returns name of current remote tracking branch.

func (Project) ResolveRemoteTracking

func (v Project) ResolveRemoteTracking(rev string) (string, error)

ResolveRemoteTracking returns revision id of current remote tracking branch.

func (Project) ResolveRevision

func (v Project) ResolveRevision(rev string) (string, error)

ResolveRevision checks and resolves reference to revid.

func (Project) Revert

func (v Project) Revert(commit string) error

Revert runs revert on commit.

func (*Project) SetGitRemoteURL

func (v *Project) SetGitRemoteURL(remoteURL string) error

SetGitRemoteURL sets remote.<remote>.url setting in git config.

func (*Project) SetManifestURL

func (v *Project) SetManifestURL(manifestURL string) error

SetManifestURL sets manifestURL and change remote url if is MetaProject.

func (Project) StartBranch

func (v Project) StartBranch(branch, track string, force bool) error

StartBranch creates new branch.

func (Project) Status

func (v Project) Status() *CmdExecResult

Status shows combined output of git status for project.

func (Project) SubmoduleUpdate

func (v Project) SubmoduleUpdate(args ...string) error

SubmoduleUpdate runs git submodule update.

func (Project) SyncLocalHalf

func (v Project) SyncLocalHalf(o *CheckoutOptions) error

SyncLocalHalf will checkout/rebase branch.

func (*Project) SyncNetworkHalf

func (v *Project) SyncNetworkHalf(o *FetchOptions) error

SyncNetworkHalf starts to fetch from remote repository.

func (Project) TopDir

func (v Project) TopDir() string

TopDir returns root dir of repo workspace.

func (Project) UpdateBranchTracking

func (v Project) UpdateBranchTracking(branch, remote, track string)

UpdateBranchTracking updates branch tracking info.

func (Project) UserEmail

func (v Project) UserEmail() string

UserEmail returns user identity.

type Reference

type Reference struct {
	Name string
	Hash string
}

Reference wraps reference name and object ID.

type Remote

type Remote struct {
	manifest.Remote
	helper.ProtoHelper
	// contains filtered or unexported fields
}

Remote wraps manifest remote.

func NewRemote

func NewRemote(r *manifest.Remote, h helper.ProtoHelper) *Remote

NewRemote return new remote object.

func (*Remote) Initialized

func (v *Remote) Initialized() bool

Initialized indicates whether Remote is initialized.

func (*Remote) ProtoHelperReady

func (v *Remote) ProtoHelperReady() bool

ProtoHelperReady indicates ProtoHelper is ready for remote.

type RemoteMap

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

RemoteMap holds all remotes of a project.

func NewRemoteMap

func NewRemoteMap() *RemoteMap

NewRemoteMap returns new RemoteMap object.

func (*RemoteMap) Add

func (v *RemoteMap) Add(remote *Remote) *Remote

Add will add Remote to map.

func (*RemoteMap) Default

func (v *RemoteMap) Default(useOrigin bool) *Remote

Default gets default remote.

func (*RemoteMap) Get

func (v *RemoteMap) Get(name string) *Remote

Get returns Remote with matched name.

func (*RemoteMap) SetDefault

func (v *RemoteMap) SetDefault(name string)

SetDefault sets default remote name.

type RemoteTrack

type RemoteTrack struct {
	Remote string
	Branch string
	Track  Reference
}

RemoteTrack holds info of remote tracking branch

type RepoSettings

type RepoSettings struct {
	TopDir       string
	ManifestURL  string
	ManifestName string
	Groups       string
	Reference    string
	Revision     string
	Depth        int
	Archive      bool
	Dissociate   bool
	Mirror       bool
	Submodules   bool
	Config       goconfig.GitConfig
}

RepoSettings holds settings in manifest project.

type Repository

type Repository struct {
	manifest.Project

	DotGit        string // Path to worktree/.git
	GitDir        string // Project's bare repository inside .repo
	ObjectsGitDir string // Several projects may share the same repository

	// If project.Revision is a tag or sha, save manifest.DefaultRevision here
	ManifestDefaultRevision string

	IsBare    bool
	RemoteURL string
	Remotes   *RemoteMap
	Reference string // Alternate repository
	Settings  *RepoSettings
	// contains filtered or unexported fields
}

Repository has repository related operations.

func (Repository) CommonDir

func (v Repository) CommonDir() string

CommonDir returns commondir of a repository.

func (Repository) Config

func (v Repository) Config() goconfig.GitConfig

Config returns git config file parser.

func (Repository) DefaultTrackingBranch added in v0.7.7

func (v Repository) DefaultTrackingBranch() string

DefaultTrackingBranch is defined in Manifest file, and is used as default tracking branch for current project

func (Repository) DeleteBranch

func (v Repository) DeleteBranch(branch string) error

DeleteBranch deletes a branch.

func (Repository) Exists

func (v Repository) Exists() bool

Exists checks repository layout.

func (*Repository) Fetch

func (v *Repository) Fetch(remote string, o *FetchOptions) error

Fetch runs git-fetch on repository.

func (Repository) GetHead

func (v Repository) GetHead() string

GetHead returns current branch name

func (Repository) GitConfigRemoteURL

func (v Repository) GitConfigRemoteURL(name string) string

GitConfigRemoteURL returns remote url in git config.

func (Repository) HasAlternates

func (v Repository) HasAlternates() bool

HasAlternates checks if repository has defined alternates.

func (Repository) Heads

func (v Repository) Heads() []Branch

Heads returns branches of repository.

func (*Repository) Init

func (v *Repository) Init(remoteName, remoteURL, referenceGitDir string) error

Init runs git-init on repository.

func (v *Repository) InitByLink(remoteName, remoteURL string, repo *Repository) error

InitByLink starts to init repository by attaching other repository.

func (Repository) IsRebaseInProgress

func (v Repository) IsRebaseInProgress() bool

IsRebaseInProgress checks whether is in middle of a rebase.

func (Repository) LastModified

func (v Repository) LastModified(revision string) string

LastModified gets last modified time of a revision

func (Repository) LocalTrackBranch

func (v Repository) LocalTrackBranch(branch string) string

LocalTrackBranch gets local tracking remote branch

func (Repository) ObjectsRepository

func (v Repository) ObjectsRepository() *Repository

ObjectsRepository returns repository which ObjectsGitDir points to

func (Repository) Prompt

func (v Repository) Prompt() string

Prompt will show project path as prompt.

func (Repository) Raw

func (v Repository) Raw() *git.Repository

Raw returns go-git repository object.

func (Repository) RemoteMatchingBranch

func (v Repository) RemoteMatchingBranch(remote, branch string) string

RemoteMatchingBranch gets local tracking branch name of a match remote branch

func (Repository) RepoDir

func (v Repository) RepoDir() string

RepoDir returns git dir of the repository

func (Repository) RevisionIsValid

func (v Repository) RevisionIsValid(revision string) bool

RevisionIsValid returns true if revision can be resolved

func (Repository) Revlist

func (v Repository) Revlist(args ...string) ([]string, error)

Revlist works like rev-list. TODO: Hack go-git plumbing/revlist package to replace git exec

func (Repository) SSHInfoCacheFile

func (v Repository) SSHInfoCacheFile() string

SSHInfoCacheFile is filename used to cache proto settings.

func (*Repository) SaveConfig

func (v *Repository) SaveConfig(cfg goconfig.GitConfig) error

SaveConfig will save config to git config file.

func (Repository) TrackBranch

func (v Repository) TrackBranch(branch string) string

TrackBranch gets remote tracking branch.

func (Repository) TrackRemote

func (v Repository) TrackRemote(branch string) string

TrackRemote gets the remote name what current branch is tracking.

func (Repository) UpdateRef

func (v Repository) UpdateRef(refname, base, reason string) error

UpdateRef creates new reference.

type ReviewableBranch

type ReviewableBranch struct {
	Project     *Project
	Branch      Branch
	DestBranch  string
	RemoteTrack RemoteTrack
	Uploaded    bool
	Error       error
	CodeReview  config.CodeReview // Push to update specific code review, only available for single repository mode.
	Remote      *Remote
	// contains filtered or unexported fields
}

ReviewableBranch holds branch of project ready for upload.

func (ReviewableBranch) AppendReviewers

func (v ReviewableBranch) AppendReviewers(people [][]string)

AppendReviewers adds reviewers to people.

func (ReviewableBranch) Commits

func (v ReviewableBranch) Commits() []string

Commits contains commits avaiable for review.

func (*ReviewableBranch) IsPublished

func (v *ReviewableBranch) IsPublished() bool

IsPublished indicates a branch has been published.

func (*ReviewableBranch) Published

func (v *ReviewableBranch) Published() *Reference

Published returns published reference.

func (ReviewableBranch) UploadForReview

func (v ReviewableBranch) UploadForReview(o *config.UploadOptions) error

UploadForReview sends review for branch.

type Tree

type Tree struct {
	Path    string
	Project *Project
	Trees   []*Tree
}

Tree is used to group projects by path

func ProjectsTree

func ProjectsTree(projects []*Project) *Tree

ProjectsTree returns a map using project path as index to group projects.

Jump to

Keyboard shortcuts

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