mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-10 16:52:33 +00:00
refactor: remove unnecessary git command wrapper functions (#38531)
Removed `gitrepo.RunCmd*` functions, because gitcmd.Command works with Repository directly. Move some "local filesystem" related function into "localfs.go"
This commit is contained in:
@@ -316,7 +316,7 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
|
||||
// Check if the pull request is merged into BaseBranch
|
||||
cmd := gitcmd.NewCommand("merge-base", "--is-ancestor").AddDynamicArguments(prHeadRef, pr.BaseBranch)
|
||||
if err := gitrepo.RunCmdWithStderr(ctx, pr.BaseRepo, cmd); err != nil {
|
||||
if err := cmd.WithRepo(pr.BaseRepo).RunWithStderr(ctx); err != nil {
|
||||
if gitcmd.IsErrorExitCode(err, 1) {
|
||||
// prHeadRef is not an ancestor of the base branch
|
||||
return nil, nil //nolint:nilnil // return nil to indicate that the PR head is not merged
|
||||
@@ -346,9 +346,8 @@ func getMergeCommit(ctx context.Context, pr *issues_model.PullRequest) (*git.Com
|
||||
// rev-list returns one line per merge commit on the ancestry path; we
|
||||
// only want the first one (the oldest, with --reverse, i.e. the merge
|
||||
// commit that actually introduced this PR).
|
||||
mergeCommit, _, err := gitrepo.RunCmdString(ctx, pr.BaseRepo,
|
||||
gitcmd.NewCommand("rev-list", "--ancestry-path", "--merges", "--reverse").
|
||||
AddDynamicArguments(prHeadCommitID+".."+pr.BaseBranch))
|
||||
mergeCommit, _, err := gitcmd.NewCommand("rev-list", "--ancestry-path", "--merges", "--reverse").
|
||||
AddDynamicArguments(prHeadCommitID + ".." + pr.BaseBranch).WithRepo(pr.BaseRepo).RunStdString(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("git rev-list --ancestry-path --merges --reverse: %w", err)
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ func checkConflictsMergeTree(ctx context.Context, pr *issues_model.PullRequest,
|
||||
// Detect whether the pull request introduces changes by comparing the merged tree (treeHash)
|
||||
// against the current base commit (baseCommitID) using `git diff-tree`. The command returns exit code 0
|
||||
// if there is no diff between these trees (empty patch) and exit code 1 if there is a diff.
|
||||
gitErr := gitrepo.RunCmd(ctx, pr.BaseRepo, gitcmd.NewCommand("diff-tree", "-r", "--quiet").
|
||||
AddDynamicArguments(treeHash, baseCommitID))
|
||||
gitErr := gitcmd.NewCommand("diff-tree", "-r", "--quiet").
|
||||
AddDynamicArguments(treeHash, baseCommitID).WithRepo(pr.BaseRepo).Run(ctx)
|
||||
switch {
|
||||
case gitErr == nil:
|
||||
log.Debug("PullRequest[%d]: Patch is empty - ignoring", pr.ID)
|
||||
|
||||
@@ -586,7 +586,7 @@ func pushToBaseRepoHelper(ctx context.Context, pr *issues_model.PullRequest, pre
|
||||
|
||||
gitRefName := pr.GetGitHeadRefName()
|
||||
|
||||
if err := gitrepo.Push(ctx, pr.HeadRepo, pr.BaseRepo, git.PushOptions{
|
||||
if err := gitrepo.PushManaged(ctx, pr.HeadRepo, pr.BaseRepo, git.PushOptions{
|
||||
Branch: prefixHeadBranch + pr.HeadBranch + ":" + gitRefName,
|
||||
Force: true,
|
||||
// Use InternalPushingEnvironment here because we know that pre-receive and post-receive do not run on a refs/pulls/...
|
||||
|
||||
Reference in New Issue
Block a user