diff options
author | Gusted <williamzijl7@hotmail.com> | 2022-01-23 21:46:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-23 21:46:09 +0000 |
commit | 42991dc89a7f3dadb7ad3b36d18b1a74628ec272 (patch) | |
tree | 82b22104610a0e6b117f34d1e32d18db6a5b6146 /modules | |
parent | 160de9fbdac41580b9cba88061bfaf1b3324d5a8 (diff) | |
download | gitea-42991dc89a7f3dadb7ad3b36d18b1a74628ec272.tar.gz gitea-42991dc89a7f3dadb7ad3b36d18b1a74628ec272.zip |
Fix partial cloning a repo (#18373) (#18377)
* Fix partial cloning a repo (#18373)
- Backport from: #18373
- Backport isn't 1-1, because the frontport had a refactor in that area,
which v1.16 doesn't have.
* Include diff & use copy
* Add partial clone test
* patch
* Apply suggestions from code review
* globalArgs first
* avoid copy but make GlobalCMDArgs append first
* please linter
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/diff.go | 15 | ||||
-rw-r--r-- | modules/git/repo.go | 5 |
2 files changed, 12 insertions, 8 deletions
diff --git a/modules/git/diff.go b/modules/git/diff.go index f90f911be0..8ca58b4809 100644 --- a/modules/git/diff.go +++ b/modules/git/diff.go @@ -59,27 +59,28 @@ func GetRepoRawDiffForFile(repo *Repository, startCommit, endCommit string, diff ctx, _, finished := process.GetManager().AddContext(repo.Ctx, fmt.Sprintf("GetRawDiffForFile: [repo_path: %s]", repo.Path)) defer finished() - var cmd *exec.Cmd + cmd := exec.CommandContext(ctx, GitExecutable, GlobalCommandArgs...) + switch diffType { case RawDiffNormal: if len(startCommit) != 0 { - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"diff", "-M", startCommit, endCommit}, fileArgs...)...) } else if commit.ParentCount() == 0 { - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"show", endCommit}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"show", endCommit}, fileArgs...)...) } else { c, _ := commit.Parent(0) - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"diff", "-M", c.ID.String(), endCommit}, fileArgs...)...) } case RawDiffPatch: if len(startCommit) != 0 { query := fmt.Sprintf("%s...%s", endCommit, startCommit) - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"format-patch", "--no-signature", "--stdout", "--root", query}, fileArgs...)...) } else if commit.ParentCount() == 0 { - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"format-patch", "--no-signature", "--stdout", "--root", endCommit}, fileArgs...)...) } else { c, _ := commit.Parent(0) query := fmt.Sprintf("%s...%s", endCommit, c.ID.String()) - cmd = exec.CommandContext(ctx, GitExecutable, append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)...) + cmd.Args = append(cmd.Args, append([]string{"format-patch", "--no-signature", "--stdout", query}, fileArgs...)...) } default: return fmt.Errorf("invalid diffType: %s", diffType) diff --git a/modules/git/repo.go b/modules/git/repo.go index b19e80cd44..47e46de3aa 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -101,6 +101,7 @@ type CloneRepoOptions struct { Shared bool NoCheckout bool Depth int + Filter string } // Clone clones original repository to target path. @@ -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) } |