Skip to content

Add conformance tests based on upstream Git#59

Merged
pjbgf merged 5 commits into
mainfrom
conformance-tests
May 13, 2026
Merged

Add conformance tests based on upstream Git#59
pjbgf merged 5 commits into
mainfrom
conformance-tests

Conversation

@pjbgf
Copy link
Copy Markdown
Member

@pjbgf pjbgf commented May 12, 2026

Expands the cli featureset mostly so that we can run the same test cases as git/git, ensuring that go-git's behaviour is aligned with upstream.

First test suites introduced:

t2008-checkout-subdir.sh
t5308-pack-detect-duplicates.sh

Results:

make conformance
./conformance/run.sh
Building gogit...
Refreshing /home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git from origin...
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)
HEAD is now at 29bd7ed The second batch
=== Running t2008-checkout-subdir.sh ===
Initialized empty Git repository in /home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir
expecting success of 2008.1 'setup':

	echo "base" > file0 &&
	git add file0 &&
	mkdir dir1 &&
	echo "hello" > dir1/file1 &&
	git add dir1/file1 &&
	mkdir dir2 &&
	echo "bonjour" > dir2/file2 &&
	git add dir2/file2 &&
	test_tick &&
	git commit -m "populate tree"


ok 1 - setup

expecting success of 2008.2 'remove and restore with relative path':

	(
		cd dir1 &&
		rm ../file0 &&
		git checkout HEAD -- ../file0 &&
		test "base" = "$(cat ../file0)" &&
		rm ../dir2/file2 &&
		git checkout HEAD -- ../dir2/file2 &&
		test "bonjour" = "$(cat ../dir2/file2)" &&
		rm ../file0 ./file1 &&
		git checkout HEAD -- .. &&
		test "base" = "$(cat ../file0)" &&
		test "hello" = "$(cat file1)"
	)


ok 2 - remove and restore with relative path

expecting success of 2008.3 'checkout with empty prefix':

	rm file0 &&
	git checkout HEAD -- file0 &&
	test "base" = "$(cat file0)"


ok 3 - checkout with empty prefix

expecting success of 2008.4 'checkout with simple prefix':

	rm dir1/file1 &&
	git checkout HEAD -- dir1 &&
	test "hello" = "$(cat dir1/file1)" &&
	rm dir1/file1 &&
	git checkout HEAD -- dir1/file1 &&
	test "hello" = "$(cat dir1/file1)"


ok 4 - checkout with simple prefix

expecting success of 2008.5 'checkout with complex relative path':
	(
		cd dir1 &&
		rm file1 &&
		git checkout HEAD -- ../dir1/../dir1/file1 &&
		test "hello" = "$(cat file1)"
	)

ok 5 - checkout with complex relative path

expecting success of 2008.6 'relative path outside tree should fail': test_must_fail git checkout HEAD -- ../../Makefile
Error: pathspec "../../Makefile" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
Usage:
  gogit checkout <tree-ish> -- <pathspec>...

Flags:
  -h, --help   help for checkout

pathspec "../../Makefile" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
ok 6 - relative path outside tree should fail

expecting success of 2008.7 'incorrect relative path to file should fail (1)': test_must_fail git checkout HEAD -- ../file0
Error: pathspec "../file0" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
Usage:
  gogit checkout <tree-ish> -- <pathspec>...

Flags:
  -h, --help   help for checkout

pathspec "../file0" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
ok 7 - incorrect relative path to file should fail (1)

expecting success of 2008.8 'incorrect relative path should fail (2)': ( cd dir1 && test_must_fail git checkout HEAD -- ./file0 )
Error: no matching paths in HEAD
Usage:
  gogit checkout <tree-ish> -- <pathspec>...

Flags:
  -h, --help   help for checkout

no matching paths in HEAD
ok 8 - incorrect relative path should fail (2)

expecting success of 2008.9 'incorrect relative path should fail (3)': ( cd dir1 && test_must_fail git checkout HEAD -- ../../file0 )
Error: pathspec "../../file0" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
Usage:
  gogit checkout <tree-ish> -- <pathspec>...

Flags:
  -h, --help   help for checkout

pathspec "../../file0" is outside worktree "/home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t2008-checkout-subdir"
ok 9 - incorrect relative path should fail (3)

# passed all 9 test(s)
1..9
=== Running t5308-pack-detect-duplicates.sh ===
Initialized empty Git repository in /home/coder/git/tasks/conformance-tests/go-git-cli/conformance/.cache/git/t/trash directory.t5308-pack-detect-duplicates
expecting success of 5308.1 'setup':
	test_oid_cache <<-EOF
	lo_oid sha1:e68fe8129b546b101aee9510c5328e7f21ca1d18
	lo_oid sha256:471819e8c52bf11513f100b2810a8aa0622d5cd3d1c913758a071dd4b3bad8fe

	missing_oid sha1:e69d000000000000000000000000000000000000
	missing_oid sha256:4720000000000000000000000000000000000000000000000000000000000000
	EOF

ok 1 - setup

expecting success of 5308.2 'pack with no duplicates':
	create_pack no-dups.pack 1 &&
	git index-pack --stdin <no-dups.pack

ok 2 - pack with no duplicates

expecting success of 5308.3 'index-pack will allow duplicate objects by default':
	clear_packs &&
	create_pack dups.pack 100 &&
	git index-pack --stdin <dups.pack

ok 3 - index-pack will allow duplicate objects by default

expecting success of 5308.4 'create batch-check test vectors':
	cat >input <<-EOF &&
	$LO_SHA1
	$HI_SHA1
	$MISSING_SHA1
	EOF
	cat >expect <<-EOF
	$LO_SHA1 blob 2
	$HI_SHA1 blob 0
	$MISSING_SHA1 missing
	EOF

ok 4 - create batch-check test vectors

expecting success of 5308.5 'lookup in duplicated pack':
	git cat-file --batch-check <input >actual &&
	test_cmp expect actual

ok 5 - lookup in duplicated pack

expecting success of 5308.6 'index-pack can reject packs with duplicates':
	clear_packs &&
	create_pack dups.pack 2 &&
	test_must_fail git index-pack --strict --stdin <dups.pack &&
	test_expect_code 1 git cat-file -e $LO_SHA1

duplicate object e68fe8129b546b101aee9510c5328e7f21ca1d18 in pack (--strict)
ok 6 - index-pack can reject packs with duplicates

# passed all 6 test(s)
1..6

Thanks @Soph for suggesting this approach. 🙇

Copilot AI review requested due to automatic review settings May 12, 2026 20:44
@pjbgf pjbgf requested a review from aymanbagabas as a code owner May 12, 2026 20:44
pjbgf added 3 commits May 12, 2026 21:46
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Adds a regression gate for gogit's path-restore checkout by running
upstream Git's own test framework against the gogit binary.

- Implements just enough gogit subcommands for t/t2008-checkout-subdir.sh
  to run end-to-end: init, add, commit -m (with GIT_*_NAME/EMAIL/DATE env
  honoured), checkout HEAD -- <pathspec> (with worktree-escape rejection
  and directory expansion), version --build-options.
- Root-level --exec-path and --version flags, plus os.Exit(1) on bare
  invocation; required by test-lib.sh's bootstrap and sanity checks.
- All repo opens use PlainOpenWithOptions(DetectDotGit) so commands work
  from subdirectories (t2008 cd's into dir1).
- conformance/run.sh fetches upstream tests via \$GIT_SRC override or a
  shallow clone of github.com/git/git default branch (no SHA pin --
  upstream drift surfaces immediately). Synthesises a minimal
  GIT_BUILD_DIR with GIT-BUILD-OPTIONS and a test-tool stub so test-lib
  can bootstrap without an actual upstream build. Supports per-script
  --run= selection and \$GO_GIT_REF for testing against an in-flight
  go-git ref (with go.mod/go.sum snapshot/restore).
- Interactive runs preserve upstream's coloured output by skipping the
  per-test TAP tee when stdout is a TTY; CI still captures TAP for
  artifact upload.
- make conformance target plus CI matrix job across ubuntu-latest,
  macos-latest, windows-latest.

Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
Extends the conformance gate to cover pack-file processing.

- gogit cat-file: -e <oid> existence check (exit 0/1, no output) and
  --batch-check (stdin OIDs -> "<oid> <type> <size>" or "<oid> missing").
- gogit index-pack --stdin [--strict]: reads a pack from stdin and writes
  pack-<sha>.{pack,idx} into .git/objects/pack/ via go-git's
  WritePackfileToObjectStorage. --strict scans the pack with a
  WithScannerObservers-attached observer and rejects packs containing
  duplicate object IDs before any state is written.
- Harness test-tool stub gains sha1/sha256 [-b] cases (used by
  t/lib-pack.sh to compute pack trailers) and is now rewritten on every
  run so script changes take effect without manual cache invalidation.
- conformance/tests.txt: append t5308-pack-detect-duplicates.sh.

Assisted-by: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: Paulo Gomes <paulo@entire.io>
@pjbgf pjbgf force-pushed the conformance-tests branch from 8b94c5a to b2d403d Compare May 12, 2026 20:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a conformance-test harness that runs curated upstream git/git test scripts against gogit (go-git–backed CLI), expanding the CLI feature surface to match the needs of the first imported test suites.

Changes:

  • Introduces conformance/run.sh + conformance/tests.txt and a make conformance target (with CI job + TAP artifact upload on failure).
  • Adds minimal gogit commands/flags needed by the initial upstream tests (e.g., init, add, commit, checkout, cat-file, index-pack, version, --exec-path, root no-args exit behavior) plus unit tests.
  • Updates go-git/go-git-fixtures (and x/net indirect) versions to support the new behavior/tests.

Reviewed changes

Copilot reviewed 23 out of 25 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Makefile Adds conformance target to run the harness.
go.mod Bumps go-git/go-git-fixtures versions; updates x/net indirect.
go.sum Updates dependency sums for the version bumps.
conformance/tests.txt Defines curated upstream test scripts to run.
conformance/run.sh Implements the conformance runner (build gogit, fetch upstream git tests, stub test-tool, run tests, capture TAP).
cmd/gogit/main.go Adds root behavior for conformance (--exec-path, exit code 1 on no subcommand) and sets a version string.
cmd/gogit/main_test.go Adds integration-style tests that execute the built gogit binary.
cmd/gogit/version.go Adds version subcommand with --build-options output.
cmd/gogit/version_test.go Tests version --build-options output.
cmd/gogit/init.go Adds init command (with --template compatibility flag).
cmd/gogit/init_test.go Tests init and ignored --template.
cmd/gogit/add.go Adds add command.
cmd/gogit/add_test.go Tests add behavior.
cmd/gogit/commit.go Adds commit command with env-based identity/date handling.
cmd/gogit/commit_test.go Tests committing with env identity values.
cmd/gogit/checkout.go Adds checkout <tree-ish> -- <pathspec>... restore behavior and directory expansion.
cmd/gogit/checkout_test.go Tests restoring files/dirs and pathspec escape failure.
cmd/gogit/checkout_pathspec.go Implements pathspec resolution relative to worktree root with escape prevention.
cmd/gogit/checkout_pathspec_test.go Unit tests for pathspec resolution.
cmd/gogit/cat-file.go Adds cat-file -e and cat-file --batch-check.
cmd/gogit/cat-file_test.go Tests cat-file existence and batch-check output.
cmd/gogit/index-pack.go Adds index-pack --stdin [--strict] with duplicate detection in strict mode.
cmd/gogit/index-pack_test.go Tests strict/non-strict behavior using constructed pack data.
.gitignore Ignores conformance cache directory.
.github/workflows/build.yml Adds a conformance job (matrix) and an optional go_git_ref workflow input.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/gogit/commit.go Outdated
Comment thread cmd/gogit/main_test.go
Comment thread cmd/gogit/index-pack.go
Comment thread Makefile
pjbgf added 2 commits May 13, 2026 09:40
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
Signed-off-by: Paulo Gomes <pjbgf@linux.com>
@pjbgf pjbgf merged commit 286484d into main May 13, 2026
7 checks passed
@pjbgf pjbgf deleted the conformance-tests branch May 13, 2026 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants