예제 #1
0
파일: remote.go 프로젝트: johnbellone/gh
func transformRemoteArgs(args *Args) {
	ownerWithName := args.LastParam()
	owner, name, match := parseRepoNameOwner(ownerWithName)
	if !match {
		return
	}

	var err error
	if name == "" {
		name, err = utils.DirName()
		utils.Check(err)
	}

	isPriavte := parseRemotePrivateFlag(args)

	if owner == "origin" {
		owner = github.CurrentConfig().FetchUser()
	} else if args.ParamsSize() > 2 {
		// `git remote add jingweno foo/bar`
		args.RemoveParam(args.ParamsSize() - 1)
	}

	project := github.Project{Owner: owner, Name: name}
	url := project.GitURL(name, owner, isPriavte)

	args.AppendParams(url)
}
예제 #2
0
파일: clone.go 프로젝트: rif/golang-stuff
func transformCloneArgs(args *Args) {
	isSSH := parseClonePrivateFlag(args)
	hasValueRegxp := regexp.MustCompile("^(--(upload-pack|template|depth|origin|branch|reference|name)|-[ubo])$")
	nameWithOwnerRegexp := regexp.MustCompile(NameWithOwnerRe)
	for i, a := range args.Params {
		if hasValueRegxp.MatchString(a) {
			continue
		}

		if nameWithOwnerRegexp.MatchString(a) && !isDir(a) {
			name, owner := parseCloneNameAndOwner(a)
			config := github.CurrentConfig()
			isSSH = isSSH || owner == config.User
			if owner == "" {
				owner = config.User
			}

			project := github.Project{Name: name, Owner: owner}
			url := project.GitURL(name, owner, isSSH)
			args.ReplaceParam(i, url)

			break
		}
	}
}
예제 #3
0
파일: init.go 프로젝트: rif/golang-stuff
func transformInitArgs(args *Args) error {
	if !parseInitFlag(args) {
		return nil
	}

	name, err := utils.DirName()
	if err != nil {
		return err
	}

	owner := github.CurrentConfig().FetchUser()
	project := github.Project{Owner: owner, Name: name}
	url := project.GitURL(name, owner, true)
	args.After("git", "remote", "add", "origin", url)

	return nil
}
예제 #4
0
파일: clone.go 프로젝트: johnbellone/gh
func transformCloneArgs(args *Args) {
	isSSH := parseClonePrivateFlag(args)
	hasValueRegxp := regexp.MustCompile("^(--(upload-pack|template|depth|origin|branch|reference|name)|-[ubo])$")
	nameWithOwnerRegexp := regexp.MustCompile(NameWithOwnerRe)
	var skipNext bool
	for i, a := range args.Params {
		if skipNext {
			skipNext = false
			continue
		}

		if strings.HasPrefix(a, "-") {
			if hasValueRegxp.MatchString(a) {
				skipNext = true
			}
			continue
		}

		if github.MatchURL(a) != nil {
			break
		}

		if nameWithOwnerRegexp.MatchString(a) && !isDir(a) {
			name, owner := parseCloneNameAndOwner(a)
			config := github.CurrentConfig()
			isSSH = isSSH || args.Command != "submodule" && owner == config.User
			if owner == "" {
				owner = config.User
				isSSH = true
			}

			project := github.Project{Name: name, Owner: owner}
			url := project.GitURL(name, owner, isSSH)
			args.ReplaceParam(i, url)

			break
		}
	}
}