<commit_before>package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"path"
	"strings"

	ostree "github.com/sjoerdsimons/ostree-go/pkg/otbuiltin"
)

type OstreeDeployAction struct {
	*BaseAction
	Repository       string
	RemoteRepository string
	Branch           string
	Os               string
}

func (ot *OstreeDeployAction) Run(context *YaibContext) {
	repoPath := "file://" + path.Join(context.artifactdir, ot.Repository)

	sysroot := ostree.NewSysroot(context.imageMntDir)
	err := sysroot.InitializeFS()
	if err != nil {
		log.Fatal(err)
	}

	err = sysroot.InitOsname(ot.Os, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	dstRepo, err := sysroot.Repo(nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	err = dstRepo.RemoteAdd("origin", ot.RemoteRepository, nil, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	var options ostree.PullOptions
	options.OverrideRemoteName = "origin"
	options.Refs = []string{ot.Branch}

	err = dstRepo.PullWithOptions(repoPath, options, nil, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	/* Required by ostree to make sure a bunch of information was pulled in  */
	sysroot.Load(nil)

	revision, err := dstRepo.ResolveRev(ot.Branch, false)
	if err != nil {
		log.Fatalf("%s", err)
	}

	cmdline, _ := ioutil.ReadFile(path.Join(context.imageMntDir, "etc/kernel/cmdline"))
	kargs := strings.Split(strings.TrimSpace(string(cmdline)), " ")

	origin := sysroot.OriginNewFromRefspec("origin:" + ot.Branch)
	deployment, err := sysroot.DeployTree(ot.Os, revision, origin, nil, kargs, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	deploymentDir := fmt.Sprintf("ostree/deploy/%s/deploy/%s.%d",
		deployment.Osname(), deployment.Csum(), deployment.Deployserial())

	etcDir := path.Join(context.imageMntDir, deploymentDir, "etc")

	err = os.Mkdir(etcDir, 755)
	if err != nil && !os.IsExist(err) {
		log.Fatalf("%s", err)
	}

	dst, err := os.OpenFile(path.Join(etcDir, "fstab"), os.O_WRONLY|os.O_CREATE, 0755)
	defer dst.Close()
	if err != nil {
		log.Fatalf("%s", err)
	}

	src, err := os.Open(path.Join(context.imageMntDir, "etc", "fstab"))
	defer src.Close()
	if err != nil {
		log.Fatalf("%s", err)
	}

	_, err = io.Copy(dst, src)
	if err != nil {
		log.Fatalf("%s", err)
	}

	err = sysroot.SimpleWriteDeployment(ot.Os, deployment, nil, 0, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}
}
<commit_msg>Explicitely name the remote repository field<commit_after>package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"path"
	"strings"

	ostree "github.com/sjoerdsimons/ostree-go/pkg/otbuiltin"
)

type OstreeDeployAction struct {
	*BaseAction
	Repository       string
	RemoteRepository string "remote_repository"
	Branch           string
	Os               string
}

func (ot *OstreeDeployAction) Run(context *YaibContext) {
	repoPath := "file://" + path.Join(context.artifactdir, ot.Repository)

	sysroot := ostree.NewSysroot(context.imageMntDir)
	err := sysroot.InitializeFS()
	if err != nil {
		log.Fatal(err)
	}

	err = sysroot.InitOsname(ot.Os, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	dstRepo, err := sysroot.Repo(nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	err = dstRepo.RemoteAdd("origin", ot.RemoteRepository, nil, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	var options ostree.PullOptions
	options.OverrideRemoteName = "origin"
	options.Refs = []string{ot.Branch}

	err = dstRepo.PullWithOptions(repoPath, options, nil, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	/* Required by ostree to make sure a bunch of information was pulled in  */
	sysroot.Load(nil)

	revision, err := dstRepo.ResolveRev(ot.Branch, false)
	if err != nil {
		log.Fatalf("%s", err)
	}

	cmdline, _ := ioutil.ReadFile(path.Join(context.imageMntDir, "etc/kernel/cmdline"))
	kargs := strings.Split(strings.TrimSpace(string(cmdline)), " ")

	origin := sysroot.OriginNewFromRefspec("origin:" + ot.Branch)
	deployment, err := sysroot.DeployTree(ot.Os, revision, origin, nil, kargs, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}

	deploymentDir := fmt.Sprintf("ostree/deploy/%s/deploy/%s.%d",
		deployment.Osname(), deployment.Csum(), deployment.Deployserial())

	etcDir := path.Join(context.imageMntDir, deploymentDir, "etc")

	err = os.Mkdir(etcDir, 755)
	if err != nil && !os.IsExist(err) {
		log.Fatalf("%s", err)
	}

	dst, err := os.OpenFile(path.Join(etcDir, "fstab"), os.O_WRONLY|os.O_CREATE, 0755)
	defer dst.Close()
	if err != nil {
		log.Fatalf("%s", err)
	}

	src, err := os.Open(path.Join(context.imageMntDir, "etc", "fstab"))
	defer src.Close()
	if err != nil {
		log.Fatalf("%s", err)
	}

	_, err = io.Copy(dst, src)
	if err != nil {
		log.Fatalf("%s", err)
	}

	err = sysroot.SimpleWriteDeployment(ot.Os, deployment, nil, 0, nil)
	if err != nil {
		log.Fatalf("%s", err)
	}
}

{'fraction_non_alphanumeric': 0.16852279890733346, 'fraction_numerical': 0.0033620508510191216, 'mean_word_length': 3.912280701754386, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2937273', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1852, 'n_words': 386}