示例#1
0
文件: git.go 项目: jingweno/gh
func Spawn(command string, args ...string) error {
	cmd := cmd.New("git")
	cmd.WithArg(command)
	for _, a := range args {
		cmd.WithArg(a)
	}

	return cmd.Exec()
}
示例#2
0
文件: git.go 项目: jingweno/gh
func Show(sha string) (string, error) {
	cmd := cmd.New("git")
	cmd.WithArg("show").WithArg("-s").WithArg("--format=%w(78,0,0)%s%n%+b").WithArg(sha)

	output, err := cmd.ExecOutput()
	output = strings.TrimSpace(output)

	return output, err
}
示例#3
0
文件: editor.go 项目: jingweno/gh
func doTextEditorEdit(program, file string) error {
	editCmd := cmd.New(program)
	r := regexp.MustCompile("[mg]?vi[m]$")
	if r.MatchString(program) {
		editCmd.WithArg("-c")
		editCmd.WithArg("set ft=gitcommit tw=0 wrap lbr")
	}
	editCmd.WithArg(file)

	return editCmd.Exec()
}
示例#4
0
func editTitleAndBody(editorPath, messageFile string) error {
	editCmd := cmd.New(editorPath)
	r := regexp.MustCompile("[mg]?vi[m]$")
	if r.MatchString(editorPath) {
		editCmd.WithArg("-c")
		editCmd.WithArg("set ft=gitcommit tw=0 wrap lbr")
	}
	editCmd.WithArg(messageFile)

	return editCmd.Exec()
}
示例#5
0
文件: git.go 项目: rif/golang-stuff
func execGitCmd(input ...string) (outputs []string, err error) {
	cmd := cmd.New("git")
	for _, i := range input {
		cmd.WithArg(i)
	}

	out, err := cmd.ExecOutput()
	for _, line := range strings.Split(out, "\n") {
		outputs = append(outputs, string(line))
	}

	return outputs, err
}
示例#6
0
文件: git.go 项目: rif/golang-stuff
func Spawn(command string, args ...string) error {
	cmd := cmd.New("git")
	cmd.WithArg(command)
	for _, a := range args {
		cmd.WithArg(a)
	}

	out, err := cmd.ExecOutput()
	if err != nil {
		return errors.New(out)
	}

	return nil
}
示例#7
0
文件: git.go 项目: prsimp/gh
func Log(sha1, sha2 string) (string, error) {
	execCmd := cmd.New("git")
	execCmd.WithArg("log").WithArg("--no-color")
	execCmd.WithArg("--format=%h (%aN, %ar)%n%w(78,3,3)%s%n%+b")
	execCmd.WithArg("--cherry")
	shaRange := fmt.Sprintf("%s...%s", sha1, sha2)
	execCmd.WithArg(shaRange)

	outputs, err := execCmd.ExecOutput()
	if err != nil {
		return "", errors.New("Can't load git log " + sha1 + ".." + sha2)
	}

	return outputs, nil
}
示例#8
0
文件: args.go 项目: jingweno/gh
func (a *Args) ToCmd() *cmd.Cmd {
	return cmd.New(a.Executable).WithArg(a.Command).WithArgs(a.Params...)
}