Skip to content
quarry Artifact [169b6b58f7]
Login

Artifact [169b6b58f7]

Artifact 169b6b58f72b442806ce0c8f8427d9eec6baf1feda1f4bcaaacf15d24d61638f:


package zitcli

import (
	"context"
	"os"
	"path/filepath"
	"strings"
	"testing"
)

// The file-index warm asks about a path that cannot exist. zit 0.9.0
// follows renames by default, and a followed walk for a name it never
// meets reads every ancestor's file list (90 s+ on pkgsrc), so the warm
// must ask without following. Real file histories still follow.
func TestWarmFileIndexDoesNotFollowRenames(t *testing.T) {
	argsFile := filepath.Join(t.TempDir(), "args")
	fakeZit(t, `echo "$@" >> `+argsFile)
	c := New(t.TempDir())
	if err := c.WarmFileIndex(context.Background(), "tip", ".quarry-warm-file-index"); err != nil {
		t.Fatal(err)
	}
	if _, err := c.FileHistory(context.Background(), "tip", "src/a.c", 5); err != nil {
		t.Fatal(err)
	}
	b, _ := os.ReadFile(argsFile)
	lines := strings.Split(strings.TrimSpace(string(b)), "\n")
	if len(lines) != 2 || !strings.Contains(lines[0], "--no-follow") || strings.Contains(lines[1], "--no-follow") {
		t.Fatalf("FAIL: zit was asked\n%s\nwant --no-follow on the warm only", b)
	}
	t.Log("ok: the warm skips rename following; a file's history keeps it")
}