Example #1
0
func (r *TestRepo) AddRemote(name, url, pushURL string) {
	add := cmd.New("git").WithArgs("remote", "add", name, url)
	if _, err := add.CombinedOutput(); err != nil {
		panic(err)
	}
	if pushURL != "" {
		set := cmd.New("git").WithArgs("remote", "set-url", "--push", name, pushURL)
		if _, err := set.CombinedOutput(); err != nil {
			panic(err)
		}
	}
}
Example #2
0
File: help.go Project: d2s/hub
func runHelp(helpCmd *Command, args *Args) {
	if args.IsParamsEmpty() {
		printUsage()
		os.Exit(0)
	}

	command := args.FirstParam()

	if command == "hub" {
		man := cmd.New("man")
		man.WithArg("hub")
		err := man.Run()
		if err == nil {
			os.Exit(0)
		} else {
			os.Exit(1)
		}
	}

	c := CmdRunner.Lookup(command)
	if c != nil && !c.GitExtension {
		c.PrintUsage()
		os.Exit(0)
	} else if c == nil {
		if args.HasFlags("-a", "--all") {
			args.After("echo", "\nhub custom commands\n")
			args.After("echo", " ", strings.Join(customCommands(), "  "))
		}
	}
}
Example #3
0
File: help.go Project: pcorpet/hub
func displayManPage(manPage string, args *Args) error {
	manProgram, _ := utils.CommandPath("man")
	if manProgram == "" {
		manPage += ".txt"
		manProgram = os.Getenv("PAGER")
		if manProgram == "" {
			manProgram = "less -R"
		}
	}

	programPath, err := utils.CommandPath(args.ProgramPath)
	if err != nil {
		return err
	}

	installPrefix := filepath.Join(filepath.Dir(programPath), "..")
	manFile, err := localManPage(manPage, installPrefix)
	if err != nil {
		return err
	}

	man := cmd.New(manProgram)
	man.WithArg(manFile)
	if err = man.Run(); err == nil {
		os.Exit(0)
	} else {
		os.Exit(1)
	}
	return nil
}
Example #4
0
File: git.go Project: github/hub
func Show(sha string) (string, error) {
	cmd := cmd.New("git")
	cmd.WithArg("show").WithArg("-s").WithArg("--format=%s%n%+b").WithArg(sha)

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

	return output, err
}
Example #5
0
func (r *TestRepo) clone(repo, dir string) error {
	cmd := cmd.New("git").WithArgs("clone", repo, dir)
	output, err := cmd.CombinedOutput()
	if err != nil {
		err = fmt.Errorf("error cloning %s to %s: %s", repo, dir, output)
	}

	return err
}
Example #6
0
func openTextEditor(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.Spawn()
}
Example #7
0
File: git.go Project: github/hub
func gitCmd(args ...string) *cmd.Cmd {
	cmd := cmd.New("git")

	for _, v := range GlobalFlags {
		cmd.WithArg(v)
	}

	for _, a := range args {
		cmd.WithArg(a)
	}

	return cmd
}
Example #8
0
File: git.go Project: github/hub
func Log(sha1, sha2 string) (string, error) {
	execCmd := cmd.New("git")
	execCmd.WithArg("-c").WithArg("log.showSignature=false").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.CombinedOutput()
	if err != nil {
		return "", fmt.Errorf("Can't load git log %s..%s", sha1, sha2)
	}

	return outputs, nil
}
Example #9
0
func Run(command string, args ...string) error {
	cmd := cmd.New("git")

	for _, v := range GlobalFlags {
		cmd.WithArg(v)
	}

	cmd.WithArg(command)

	for _, a := range args {
		cmd.WithArg(a)
	}

	return cmd.Run()
}
Example #10
0
func (a *Args) ToCmd() *cmd.Cmd {
	c := cmd.New(a.Executable)
	args := make([]string, 0)

	if a.Command != "" {
		args = append(args, a.Command)
	}

	for _, arg := range a.Params {
		if arg != "" {
			args = append(args, arg)
		}
	}

	return c.WithArgs(args...)
}
Example #11
0
File: args.go Project: rlugojr/hub
func (a *Args) ToCmd() *cmd.Cmd {
	c := cmd.New(a.Executable)
	c.WithArgs(a.GlobalFlags...)

	if a.Command != "" {
		c.WithArg(a.Command)
	}

	for _, arg := range a.Params {
		if arg != "" {
			c.WithArg(arg)
		}
	}

	return c
}
Example #12
0
func git(input ...string) (outputs []string, err error) {

	cmd := cmd.New("git")

	for _, i := range input {
		cmd.WithArg(i)
	}

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

	return
}
Example #13
0
File: git.go Project: github/hub
func IsGitDir(dir string) bool {
	cmd := cmd.New("git")
	cmd.WithArgs("--git-dir="+dir, "rev-parse", "--git-dir")
	return cmd.Success()
}
Example #14
0
File: git.go Project: pcorpet/hub
func ForwardGitHelp() error {
	cmd := cmd.New("git")
	cmd.WithArgs("help")
	return cmd.Spawn()
}