Skip to content
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

Fix partial cloning a repo (#18373) #18377

Merged
merged 8 commits into from
Jan 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions integrations/git_helper_for_declarative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ func doGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
}
}

func doPartialGitClone(dstLocalPath string, u *url.URL) func(*testing.T) {
return func(t *testing.T) {
assert.NoError(t, git.CloneWithArgs(context.Background(), u.String(), dstLocalPath, allowLFSFilters(), git.CloneRepoOptions{
Filter: "blob:none",
}))
exist, err := util.IsExist(filepath.Join(dstLocalPath, "README.md"))
assert.NoError(t, err)
assert.True(t, exist)
}
}

func doGitCloneFail(u *url.URL) func(*testing.T) {
return func(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "doGitCloneFail")
Expand Down
6 changes: 6 additions & 0 deletions integrations/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ func testGit(t *testing.T, u *url.URL) {

t.Run("Clone", doGitClone(dstPath, u))

dstPath2, err := os.MkdirTemp("", httpContext.Reponame)
assert.NoError(t, err)
defer util.RemoveAll(dstPath2)

t.Run("Partial Clone", doPartialGitClone(dstPath2, u))

little, big := standardCommitAndPushTest(t, dstPath)
littleLFS, bigLFS := lfsCommitAndPushTest(t, dstPath)
rawTest(t, &httpContext, little, big, littleLFS, bigLFS)
Expand Down
1 change: 1 addition & 0 deletions modules/git/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff
cmd.Dir = repo.Path
cmd.Stdout = writer
cmd.Stderr = stderr
cmd.Args = append(cmd.Args, GlobalCommandArgs...)
6543 marked this conversation as resolved.
Show resolved Hide resolved

if err = cmd.Run(); err != nil {
return fmt.Errorf("Run: %v - %s", err, stderr)
Expand Down
5 changes: 4 additions & 1 deletion modules/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ type CloneRepoOptions struct {
Shared bool
NoCheckout bool
Depth int
Filter string
}

// Clone clones original repository to target path.
Expand Down Expand Up @@ -141,7 +142,9 @@ func CloneWithArgs(ctx context.Context, from, to string, args []string, opts Clo
if opts.Depth > 0 {
cmd.AddArguments("--depth", strconv.Itoa(opts.Depth))
}

if opts.Filter != "" {
cmd.AddArguments("--filter", opts.Filter)
}
if len(opts.Branch) > 0 {
cmd.AddArguments("-b", opts.Branch)
}
Expand Down
1 change: 1 addition & 0 deletions routers/web/repo/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ func serviceRPC(h serviceHandler, service string) {
cmd := exec.CommandContext(ctx, git.GitExecutable, service, "--stateless-rpc", h.dir)
cmd.Dir = h.dir
cmd.Env = append(os.Environ(), h.environ...)
cmd.Args = append(cmd.Args, git.GlobalCommandArgs...)
Gusted marked this conversation as resolved.
Show resolved Hide resolved
6543 marked this conversation as resolved.
Show resolved Hide resolved
cmd.Stdout = h.w
cmd.Stdin = reqBody
cmd.Stderr = &stderr
Expand Down