@@ -44,9 +44,10 @@ func (err ErrForkAlreadyExist) Unwrap() error {
44
44
45
45
// ForkRepoOptions contains the fork repository options
46
46
type 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
50
51
}
51
52
52
53
// ForkRepository forks a repository
@@ -70,14 +71,18 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
70
71
}
71
72
}
72
73
74
+ defaultBranch := opts .BaseRepo .DefaultBranch
75
+ if opts .SingleBranch != "" {
76
+ defaultBranch = opts .SingleBranch
77
+ }
73
78
repo := & repo_model.Repository {
74
79
OwnerID : owner .ID ,
75
80
Owner : owner ,
76
81
OwnerName : owner .Name ,
77
82
Name : opts .Name ,
78
83
LowerName : strings .ToLower (opts .Name ),
79
84
Description : opts .Description ,
80
- DefaultBranch : opts . BaseRepo . DefaultBranch ,
85
+ DefaultBranch : defaultBranch ,
81
86
IsPrivate : opts .BaseRepo .IsPrivate || opts .BaseRepo .Owner .Visibility == structs .VisibleTypePrivate ,
82
87
IsEmpty : opts .BaseRepo .IsEmpty ,
83
88
IsFork : true ,
@@ -134,9 +139,12 @@ func ForkRepository(ctx context.Context, doer, owner *user_model.User, opts Fork
134
139
135
140
needsRollback = true
136
141
142
+ cloneCmd := git .NewCommand (txCtx , "clone" , "--bare" )
143
+ if opts .SingleBranch != "" {
144
+ cloneCmd .AddArguments ("--single-branch" , "--branch" ).AddDynamicArguments (opts .SingleBranch )
145
+ }
137
146
repoPath := repo_model .RepoPath (owner .Name , repo .Name )
138
- if stdout , _ , err := git .NewCommand (txCtx ,
139
- "clone" , "--bare" ).AddDynamicArguments (oldRepoPath , repoPath ).
147
+ if stdout , _ , err := cloneCmd .AddDynamicArguments (oldRepoPath , repoPath ).
140
148
SetDescription (fmt .Sprintf ("ForkRepository(git clone): %s to %s" , opts .BaseRepo .FullName (), repo .FullName ())).
141
149
RunStdBytes (& git.RunOpts {Timeout : 10 * time .Minute }); err != nil {
142
150
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