···
-
"github.com/go-git/go-git/v5/plumbing"
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/workflow"
···
-
// checkoutStep checks out the specified ref in the cloned repository.
-
func checkoutStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata) Step {
-
ref = tr.PullRequest.TargetBranch
-
// TODO: this needs to be specified in lexicon
-
ref = tr.Repo.DefaultBranch
-
checkoutCmd := fmt.Sprintf("git config advice.detachedHead false; git checkout --progress --force %s", ref)
-
Name: "Checkout ref " + ref,
// cloneOptsAsSteps processes clone options and adds corresponding steps
// to the beginning of the workflow's step list if cloning is not skipped.
func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata, dev bool) Step {
tr.Repo.Knot = strings.ReplaceAll(tr.Repo.Knot, "localhost", "host.docker.internal")
-
cloneUrl := uri + path.Join(tr.Repo.Knot, tr.Repo.Did, tr.Repo.Repo)
-
cloneCmd := []string{"git", "clone", cloneUrl, "."}
-
// default clone depth is 1
-
if twf.Clone.Depth > 1 {
-
cloneDepth = int(twf.Clone.Depth)
-
cloneCmd = append(cloneCmd, fmt.Sprintf("--depth=%d", cloneDepth))
-
// select the clone branch
-
case workflow.TriggerKindManual:
-
case workflow.TriggerKindPush:
-
refName := plumbing.ReferenceName(ref)
-
cloneBranch = refName.Short()
-
case workflow.TriggerKindPullRequest:
-
cloneBranch = tr.PullRequest.SourceBranch
-
cloneCmd = append(cloneCmd, fmt.Sprintf("--branch=%s", cloneBranch))
-
if twf.Clone.Submodules {
-
cloneCmd = append(cloneCmd, "--recursive")
-
fmt.Println(strings.Join(cloneCmd, " "))
-
Command: strings.Join(cloneCmd, " "),
Name: "Clone repository into workspace",
···
"tangled.sh/tangled.sh/core/api/tangled"
"tangled.sh/tangled.sh/core/workflow"
···
// cloneOptsAsSteps processes clone options and adds corresponding steps
// to the beginning of the workflow's step list if cloning is not skipped.
+
// the steps to do here are:
+
// - git remote add origin <url>
+
// - git fetch --depth=<d> --recurse-submodules=<yes|no> <sha>
+
// - git checkout FETCH_HEAD
func cloneStep(twf tangled.Pipeline_Workflow, tr tangled.Pipeline_TriggerMetadata, dev bool) Step {
+
// initialize git repo in workspace
+
commands = append(commands, "git init")
+
// add repo as git remote
tr.Repo.Knot = strings.ReplaceAll(tr.Repo.Knot, "localhost", "host.docker.internal")
+
url := scheme + path.Join(tr.Repo.Knot, tr.Repo.Did, tr.Repo.Repo)
+
commands = append(commands, fmt.Sprintf("git remote add origin %s", url))
+
// default clone depth is 1
+
if twf.Clone.Depth > 1 {
+
depth = int(twf.Clone.Depth)
+
fetchArgs = append(fetchArgs, fmt.Sprintf("--depth=%d", depth))
+
// optionally recurse submodules
+
if twf.Clone.Submodules {
+
fetchArgs = append(fetchArgs, "--recurse-submodules=yes")
+
// set remote to fetch from
+
fetchArgs = append(fetchArgs, "origin")
+
// set revision to checkout
+
switch workflow.TriggerKind(tr.Kind) {
+
case workflow.TriggerKindManual:
+
case workflow.TriggerKindPush:
+
fetchArgs = append(fetchArgs, tr.Push.NewSha)
+
case workflow.TriggerKindPullRequest:
+
fetchArgs = append(fetchArgs, tr.PullRequest.SourceSha)
+
commands = append(commands, fmt.Sprintf("git fetch %s", strings.Join(fetchArgs, " ")))
+
commands = append(commands, "git checkout FETCH_HEAD")
+
Command: strings.Join(commands, "\n"),
Name: "Clone repository into workspace",