本文整理匯總了Golang中github.com/Unknwon/com.ExecCmdDir函數的典型用法代碼示例。如果您正苦於以下問題:Golang ExecCmdDir函數的具體用法?Golang ExecCmdDir怎麽用?Golang ExecCmdDir使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ExecCmdDir函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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))
}
示例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)
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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()
}
示例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
}