@@ -44,9 +44,10 @@ func (err ErrForkAlreadyExist) Unwrap() error {
4444
4545// ForkRepoOptions contains the fork repository options
4646type ForkRepoOptions struct {
47- BaseRepo * repo_model.Repository
48- Name string
49- Description string
47+ BaseRepo * repo_model.Repository
48+ Name string
49+ Description string
50+ SingleBranch string
5051}
5152
5253// ForkRepository forks a repository
@@ -70,14 +71,18 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
7071 }
7172 }
7273
74+ defaultBranch := opts .BaseRepo .DefaultBranch
75+ if opts .SingleBranch != "" {
76+ defaultBranch = opts .SingleBranch
77+ }
7378 repo := & repo_model.Repository {
7479 OwnerID : owner .ID ,
7580 Owner : owner ,
7681 OwnerName : owner .Name ,
7782 Name : opts .Name ,
7883 LowerName : strings .ToLower (opts .Name ),
7984 Description : opts .Description ,
80- DefaultBranch : opts . BaseRepo . DefaultBranch ,
85+ DefaultBranch : defaultBranch ,
8186 IsPrivate : opts .BaseRepo .IsPrivate || opts .BaseRepo .Owner .Visibility == structs .VisibleTypePrivate ,
8287 IsEmpty : opts .BaseRepo .IsEmpty ,
8388 IsFork : true ,
@@ -134,9 +139,15 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
134139
135140 needsRollback = true
136141
142+ var cloneCmd * git.Command
143+ if opts .SingleBranch != "" {
144+ cloneCmd = git .NewCommand (txCtx , "clone" , "--bare" , "--single-branch" , "--branch" )
145+ cloneCmd = cloneCmd .AddDynamicArguments (opts .SingleBranch )
146+ } else {
147+ cloneCmd = git .NewCommand (txCtx , "clone" , "--bare" )
148+ }
137149 repoPath := repo_model .RepoPath (owner .Name , repo .Name )
138- if stdout , _ , err := git .NewCommand (txCtx ,
139- "clone" , "--bare" ).AddDynamicArguments (oldRepoPath , repoPath ).
150+ if stdout , _ , err := cloneCmd .AddDynamicArguments (oldRepoPath , repoPath ).
140151 SetDescription (fmt .Sprintf ("ForkRepository(git clone): %s to %s" , opts .BaseRepo .FullName (), repo .FullName ())).
141152 RunStdBytes (& git.RunOpts {Timeout : 10 * time .Minute }); err != nil {
142153 log .Error ("Fork Repository (git clone) Failed for %v (from %v):\n Stdout: %s\n Error: %v" , repo , opts .BaseRepo , stdout , err )
0 commit comments