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.
| 1 | package git |
| 2 | |
| 3 | // RefCommit exists to make the index's once-per-page check cheap, so its two |
| 4 | // answers matter equally: a loose ref must not start a process, and a ref the |
| 5 | // fast path cannot read must still get git's answer. |
| 6 | |
| 7 | import ( |
| 8 | "os" |
| 9 | "os/exec" |
| 10 | "path/filepath" |
| 11 | "strings" |
| 12 | "testing" |
| 13 | ) |
| 14 | |
| 15 | func TestRefCommitReadsALooseRefWithoutRunningGit(t *testing.T) { |
| 16 | dir := tagRepo(t) |
| 17 | r := open(t, dir) |
| 18 | trace := filepath.Join(t.TempDir(), "git.trace") |
| 19 | t.Setenv("GIT_TRACE", trace) |
| 20 | |
| 21 | sha, err := r.RefCommit("refs/heads/main") |
| 22 | if err != nil || sha == "" { |
| 23 | t.Fatalf("RefCommit(loose) = %q, %v", sha, err) |
| 24 | } |
| 25 | if data, err := os.ReadFile(trace); err == nil && strings.Contains(string(data), "rev-parse") { |
| 26 | t.Fatalf("a loose ref started git:\n%s", data) |
| 27 | } |
| 28 | |
| 29 | // After packing, the loose file is gone; the fallback must still answer the |
| 30 | // same commit, and this time it does run git. |
| 31 | cmd := exec.Command("git", "-C", dir, "pack-refs", "--all") |
| 32 | cmd.Env = append(os.Environ(), "GIT_CONFIG_GLOBAL=/dev/null", "GIT_CONFIG_SYSTEM=/dev/null") |
| 33 | if out, err := cmd.CombinedOutput(); err != nil { |
| 34 | t.Fatalf("pack-refs: %v: %s", err, out) |
| 35 | } |
| 36 | if _, err := os.Stat(filepath.Join(dir, ".git", "refs", "heads", "main")); !os.IsNotExist(err) { |
| 37 | t.Fatalf("pack-refs left the loose ref behind: %v", err) |
| 38 | } |
| 39 | packed, err := r.RefCommit("refs/heads/main") |
| 40 | if err != nil || packed != sha { |
| 41 | t.Fatalf("RefCommit(packed) = %q, %v; want %q", packed, err, sha) |
| 42 | } |
| 43 | data, err := os.ReadFile(trace) |
| 44 | if err != nil || !strings.Contains(string(data), "rev-parse") { |
| 45 | t.Fatalf("a packed ref did not fall back to git: %v\n%s", err, data) |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | func TestRefCommitFallsBackForARevisionItDoesNotRead(t *testing.T) { |
| 50 | r := open(t, tagRepo(t)) |
| 51 | head, err := r.RefCommit("refs/heads/main") |
| 52 | if err != nil || head == "" { |
| 53 | t.Fatal(err) |
| 54 | } |
| 55 | // A branch that does not exist resolves to "", exactly like RevParse. |
| 56 | if sha, err := r.RefCommit("refs/heads/nope"); err != nil || sha != "" { |
| 57 | t.Fatalf("missing ref = %q, %v", sha, err) |
| 58 | } |
| 59 | // A revision that is not a branch name is git's business, not the file's. |
| 60 | if sha, err := r.RefCommit("main"); err != nil || sha != head { |
| 61 | t.Fatalf("RefCommit(main) = %q, %v; want %q", sha, err, head) |
| 62 | } |
| 63 | } |
| 64 |