| 1 | import { afterAll, expect, test } from "bun:test"; |
| 2 | import { mkdtemp, rm |
| 3 | import os from "node:os |
| 4 | import path from "node:path |
| 5 | |
| 6 | import { credentialEnv, listRefs |
| 7 | |
| 8 | const never = new |
| 9 | const dir = await |
| 10 | afterAll(() => rm |
| 11 | |
| 12 | const env = { |
| 13 | GIT_AUTHOR_NAME: "t", |
| 14 | GIT_AUTHOR_EMAIL: "t@t", |
| 15 | GIT_COMMITTER_NAME: "t", |
| 16 | GIT_COMMITTER_EMAIL: "t@t", |
| 17 | }; |
| 18 | function git(...args |
| 19 | const result = |
| 20 | env: { ...process |
| 21 | }); |
| 22 | if (result.exitCode |
| 23 | return result.stdout |
| 24 | } |
| 25 | |
| 26 | git("init", " |
| 27 | git("commit", " |
| 28 | git("tag", " |
| 29 | const head = git |
| 30 | |
| 31 | test("credentialEnv scopes a basic header to one origin", () |
| 32 | expect(credentialEnv("https://github.com |
| 33 | GIT_TERMINAL_PROMPT: "0", |
| 34 | GIT_CONFIG_COUNT: "1", |
| 35 | GIT_CONFIG_KEY_0: "http.https://github.com/.extraHeader", |
| 36 | GIT_CONFIG_VALUE_0: `Authorization: Basic ${btoa |
| 37 | }); |
| 38 | }); |
| 39 | |
| 40 | test("listRefs lists branches and tags", async |
| 41 | expect(await listRefs |
| 42 | new Set(["refs/heads/main |
| 43 | ); |
| 44 | }); |
| 45 | |
| 46 | test("presentCommits keeps only commits the history has", async |
| 47 | expect(await presentCommits |
| 48 | new Set([head |
| 49 | ); |
| 50 | expect(await presentCommits |
| 51 | }); |
| 52 | |
| 53 | test("a failing git command reports its stderr", async |
| 54 | await expect(listRefs |
| 55 | /git -C .* for-each-ref .* exited with/ |
| 56 | ); |
| 57 | }); |