Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software:2222/vole.git

A free and open-source forge that lives in your Git repo.

Code

395 commit(s) on main

update readme Keenan Nemetz · 26m ago 32290114
history blame raw 938 B
1package git
2
3import (
4 "os/exec"
5 "path/filepath"
6 "strings"
7 "testing"
8)
9
10func TestGrepFindsFixedStrings(t *testing.T) {
11 dir := filepath.Join(t.TempDir(), "r.git")
12 if out, err := exec.Command("git", "init", "--bare", "-q", dir).CombinedOutput(); err != nil {
13 t.Fatalf("init: %v: %s", err, out)
14 }
15 g := Open(dir)
16 if _, err := CommitFiles(g, "refs/heads/main", func(files map[string][]byte) error {
17 files["main.go"] = []byte("package main\n// HelloNeedle lives here\n")
18 files["README.md"] = []byte("nothing\n")
19 return nil
20 }, "init", "test"); err != nil {
21 t.Fatal(err)
22 }
23 sha, err := g.RevParse("refs/heads/main")
24 if err != nil {
25 t.Fatal(err)
26 }
27 out, cut, err := g.Grep(sha, "needle", 4096)
28 if err != nil {
29 t.Fatal(err)
30 }
31 if cut {
32 t.Fatal("small result was truncated")
33 }
34 if !strings.Contains(string(out), "main.go:2:") || !strings.Contains(string(out), "HelloNeedle") {
35 t.Fatalf("grep output = %q", out)
36 }
37}
38