-
Notifications
You must be signed in to change notification settings - Fork 6
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
Support clients that don't enable side-band or side-band-64k #41
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4cc80f2
If unpack does not succeed, exit with an error
spraints 9e788b5
Revert a change to pktline from #40
spraints 3d157b5
Extract a couple of methods for use later
spraints eaf8daf
Add a test that demonstrates a protocol error
spraints eff59d6
Make index-pack quieter if we're not going to use its output
spraints 1488c82
When sideband is off, send the report directly
spraints 2e77fa7
Use a file for the empty pack
spraints 1c65fc2
Don't fail is there was some data
spraints 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 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 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,120 @@ | ||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"bufio" | ||
"bytes" | ||
"context" | ||
"fmt" | ||
"io" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestNoSideBand(t *testing.T) { | ||
const ( | ||
defaultBranch = "refs/heads/main" | ||
createBranch = "refs/heads/newbranch" | ||
|
||
testCommit = "e589bdee50e39beac56220c4b7a716225f79e3cf" | ||
) | ||
|
||
wd, err := os.Getwd() | ||
require.NoError(t, err) | ||
origin := filepath.Join(wd, "testdata/remote/git-internals-fork.git") | ||
|
||
testRepo := t.TempDir() | ||
requireRun(t, "git", "init", "--bare", testRepo) | ||
requireRun(t, "git", "-C", testRepo, "fetch", origin, defaultBranch+":"+defaultBranch) | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
srp := exec.CommandContext(ctx, "spokes-receive-pack", ".") | ||
srp.Dir = testRepo | ||
srp.Env = append(os.Environ(), | ||
"GIT_SOCKSTAT_VAR_spokes_quarantine=bool:true", | ||
"GIT_SOCKSTAT_VAR_quarantine_id=config-test-quarantine-id") | ||
srp.Stderr = os.Stderr | ||
srpIn, err := srp.StdinPipe() | ||
require.NoError(t, err) | ||
srpOut, err := srp.StdoutPipe() | ||
require.NoError(t, err) | ||
|
||
srpErr := make(chan error) | ||
go func() { srpErr <- srp.Run() }() | ||
|
||
bufSRPOut := bufio.NewReader(srpOut) | ||
|
||
refs, _, err := readAdv(bufSRPOut) | ||
require.NoError(t, err) | ||
assert.Equal(t, refs, map[string]string{ | ||
defaultBranch: testCommit, | ||
}) | ||
|
||
oldnew := fmt.Sprintf("%040d %s", 0, testCommit) | ||
require.NoError(t, writePktlinef(srpIn, | ||
"%s %s\x00report-status report-status-v2 push-options object-format=sha1\n", oldnew, createBranch)) | ||
_, err = srpIn.Write([]byte("0000")) | ||
require.NoError(t, err) | ||
|
||
require.NoError(t, writePktlinef(srpIn, | ||
"anything i want to put in a push option\n")) | ||
_, err = srpIn.Write([]byte("0000")) | ||
require.NoError(t, err) | ||
|
||
// Send an empty pack, since we're using commits that are already in | ||
// the repo. | ||
pack, err := os.Open("testdata/empty.pack") | ||
require.NoError(t, err) | ||
if _, err := io.Copy(srpIn, pack); err != nil { | ||
t.Logf("error writing pack to spokes-receive-pack input: %v", err) | ||
} | ||
|
||
require.NoError(t, srpIn.Close()) | ||
|
||
lines, err := readResultNoSideBand(t, bufSRPOut) | ||
require.NoError(t, err) | ||
assert.Equal(t, []string{ | ||
"unpack ok\n", | ||
"ok refs/heads/newbranch\n", | ||
}, lines) | ||
} | ||
|
||
func readResultNoSideBand(t *testing.T, r io.Reader) ([]string, error) { | ||
var lines []string | ||
|
||
// Read all of the output so that we can include it with errors. | ||
data, err := io.ReadAll(r) | ||
if err != nil { | ||
if len(data) > 0 { | ||
t.Logf("got data, but there was an error: %v", err) | ||
} else { | ||
return nil, err | ||
} | ||
} | ||
|
||
// Replace r. | ||
r = bytes.NewReader(data) | ||
|
||
for { | ||
pkt, err := readPktline(r) | ||
switch { | ||
case err != nil: | ||
return nil, fmt.Errorf("%w while parsing %q", err, string(data)) | ||
|
||
case pkt == nil: | ||
return lines, nil | ||
|
||
default: | ||
lines = append(lines, string(pkt)) | ||
} | ||
} | ||
} |
This file contains 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 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
Binary file not shown.
This file contains 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 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change works around a similar problem to the one described in hashicorp/go-plugin#116, where there's a race between reads from a pipe and
exec.Cmd.Wait
closing the pipe after the process exits.