(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func TestHash(t *testing.T) { |
| 329 | t.Run("returns ErrRefNotFound for a missing ref", func(t *testing.T) { |
| 330 | tempDir := setupTestRepository(t) |
| 331 | |
| 332 | _, err := Hash(context.Background(), tempDir, "refs/heads/does-not-exist") |
| 333 | require.ErrorIs(t, err, ErrRefNotFound) |
| 334 | }) |
| 335 | |
| 336 | t.Run("returns ErrRefNotFound for HEAD in an unborn repository", func(t *testing.T) { |
| 337 | tempDir := t.TempDir() |
| 338 | require.NoError(t, exec.Command("git", "init", tempDir).Run()) |
| 339 | require.NoError(t, exec.Command("git", "-C", tempDir, "checkout", "-b", "main").Run()) |
| 340 | setupGitConfig(t, tempDir) |
| 341 | |
| 342 | _, err := Hash(context.Background(), tempDir, "HEAD") |
| 343 | require.ErrorIs(t, err, ErrRefNotFound) |
| 344 | }) |
| 345 | |
| 346 | t.Run("returns the commit hash for HEAD", func(t *testing.T) { |
| 347 | tempDir := setupTestRepository(t) |
| 348 | |
| 349 | hash, err := Hash(context.Background(), tempDir, "HEAD") |
| 350 | require.NoError(t, err) |
| 351 | require.Len(t, hash, 40) |
| 352 | }) |
| 353 | } |
| 354 | |
| 355 | func TestIsCommitHash(t *testing.T) { |
| 356 | require.True(t, IsCommitHash(strings.Repeat("a1", 20)), "40-char SHA-1") |
nothing calls this directly
no test coverage detected