@ -16,15 +16,15 @@ import (
)
// ForkRepository forks a repository
func ForkRepository ( doer , owner * models . User , oldRepo * models . Repository , name , desc string ) ( _ * models . Repository , err error ) {
forkedRepo , err := old Repo . GetUserFork ( owner . ID )
func ForkRepository ( doer , owner * models . User , opts models . ForkRepoOptions ) ( _ * models . Repository , err error ) {
forkedRepo , err := opts . Base Repo . GetUserFork ( owner . ID )
if err != nil {
return nil , err
}
if forkedRepo != nil {
return nil , models . ErrForkAlreadyExist {
Uname : owner . Name ,
RepoName : old Repo . FullName ( ) ,
RepoName : opts . Base Repo . FullName ( ) ,
ForkName : forkedRepo . FullName ( ) ,
}
}
@ -33,17 +33,17 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
OwnerID : owner . ID ,
Owner : owner ,
OwnerName : owner . Name ,
Name : n ame,
LowerName : strings . ToLower ( n ame) ,
Description : desc ,
DefaultBranch : old Repo . DefaultBranch ,
IsPrivate : old Repo . IsPrivate || old Repo . Owner . Visibility == structs . VisibleTypePrivate ,
IsEmpty : old Repo . IsEmpty ,
Name : opts . N ame,
LowerName : strings . ToLower ( opts . N ame) ,
Description : opts . Description ,
DefaultBranch : opts . Base Repo . DefaultBranch ,
IsPrivate : opts . Base Repo . IsPrivate || opts . Base Repo . Owner . Visibility == structs . VisibleTypePrivate ,
IsEmpty : opts . Base Repo . IsEmpty ,
IsFork : true ,
ForkID : old Repo . ID ,
ForkID : opts . Base Repo . ID ,
}
oldRepoPath := old Repo . RepoPath ( )
oldRepoPath := opts . Base Repo . RepoPath ( )
err = models . WithTx ( func ( ctx models . DBContext ) error {
if err = models . CreateRepository ( ctx , doer , owner , repo , false ) ; err != nil {
@ -59,13 +59,13 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
}
}
if err = models . IncrementRepoForkNum ( ctx , old Repo . ID ) ; err != nil {
if err = models . IncrementRepoForkNum ( ctx , opts . Base Repo . ID ) ; err != nil {
rollbackRemoveFn ( )
return err
}
// copy lfs files failure should not be ignored
if err := models . CopyLFS ( ctx , repo , old Repo ) ; err != nil {
if err := models . CopyLFS ( ctx , repo , opts . Base Repo ) ; err != nil {
rollbackRemoveFn ( )
return err
}
@ -73,9 +73,9 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
repoPath := models . RepoPath ( owner . Name , repo . Name )
if stdout , err := git . NewCommand (
"clone" , "--bare" , oldRepoPath , repoPath ) .
SetDescription ( fmt . Sprintf ( "ForkRepository(git clone): %s to %s" , old Repo . FullName ( ) , repo . FullName ( ) ) ) .
SetDescription ( fmt . Sprintf ( "ForkRepository(git clone): %s to %s" , opts . Base Repo . FullName ( ) , repo . FullName ( ) ) ) .
RunInDirTimeout ( 10 * time . Minute , "" ) ; err != nil {
log . Error ( "Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v" , repo , old Repo , stdout , err )
log . Error ( "Fork Repository (git clone) Failed for %v (from %v):\nStdout: %s\nError: %v" , repo , opts . Base Repo , stdout , err )
rollbackRemoveFn ( )
return fmt . Errorf ( "git clone: %v" , err )
}
@ -103,7 +103,7 @@ func ForkRepository(doer, owner *models.User, oldRepo *models.Repository, name,
if err = repo . UpdateSize ( ctx ) ; err != nil {
log . Error ( "Failed to update size for repository: %v" , err )
}
if err := models . CopyLanguageStat ( old Repo , repo ) ; err != nil {
if err := models . CopyLanguageStat ( opts . Base Repo , repo ) ; err != nil {
log . Error ( "Copy language stat from oldRepo failed" )
}