0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-01-24 04:15:35 +01:00
This commit is contained in:
Lunny Xiao 2025-12-22 19:03:34 -08:00
parent 7228fb1498
commit b4df643ad1
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 9 additions and 1 deletions

View File

@ -186,6 +186,7 @@ func Clone(ctx context.Context, from, to string, opts CloneRepoOptions) error {
// PushOptions options when push to remote
type PushOptions struct {
Remote string
LocalBranch string
Branch string
Force bool
ForceWithLease string
@ -207,7 +208,13 @@ func Push(ctx context.Context, repoPath string, opts PushOptions) error {
}
remoteBranchArgs := []string{opts.Remote}
if len(opts.Branch) > 0 {
remoteBranchArgs = append(remoteBranchArgs, opts.Branch)
var refspec string
if opts.LocalBranch != "" {
refspec = fmt.Sprintf("%s:%s", opts.LocalBranch, opts.Branch)
} else {
refspec = opts.Branch
}
remoteBranchArgs = append(remoteBranchArgs, refspec)
}
cmd.AddDashesAndList(remoteBranchArgs...)

View File

@ -74,6 +74,7 @@ func initRepoCommit(ctx context.Context, tmpPath string, repo *repo_model.Reposi
}
if err := gitrepo.PushFromLocal(ctx, tmpPath, repo, git.PushOptions{
LocalBranch: "HEAD",
Branch: defaultBranch,
Env: repo_module.InternalPushingEnvironment(u, repo),
}); err != nil {