本文整理汇总了Golang中github.com/Unknwon/com.ExecCmdDir函数的典型用法代码示例。如果您正苦于以下问题:Golang ExecCmdDir函数的具体用法?Golang ExecCmdDir怎么用?Golang ExecCmdDir使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ExecCmdDir函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: initRepoCommit
// initRepoCommit temporarily changes with work directory.
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
var stderr string
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
return err
}
if len(stderr) > 0 {
log.Trace("stderr(1): %s", stderr)
}
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
"-m", "Init commit"); err != nil {
return err
}
if len(stderr) > 0 {
log.Trace("stderr(2): %s", stderr)
}
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
return err
}
if len(stderr) > 0 {
log.Trace("stderr(3): %s", stderr)
}
return nil
}
开发者ID:JREAMLU,项目名称:gogs,代码行数:26,代码来源:repo.go
示例2: initRepoCommit
// initRepoCommit temporarily changes with work directory.
func initRepoCommit(tmpPath string, sig *git.Signature) (err error) {
var stderr string
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "add", "--all"); err != nil {
return errors.New("git add: " + stderr)
}
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "commit", fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email),
"-m", "Init commit"); err != nil {
return errors.New("git commit: " + stderr)
}
if _, stderr, err = com.ExecCmdDir(tmpPath, "git", "push", "origin", "master"); err != nil {
return errors.New("git push: " + stderr)
}
return nil
}
开发者ID:kristofer,项目名称:gogs,代码行数:16,代码来源:repo.go
示例3: getCommitIdOfRef
func (repo *Repository) getCommitIdOfRef(refpath string) (string, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "show-ref", "--verify", refpath)
if err != nil {
return "", errors.New(stderr)
}
return strings.Split(stdout, " ")[0], nil
}
开发者ID:noikiy,项目名称:gitea,代码行数:7,代码来源:repo_commit.go
示例4: CreateTag
func (repo *Repository) CreateTag(tagName, idStr string) error {
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", tagName, idStr)
if err != nil {
return errors.New(stderr)
}
return nil
}
开发者ID:noikiy,项目名称:gogs,代码行数:7,代码来源:repo_tag.go
示例5: RemoveRemote
// RemoveRemote removes a remote from repository.
func (repo *Repository) RemoveRemote(name string) error {
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "remove", name)
if err != nil {
return fmt.Errorf("remove remote(%s): %v", name, concatenateError(err, stderr))
}
return nil
}
开发者ID:hopehook,项目名称:gogs,代码行数:8,代码来源:repo_pull.go
示例6: AddRemote
// AddRemote adds a remote to repository.
func (repo *Repository) AddRemote(name, path string) error {
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "add", "-f", name, path)
if err != nil {
return fmt.Errorf("add remote(%s - %s): %v", name, path, concatenateError(err, stderr))
}
return nil
}
开发者ID:hopehook,项目名称:gogs,代码行数:8,代码来源:repo_pull.go
示例7: CreateRelease
// CreateRelease creates a new release of repository.
func CreateRelease(gitRepo *git.Repository, rel *Release) error {
isExist, err := IsReleaseExist(rel.RepoId, rel.TagName)
if err != nil {
return err
} else if isExist {
return ErrReleaseAlreadyExist
}
if !gitRepo.IsTagExist(rel.TagName) {
_, stderr, err := com.ExecCmdDir(gitRepo.Path, "git", "tag", rel.TagName, "-m", rel.Title)
if err != nil {
return errors.New(stderr)
}
} else {
commit, err := gitRepo.GetCommitOfTag(rel.TagName)
if err != nil {
return err
}
rel.NumCommits, err = commit.CommitsCount()
if err != nil {
return err
}
}
rel.LowerTagName = strings.ToLower(rel.TagName)
_, err = orm.InsertOne(rel)
return err
}
开发者ID:hilerchyn,项目名称:gogs,代码行数:30,代码来源:release.go
示例8: commitsCount
func (repo *Repository) commitsCount(id sha1) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count", id.String())
if err != nil {
return 0, errors.New(stderr)
}
return StrToInt(strings.TrimSpace(stdout))
}
开发者ID:frank3nst3in,项目名称:git,代码行数:7,代码来源:repo_commit.go
示例9: MigrateRepository
// MigrateRepository migrates a existing repository from other project hosting.
func MigrateRepository(user *User, name, desc string, private, mirror bool, url string) (*Repository, error) {
repo, err := CreateRepository(user, name, desc, "", "", private, mirror, false)
if err != nil {
return nil, err
}
// Clone to temprory path and do the init commit.
tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()))
os.MkdirAll(tmpDir, os.ModePerm)
repoPath := RepoPath(user.Name, name)
repo.IsBare = false
if mirror {
if err = MirrorRepository(repo.Id, user.Name, repo.Name, repoPath, url); err != nil {
return repo, err
}
repo.IsMirror = true
return repo, UpdateRepository(repo)
}
// Clone from local repository.
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
if err != nil {
return repo, err
} else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git clone: " + stderr)
}
// Pull data from source.
_, stderr, err = com.ExecCmdDir(tmpDir, "git", "pull", url)
if err != nil {
return repo, err
} else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git pull: " + stderr)
}
// Push data to local repository.
if _, stderr, err = com.ExecCmdDir(tmpDir, "git", "push", "origin", "master"); err != nil {
return repo, err
} else if strings.Contains(stderr, "fatal:") {
return repo, errors.New("git push: " + stderr)
}
return repo, UpdateRepository(repo)
}
开发者ID:kennylixi,项目名称:gogs,代码行数:47,代码来源:repo.go
示例10: GetMergeBase
// GetMergeBase checks and returns merge base of two branches.
func (repo *Repository) GetMergeBase(remoteBranch, headBranch string) (string, error) {
// Get merge base commit.
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "merge-base", remoteBranch, headBranch)
if err != nil {
return "", fmt.Errorf("get merge base: %v", concatenateError(err, stderr))
}
return strings.TrimSpace(stdout), nil
}
开发者ID:hopehook,项目名称:gogs,代码行数:9,代码来源:repo_pull.go
示例11: GetTags
// GetTags returns all tags of given repository.
func (repo *Repository) GetTags() ([]string, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l")
if err != nil {
return nil, errors.New(stderr)
}
tags := strings.Split(stdout, "\n")
return tags[:len(tags)-1], nil
}
开发者ID:felipelovato,项目名称:gogs,代码行数:9,代码来源:repo_tag.go
示例12: FilesCountBetween
func (repo *Repository) FilesCountBetween(startCommitID, endCommitID string) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "diff", "--name-only",
startCommitID+"..."+endCommitID)
if err != nil {
return 0, fmt.Errorf("list changed files: %v", concatenateError(err, stderr))
}
return len(strings.Split(stdout, "\n")) - 1, nil
}
开发者ID:Janfred,项目名称:gogs,代码行数:8,代码来源:repo_commit.go
示例13: getTagsReversed
func (repo *Repository) getTagsReversed() ([]string, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l", "--sort=-v:refname")
if err != nil {
return nil, concatenateError(err, stderr)
}
tags := strings.Split(stdout, "\n")
return tags[:len(tags)-1], nil
}
开发者ID:noikiy,项目名称:gogs,代码行数:8,代码来源:repo_tag.go
示例14: FileCommitsCount
func (repo *Repository) FileCommitsCount(branch, file string) (int, error) {
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "rev-list", "--count",
branch, "--", file)
if err != nil {
return 0, errors.New(stderr)
}
return com.StrTo(strings.TrimSpace(stdout)).Int()
}
开发者ID:noikiy,项目名称:gitea,代码行数:8,代码来源:repo_commit.go
示例15: LocalLastCommitDate
// Get last commit date from local repository
func (g *githubPackage) LocalLastCommitDate() (time.Time, error) {
stdout, _, _ := com.ExecCmdDir(g.Dir(), "git", "log", "-1", "--date=rfc2822", "--pretty=format:%cd")
layout := "Mon, _2 Jan 2006 15:04:05 -0700"
t, err := time.Parse(layout, stdout)
if err != nil {
return time.Time{}, errors.New("Error parse local time")
}
return t.UTC(), nil
}
开发者ID:firstrow,项目名称:go-outdated,代码行数:10,代码来源:main.go
示例16: getTree
func (repo *Repository) getTree(id sha1) (*Tree, error) {
treePath := filepathFromSHA1(repo.Path, id.String())
if !com.IsFile(treePath) {
_, _, err := com.ExecCmdDir(repo.Path, "git", "ls-tree", id.String())
if err != nil {
return nil, fmt.Errorf("repo.getTree: %v", ErrNotExist)
}
}
return NewTree(repo, id), nil
}
开发者ID:hogehoge999,项目名称:gogs,代码行数:11,代码来源:repo_tree.go
示例17: GetTags
// GetTags returns all tags of given repository.
func (repo *Repository) GetTags() ([]string, error) {
if gitVer.AtLeast(MustParseVersion("2.0.0")) {
return repo.getTagsReversed()
}
stdout, stderr, err := com.ExecCmdDir(repo.Path, "git", "tag", "-l")
if err != nil {
return nil, concatenateError(err, stderr)
}
tags := strings.Split(stdout, "\n")
return tags[:len(tags)-1], nil
}
开发者ID:noikiy,项目名称:gogs,代码行数:12,代码来源:repo_tag.go
示例18: Do
// Git deployment action
func (g *GitTask) Do(b *builder.Builder, ctx *builder.Context) error {
gitDir := path.Join(ctx.DstDir, ".git")
if !com.IsDir(gitDir) {
return ErrGitNotRepo
}
var err error
if err = g.readRepo(ctx.DstDir); err != nil {
return err
}
if g.opt.Branch == "" {
return ErrGitNoBranch
}
// add files
if _, stderr, err := com.ExecCmdDir(ctx.DstDir, "git", []string{"add", "--all"}...); err != nil {
log15.Error("Deploy.Git.Error", "error", stderr)
return err
}
log15.Debug("Deploy.Git.[" + g.opt.Branch + "].AddFiles")
// commit message
message := gitMessageReplacer.Replace(g.opt.Message)
if _, stderr, err := com.ExecCmdDir(ctx.DstDir, "git", []string{"commit", "-m", message}...); err != nil {
log15.Error("Deploy.Git.Error", "error", stderr)
return err
}
log15.Debug("Deploy.Git.[" + g.opt.Branch + "].Commit.'" + message + "'")
// push to repo
_, stderr, err := com.ExecCmdDir(ctx.DstDir, "git", []string{
"push", "--force", "origin", g.opt.Branch}...)
if err != nil {
log15.Error("Deploy.Git.Error", "error", stderr)
if stderr != "" {
return errors.New(stderr)
}
return err
}
log15.Debug("Deploy.Git.[" + g.opt.Branch + "].Push")
return nil
}
开发者ID:cnhans,项目名称:pugo-static,代码行数:42,代码来源:git.go
示例19: GetPullRequestInfo
// GetPullRequestInfo generates and returns pull request information
// between base and head branches of repositories.
func (repo *Repository) GetPullRequestInfo(basePath, baseBranch, headBranch string) (*PullRequestInfo, error) {
// Add a temporary remote.
tmpRemote := com.ToStr(time.Now().UnixNano())
_, stderr, err := com.ExecCmdDir(repo.Path, "git", "remote", "add", "-f", tmpRemote, basePath)
if err != nil {
return nil, fmt.Errorf("add base as remote: %v", concatenateError(err, stderr))
}
defer func() {
com.ExecCmdDir(repo.Path, "git", "remote", "remove", tmpRemote)
}()
prInfo := new(PullRequestInfo)
var stdout string
remoteBranch := "remotes/" + tmpRemote + "/" + baseBranch
// Get merge base commit.
stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "merge-base", remoteBranch, headBranch)
if err != nil {
return nil, fmt.Errorf("get merge base: %v", concatenateError(err, stderr))
}
prInfo.MergeBase = strings.TrimSpace(stdout)
stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "log", remoteBranch+"..."+headBranch, prettyLogFormat)
if err != nil {
return nil, fmt.Errorf("list diff logs: %v", concatenateError(err, stderr))
}
prInfo.Commits, err = parsePrettyFormatLog(repo, []byte(stdout))
if err != nil {
return nil, fmt.Errorf("parsePrettyFormatLog: %v", err)
}
// Count number of changed files.
stdout, stderr, err = com.ExecCmdDir(repo.Path, "git", "diff", "--name-only", remoteBranch+"..."+headBranch)
if err != nil {
return nil, fmt.Errorf("list changed files: %v", concatenateError(err, stderr))
}
prInfo.NumFiles = len(strings.Split(stdout, "\n")) - 1
return prInfo, nil
}
开发者ID:GoNuuts,项目名称:gogs,代码行数:42,代码来源:repo_pull.go
示例20: getCommitOfRelPath
func (repo *Repository) getCommitOfRelPath(id sha1, relPath string) (*Commit, error) {
stdout, _, err := com.ExecCmdDir(repo.Path, "git", "log", "-1", prettyLogFormat, id.String(), "--", relPath)
if err != nil {
return nil, err
}
id, err = NewIdFromString(string(stdout))
if err != nil {
return nil, err
}
return repo.getCommit(id)
}
开发者ID:noikiy,项目名称:gitea,代码行数:13,代码来源:repo_commit.go
注:本文中的github.com/Unknwon/com.ExecCmdDir函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论