BlueGit

timfa bluegit

Files

bluegit / internal / runner / clone_test.go

clone_test.go

clone_test.go 1.3 KiB Download Raw
1package runner
2
3import (
4 "os"
5 "os/exec"
6 "path/filepath"
7 "testing"
8)
9
10func TestCloneCopiesObjects(t *testing.T) {
11 if _, err := exec.LookPath("git"); err != nil {
12 t.Skip("git ontbreekt")
13 }
14 src := t.TempDir()
15 run := func(dir string, args ...string) {
16 cmd := exec.Command("git", append([]string{"-C", dir}, args...)...)
17 cmd.Env = append(os.Environ(), "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@t", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@t")
18 if out, err := cmd.CombinedOutput(); err != nil {
19 t.Fatalf("%v: %s", args, out)
20 }
21 }
22 run(src, "init", "-q", "-b", "master")
23 _ = os.WriteFile(filepath.Join(src, "a"), []byte("a"), 0o644)
24 run(src, "add", "a")
25 run(src, "commit", "-qm", "a")
26 bare := filepath.Join(t.TempDir(), "r.git")
27 if out, err := exec.Command("git", "clone", "-q", "--bare", src, bare).CombinedOutput(); err != nil {
28 t.Fatal(string(out))
29 }
30 work := filepath.Join(t.TempDir(), "w")
31 if out, err := exec.Command("git", cloneArgs(bare, work)...).CombinedOutput(); err != nil {
32 t.Fatal(string(out))
33 }
34 // geen gedeelde inodes met de bare repo
35 _ = filepath.Walk(filepath.Join(work, ".git", "objects"), func(p string, info os.FileInfo, err error) error {
36 if err == nil && !info.IsDir() {
37 if st, ok := sysNlink(info); ok && st > 1 {
38 t.Fatalf("hardlink: %s", p)
39 }
40 }
41 return nil
42 })
43}