-
Notifications
You must be signed in to change notification settings - Fork 4
Add conformance tests based on upstream Git #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ba19e5e
build: Bump go-git
pjbgf 860b070
conformance: add upstream Git test harness with t2008 gate
pjbgf b2d403d
conformance: graduate t5308-pack-detect-duplicates
pjbgf 8b32350
build: Fix MacOS/Windows issues
pjbgf b867657
Fix timezone parsing
pjbgf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| build/ | ||
| conformance/.cache/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/go-git/go-git/v6" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(addCmd) | ||
| } | ||
|
|
||
| var addCmd = &cobra.Command{ | ||
| Use: "add <pathspec>...", | ||
| Short: "Add file contents to the index", | ||
| Args: cobra.MinimumNArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| r, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open repository: %w", err) | ||
| } | ||
|
|
||
| w, err := r.Worktree() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open worktree: %w", err) | ||
| } | ||
|
|
||
| for _, path := range args { | ||
| if _, err := w.Add(path); err != nil { | ||
| return fmt.Errorf("failed to add %s: %w", path, err) | ||
| } | ||
| } | ||
|
|
||
| return nil | ||
| }, | ||
| DisableFlagsInUseLine: true, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestAddSingleFile(t *testing.T) { | ||
| t.Parallel() | ||
| repo := t.TempDir() | ||
|
|
||
| if _, _, err := runGogit(t, repo, "init"); err != nil { | ||
| t.Fatalf("init: %v", err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(filepath.Join(repo, "file0"), []byte("base\n"), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if _, _, err := runGogit(t, repo, "add", "file0"); err != nil { | ||
| t.Fatalf("add: %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestAddMultiplePaths(t *testing.T) { | ||
| t.Parallel() | ||
| repo := t.TempDir() | ||
|
|
||
| if _, _, err := runGogit(t, repo, "init"); err != nil { | ||
| t.Fatalf("init: %v", err) | ||
| } | ||
|
|
||
| if err := os.MkdirAll(filepath.Join(repo, "dir1"), 0o755); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(filepath.Join(repo, "file0"), []byte("a\n"), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(filepath.Join(repo, "dir1", "file1"), []byte("b\n"), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if _, _, err := runGogit(t, repo, "add", "file0", "dir1/file1"); err != nil { | ||
| t.Fatalf("add: %v", err) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bufio" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/go-git/go-git/v6" | ||
| "github.com/go-git/go-git/v6/plumbing" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| catFileExists bool | ||
| catFileBatchCheck bool | ||
| ) | ||
|
|
||
| func init() { | ||
| catFileCmd.Flags().BoolVarP(&catFileExists, "exists", "e", false, | ||
| "Check whether object exists; exit 0 if so, 1 otherwise") | ||
| catFileCmd.Flags().BoolVar(&catFileBatchCheck, "batch-check", false, | ||
| "Read object IDs from stdin and print <oid> <type> <size> per line (or '<oid> missing')") | ||
| rootCmd.AddCommand(catFileCmd) | ||
| } | ||
|
|
||
| var catFileCmd = &cobra.Command{ | ||
| Use: "cat-file (-e <oid> | --batch-check)", | ||
| Short: "Provide content or check existence of repository objects", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if catFileExists && catFileBatchCheck { | ||
| return errors.New("-e and --batch-check are mutually exclusive") | ||
| } | ||
|
|
||
| if !catFileExists && !catFileBatchCheck { | ||
| return errors.New("one of -e or --batch-check is required") | ||
| } | ||
|
|
||
| r, err := git.PlainOpenWithOptions(".", &git.PlainOpenOptions{DetectDotGit: true}) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to open repository: %w", err) | ||
| } | ||
|
|
||
| if catFileExists { | ||
| if len(args) != 1 { | ||
| return errors.New("-e requires exactly one <oid> argument") | ||
| } | ||
|
|
||
| return catFileExistsCheck(r, args[0]) | ||
| } | ||
|
|
||
| return catFileBatchCheckRun(cmd, r, os.Stdin) | ||
| }, | ||
| DisableFlagsInUseLine: true, | ||
| SilenceUsage: true, | ||
| SilenceErrors: true, | ||
| } | ||
|
|
||
| func catFileExistsCheck(r *git.Repository, oid string) error { | ||
| h := plumbing.NewHash(oid) | ||
| if _, err := r.Storer.EncodedObject(plumbing.AnyObject, h); err != nil { | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func catFileBatchCheckRun(cmd *cobra.Command, r *git.Repository, stdin io.Reader) error { | ||
| w := bufio.NewWriter(cmd.OutOrStdout()) | ||
| defer w.Flush() | ||
|
|
||
| scanner := bufio.NewScanner(stdin) | ||
| for scanner.Scan() { | ||
| line := strings.TrimSpace(scanner.Text()) | ||
| if line == "" { | ||
| continue | ||
| } | ||
|
|
||
| h := plumbing.NewHash(line) | ||
|
|
||
| obj, err := r.Storer.EncodedObject(plumbing.AnyObject, h) | ||
| if err != nil { | ||
| fmt.Fprintf(w, "%s missing\n", line) | ||
|
|
||
| continue | ||
| } | ||
|
|
||
| fmt.Fprintf(w, "%s %s %d\n", line, obj.Type(), obj.Size()) | ||
| } | ||
|
|
||
| return scanner.Err() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
| ) | ||
|
|
||
| const baseBlobOID = "df967b96a579e45a18b8251732d16804b2e56a55" // sha1 of "blob 5\0base\n" | ||
|
|
||
| func setupRepoWithBaseBlob(t *testing.T) string { | ||
| t.Helper() | ||
|
|
||
| repo := t.TempDir() | ||
|
|
||
| if _, _, err := runGogit(t, repo, "init"); err != nil { | ||
| t.Fatalf("init: %v", err) | ||
| } | ||
|
|
||
| if err := os.WriteFile(filepath.Join(repo, "file0"), []byte("base\n"), 0o644); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
|
|
||
| if _, _, err := runGogit(t, repo, "add", "file0"); err != nil { | ||
| t.Fatalf("add: %v", err) | ||
| } | ||
|
|
||
| if _, _, err := runGogitEnv(t, repo, gitIdentityEnv(repo), "commit", "-m", "x"); err != nil { | ||
| t.Fatalf("commit: %v", err) | ||
| } | ||
|
|
||
| return repo | ||
| } | ||
|
|
||
| func TestCatFileExistsExitsZero(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| repo := setupRepoWithBaseBlob(t) | ||
|
|
||
| if _, _, err := runGogit(t, repo, "cat-file", "-e", baseBlobOID); err != nil { | ||
| t.Fatalf("cat-file -e <existing>: expected exit 0, got %v", err) | ||
| } | ||
| } | ||
|
|
||
| func TestCatFileMissingExitsOne(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| repo := t.TempDir() | ||
|
|
||
| if _, _, err := runGogit(t, repo, "init"); err != nil { | ||
| t.Fatalf("init: %v", err) | ||
| } | ||
|
|
||
| stdout, _, err := runGogit(t, repo, "cat-file", "-e", "0000000000000000000000000000000000000000") | ||
| if err == nil { | ||
| t.Fatalf("expected non-zero exit, got success") | ||
| } | ||
|
|
||
| if stdout != "" { | ||
| t.Fatalf("expected no stdout, got %q", stdout) | ||
| } | ||
| } | ||
|
|
||
| func TestCatFileBatchCheck(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| repo := setupRepoWithBaseBlob(t) | ||
|
|
||
| const missingOID = "0000000000000000000000000000000000000000" | ||
|
|
||
| input := baseBlobOID + "\n" + missingOID + "\n" | ||
| want := baseBlobOID + " blob 5\n" + missingOID + " missing\n" | ||
|
|
||
| stdout, stderr, err := runGogitStdin(t, repo, input, "cat-file", "--batch-check") | ||
| if err != nil { | ||
| t.Fatalf("cat-file --batch-check failed: %v\nstderr: %s", err, stderr) | ||
| } | ||
|
|
||
| if stdout != want { | ||
| t.Fatalf("batch-check output mismatch:\n got: %q\nwant: %q", stdout, want) | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.