prow/pod-utils/clone/clone.go
func (g *gitCtx) commandsForBaseRef(refs prowapi.Refs, gitUserName, gitUserEmail, cookiePath string) []cloneCommand {
	commands := []cloneCommand{{dir: "/", env: g.env, command: "mkdir", args: []string{"-p", g.cloneDir}}}

	commands = append(commands, g.gitCommand("init"))
	if gitUserName != "" {
		commands = append(commands, g.gitCommand("config", "user.name", gitUserName))
	}
	if gitUserEmail != "" {
		commands = append(commands, g.gitCommand("config", "user.email", gitUserEmail))
	}
	if cookiePath != "" {
		commands = append(commands, g.gitCommand("config", "http.cookiefile", cookiePath))
	}
	commands = append(commands, g.gitCommand("fetch", g.repositoryURI, "--tags", "--prune"))
	commands = append(commands, g.gitCommand("fetch", g.repositoryURI, refs.BaseRef))

	var target string
	if refs.BaseSHA != "" {
		target = refs.BaseSHA
	} else {
		target = "FETCH_HEAD"
	}
	// we need to be "on" the target branch after the sync
	// so we need to set the branch to point to the base ref,
	// but we cannot update a branch we are on, so in case we
	// are on the branch we are syncing, we check out the SHA
	// first and reset the branch second, then check out the
	// branch we just reset to be in the correct final state
	commands = append(commands, g.gitCommand("checkout", target))
	commands = append(commands, g.gitCommand("branch", "--force", refs.BaseRef, target))
	commands = append(commands, g.gitCommand("checkout", refs.BaseRef))

	return commands
}
func (g *gitCtx) commandsForBaseRef(refs prowapi.Refs, gitUserName, gitUserEmail, cookiePath string) []cloneCommand {
	commands := []cloneCommand{{dir: "/", env: g.env, command: "mkdir", args: []string{"-p", g.cloneDir}}}

	commands = append(commands, g.gitCommand("init"))
	if gitUserName != "" {
		commands = append(commands, g.gitCommand("config", "user.name", gitUserName))
	}
	if gitUserEmail != "" {
		commands = append(commands, g.gitCommand("config", "user.email", gitUserEmail))
	}
	if cookiePath != "" {
		commands = append(commands, g.gitCommand("config", "http.cookiefile", cookiePath))
	}
	commands = append(commands, g.gitCommand("fetch", g.repositoryURI, "--tags", "--prune"))
	commands = append(commands, g.gitCommand("fetch", g.repositoryURI, refs.BaseRef))

	var target string
	if refs.BaseSHA != "" {
		target = refs.BaseSHA
	} else {
		target = "FETCH_HEAD"
	}
	// we need to be "on" the target branch after the sync
	// so we need to set the branch to point to the base ref,
	// but we cannot update a branch we are on, so in case we
	// are on the branch we are syncing, we check out the SHA
	// first and reset the branch second, then check out the
	// branch we just reset to be in the correct final state
	commands = append(commands, g.gitCommand("checkout", target))
	commands = append(commands, g.gitCommand("branch", "--force", refs.BaseRef, target))
	commands = append(commands, g.gitCommand("checkout", refs.BaseRef))

	return commands
}
func ( g * gitCtx ) commandsForBaseRef ( refs prowapi . Refs , gitUserName , gitUserEmail , cookiePath string ) [ ] cloneCommand { commands := [ ] cloneCommand { { dir : " " , env : g . env , command : " " , args : [ ] string { " " , g . cloneDir } } } commands = append ( commands , g . gitCommand ( " " ) ) if gitUserName != " " { commands = append ( commands , g . gitCommand ( " " , " " , gitUserName ) ) } if gitUserEmail != " " { commands = append ( commands , g . gitCommand ( " " , " " , gitUserEmail ) ) } if cookiePath != " " { commands = append ( commands , g . gitCommand ( " " , " " , cookiePath ) ) } commands = append ( commands , g . gitCommand ( " " , g . repositoryURI , " " , " " ) ) commands = append ( commands , g . gitCommand ( " " , g . repositoryURI , refs . BaseRef ) ) var target string if refs . BaseSHA != " " { target = refs . BaseSHA } else { target = " " } // we need to be "on" the target branch after the sync // so we need to set the branch to point to the base ref, // but we cannot update a branch we are on, so in case we // are on the branch we are syncing, we check out the SHA // first and reset the branch second, then check out the // branch we just reset to be in the correct final state commands = append ( commands , g . gitCommand ( " " , target ) ) commands = append ( commands , g . gitCommand ( " " , " " , refs . BaseRef , target ) ) commands = append ( commands , g . gitCommand ( " " , refs . BaseRef ) ) return commands }
// commandsForBaseRef returns the list of commands needed to initialize and
// configure a local git directory, as well as fetch and check out the provided
// base ref.
commandsForBaseRef returns the list of commands needed to initialize and configure a local git directory as well as fetch and check out the provided base ref .