<commit_before>package modules

import (
	"errors"
	"fmt"
	"io/ioutil"
	"regexp"
	"strings"

	"github.com/wx13/genesis"
	"github.com/wx13/genesis/store"
)

type LineInFile struct {
	File    string
	Pattern string
	Success string
	Line    string
	Store   *store.Store
	Label   string
	Before  string
	After   string
}

func (lif LineInFile) Describe() string {
	return fmt.Sprintf("LineInFile: %s, %s, %s", lif.File, lif.Pattern, lif.Line)
}

func (lif LineInFile) ID() string {
	return "lineInFile" + lif.File + lif.Pattern + lif.Line + lif.Label + lif.Before + lif.After
}

func (lif LineInFile) readFile() ([]string, error) {
	content, err := ioutil.ReadFile(lif.File)
	if err != nil {
		return []string{}, err
	}
	lines := strings.Split(string(content), "\n")
	return lines, nil
}

func (lif LineInFile) writeFile(lines []string) error {
	content := strings.Join(lines, "\n") + "\n"
	err := ioutil.WriteFile(lif.File, []byte(content), 0644)
	return err
}

func (lif LineInFile) Remove() (string, error) {
	lif.File = genesis.ExpandHome(lif.File)
	err := lif.Store.ApplyPatch(lif.File, lif.Label)
	if err != nil {
		return "Could not apply patch.", err
	}
	return "Patch applied", nil
}

func (lif LineInFile) Status() (genesis.Status, string, error) {

	lif.File = genesis.ExpandHome(lif.File)

	lines, err := lif.readFile()
	if err != nil {
		return genesis.StatusFail, "Could not read file.", err
	}
	isAfter := len(lif.After) == 0
	for _, line := range lines {
		pattern := regexp.QuoteMeta(lif.Line)
		if len(lif.Success) > 0 {
			pattern = lif.Success
		}
		match, _ := regexp.MatchString(pattern, line)<commit_msg>bugfix: lif status should require exact match<commit_after>package modules

import (
	"errors"
	"fmt"
	"io/ioutil"
	"regexp"
	"strings"

	"github.com/wx13/genesis"
	"github.com/wx13/genesis/store"
)

type LineInFile struct {
	File    string
	Pattern string
	Success string
	Line    string
	Store   *store.Store
	Label   string
	Before  string
	After   string
}

func (lif LineInFile) Describe() string {
	return fmt.Sprintf("LineInFile: %s, %s, %s", lif.File, lif.Pattern, lif.Line)
}

func (lif LineInFile) ID() string {
	return "lineInFile" + lif.File + lif.Pattern + lif.Line + lif.Label + lif.Before + lif.After
}

func (lif LineInFile) readFile() ([]string, error) {
	content, err := ioutil.ReadFile(lif.File)
	if err != nil {
		return []string{}, err
	}
	lines := strings.Split(string(content), "\n")
	return lines, nil
}

func (lif LineInFile) writeFile(lines []string) error {
	content := strings.Join(lines, "\n") + "\n"
	err := ioutil.WriteFile(lif.File, []byte(content), 0644)
	return err
}

func (lif LineInFile) Remove() (string, error) {
	lif.File = genesis.ExpandHome(lif.File)
	err := lif.Store.ApplyPatch(lif.File, lif.Label)
	if err != nil {
		return "Could not apply patch.", err
	}
	return "Patch applied", nil
}

func (lif LineInFile) Status() (genesis.Status, string, error) {

	lif.File = genesis.ExpandHome(lif.File)

	lines, err := lif.readFile()
	if err != nil {
		return genesis.StatusFail, "Could not read file.", err
	}
	isAfter := len(lif.After) == 0
	for _, line := range lines {
		match := lif.Line == line
		if len(lif.Success) > 0 {
			match, _ := regexp.MatchString(lif.Success, line)
		}
{'fraction_non_alphanumeric': 0.15064695009242143, 'fraction_numerical': 0.0061614294516327784, 'mean_word_length': 3.8827067669172934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2059134', 'n_tokens_mistral': 1221, 'n_tokens_neox': 1173, 'n_words': 314}