mirror of
https://github.com/go-gitea/gitea
synced 2025-09-18 14:48:13 +00:00
Move git command to git/gitcmd (#35483)
The name cmd is already used in many places and may cause conflicts, so I chose `gitcmd` instead to minimize potential naming conflicts.
This commit is contained in:
@@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
)
|
||||
|
||||
@@ -55,12 +56,12 @@ func runGitDiffTree(ctx context.Context, gitRepo *git.Repository, useMergeBase b
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmd := git.NewCommand("diff-tree", "--raw", "-r", "--find-renames", "--root")
|
||||
cmd := gitcmd.NewCommand("diff-tree", "--raw", "-r", "--find-renames", "--root")
|
||||
if useMergeBase {
|
||||
cmd.AddArguments("--merge-base")
|
||||
}
|
||||
cmd.AddDynamicArguments(baseCommitID, headCommitID)
|
||||
stdout, _, runErr := cmd.RunStdString(ctx, &git.RunOpts{Dir: gitRepo.Path})
|
||||
stdout, _, runErr := cmd.RunStdString(ctx, &gitcmd.RunOpts{Dir: gitRepo.Path})
|
||||
if runErr != nil {
|
||||
log.Warn("git diff-tree: %v", runErr)
|
||||
return nil, runErr
|
||||
|
@@ -26,6 +26,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/charset"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/git/attribute"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/highlight"
|
||||
"code.gitea.io/gitea/modules/lfs"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
@@ -1090,7 +1091,7 @@ type DiffOptions struct {
|
||||
MaxLines int
|
||||
MaxLineCharacters int
|
||||
MaxFiles int
|
||||
WhitespaceBehavior git.TrustedCmdArgs
|
||||
WhitespaceBehavior gitcmd.TrustedCmdArgs
|
||||
DirectComparison bool
|
||||
}
|
||||
|
||||
@@ -1131,7 +1132,7 @@ func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOption
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
||||
cmdDiff := git.NewCommand().
|
||||
cmdDiff := gitcmd.NewCommand().
|
||||
AddArguments("diff", "--src-prefix=\\a/", "--dst-prefix=\\b/", "-M").
|
||||
AddArguments(opts.WhitespaceBehavior...)
|
||||
|
||||
@@ -1158,7 +1159,7 @@ func getDiffBasic(ctx context.Context, gitRepo *git.Repository, opts *DiffOption
|
||||
|
||||
go func() {
|
||||
stderr := &bytes.Buffer{}
|
||||
if err := cmdDiff.Run(cmdCtx, &git.RunOpts{
|
||||
if err := cmdDiff.Run(cmdCtx, &gitcmd.RunOpts{
|
||||
Timeout: time.Duration(setting.Git.Timeout.Default) * time.Second,
|
||||
Dir: repoPath,
|
||||
Stdout: writer,
|
||||
@@ -1395,8 +1396,8 @@ func CommentMustAsDiff(ctx context.Context, c *issues_model.Comment) *Diff {
|
||||
}
|
||||
|
||||
// GetWhitespaceFlag returns git diff flag for treating whitespaces
|
||||
func GetWhitespaceFlag(whitespaceBehavior string) git.TrustedCmdArgs {
|
||||
whitespaceFlags := map[string]git.TrustedCmdArgs{
|
||||
func GetWhitespaceFlag(whitespaceBehavior string) gitcmd.TrustedCmdArgs {
|
||||
whitespaceFlags := map[string]gitcmd.TrustedCmdArgs{
|
||||
"ignore-all": {"-w"},
|
||||
"ignore-change": {"-b"},
|
||||
"ignore-eol": {"--ignore-space-at-eol"},
|
||||
|
@@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/models/unittest"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/git/gitcmd"
|
||||
"code.gitea.io/gitea/modules/json"
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
|
||||
@@ -602,7 +603,7 @@ func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
defer gitRepo.Close()
|
||||
for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
|
||||
for _, behavior := range []gitcmd.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
|
||||
diffs, err := GetDiffForAPI(t.Context(), gitRepo,
|
||||
&DiffOptions{
|
||||
AfterCommitID: "d8e0bbb45f200e67d9a784ce55bd90821af45ebd",
|
||||
|
Reference in New Issue
Block a user