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 · 29m ago 32290114
history blame raw 1.4 KiB
1package git
2
3import (
4 "os/exec"
5 "path/filepath"
6 "testing"
7)
8
9// TestEnvironmentIsNotInherited guards the bug that made a hook read the wrong
10// repository: pre-receive runs with GIT_OBJECT_DIRECTORY and friends pointing at
11// the pushed repository's quarantine, and a hook that shells out to git for a
12// different repository must not inherit them.
13func TestEnvironmentIsNotInherited(t *testing.T) {
14 dir := filepath.Join(t.TempDir(), "r.git")
15 if out, err := exec.Command("git", "init", "--bare", "-q", dir).CombinedOutput(); err != nil {
16 t.Fatalf("init: %v: %s", err, out)
17 }
18 g := Open(dir)
19 if _, err := CommitFiles(g, "refs/heads/main", func(files map[string][]byte) error {
20 files["a.txt"] = []byte("hi\n")
21 return nil
22 }, "init", "test"); err != nil {
23 t.Fatal(err)
24 }
25
26 // Point the inherited variables somewhere useless, as receive-pack would.
27 t.Setenv("GIT_OBJECT_DIRECTORY", filepath.Join(t.TempDir(), "no-objects-here"))
28 t.Setenv("GIT_QUARANTINE_PATH", filepath.Join(t.TempDir(), "no-quarantine-here"))
29 t.Setenv("GIT_DIR", filepath.Join(t.TempDir(), "some-other.git"))
30
31 sha, err := g.RevParse("refs/heads/main")
32 if err != nil || sha == "" {
33 t.Fatalf("RevParse = %q, %v", sha, err)
34 }
35 files, err := g.FlatTree(sha)
36 if err != nil {
37 t.Fatalf("FlatTree: %v", err)
38 }
39 if got := string(files["a.txt"]); got != "hi\n" {
40 t.Fatalf("a.txt = %q; the inherited environment redirected git elsewhere", got)
41 }
42}
43