@@ -39,7 +39,6 @@ import (
39
39
40
40
"github.com/mcuadros/go-version"
41
41
"github.com/unknwon/com"
42
- ini "gopkg.in/ini.v1"
43
42
"xorm.io/builder"
44
43
)
45
44
@@ -941,25 +940,6 @@ func (repo *Repository) CloneLink() (cl *CloneLink) {
941
940
return repo .cloneLink (x , false )
942
941
}
943
942
944
- /*
945
- GitHub, GitLab, Gogs: *.wiki.git
946
- BitBucket: *.git/wiki
947
- */
948
- var commonWikiURLSuffixes = []string {".wiki.git" , ".git/wiki" }
949
-
950
- // wikiRemoteURL returns accessible repository URL for wiki if exists.
951
- // Otherwise, it returns an empty string.
952
- func wikiRemoteURL (remote string ) string {
953
- remote = strings .TrimSuffix (remote , ".git" )
954
- for _ , suffix := range commonWikiURLSuffixes {
955
- wikiURL := remote + suffix
956
- if git .IsRepoURLAccessible (wikiURL ) {
957
- return wikiURL
958
- }
959
- }
960
- return ""
961
- }
962
-
963
943
// CheckCreateRepository check if could created a repository
964
944
func CheckCreateRepository (doer , u * User , name string ) error {
965
945
if ! doer .CanCreateRepo () {
@@ -979,118 +959,9 @@ func CheckCreateRepository(doer, u *User, name string) error {
979
959
return nil
980
960
}
981
961
982
- // MigrateRepositoryGitData starts migrating git related data after created migrating repository
983
- func MigrateRepositoryGitData (doer , u * User , repo * Repository , opts api.MigrateRepoOption ) (* Repository , error ) {
984
- repoPath := RepoPath (u .Name , opts .RepoName )
985
-
986
- if u .IsOrganization () {
987
- t , err := u .GetOwnerTeam ()
988
- if err != nil {
989
- return nil , err
990
- }
991
- repo .NumWatches = t .NumMembers
992
- } else {
993
- repo .NumWatches = 1
994
- }
995
-
996
- migrateTimeout := time .Duration (setting .Git .Timeout .Migrate ) * time .Second
997
-
998
- var err error
999
- if err = os .RemoveAll (repoPath ); err != nil {
1000
- return repo , fmt .Errorf ("Failed to remove %s: %v" , repoPath , err )
1001
- }
1002
-
1003
- if err = git .Clone (opts .CloneAddr , repoPath , git.CloneRepoOptions {
1004
- Mirror : true ,
1005
- Quiet : true ,
1006
- Timeout : migrateTimeout ,
1007
- }); err != nil {
1008
- return repo , fmt .Errorf ("Clone: %v" , err )
1009
- }
1010
-
1011
- if opts .Wiki {
1012
- wikiPath := WikiPath (u .Name , opts .RepoName )
1013
- wikiRemotePath := wikiRemoteURL (opts .CloneAddr )
1014
- if len (wikiRemotePath ) > 0 {
1015
- if err := os .RemoveAll (wikiPath ); err != nil {
1016
- return repo , fmt .Errorf ("Failed to remove %s: %v" , wikiPath , err )
1017
- }
1018
-
1019
- if err = git .Clone (wikiRemotePath , wikiPath , git.CloneRepoOptions {
1020
- Mirror : true ,
1021
- Quiet : true ,
1022
- Timeout : migrateTimeout ,
1023
- Branch : "master" ,
1024
- }); err != nil {
1025
- log .Warn ("Clone wiki: %v" , err )
1026
- if err := os .RemoveAll (wikiPath ); err != nil {
1027
- return repo , fmt .Errorf ("Failed to remove %s: %v" , wikiPath , err )
1028
- }
1029
- }
1030
- }
1031
- }
1032
-
1033
- gitRepo , err := git .OpenRepository (repoPath )
1034
- if err != nil {
1035
- return repo , fmt .Errorf ("OpenRepository: %v" , err )
1036
- }
1037
- defer gitRepo .Close ()
1038
-
1039
- repo .IsEmpty , err = gitRepo .IsEmpty ()
1040
- if err != nil {
1041
- return repo , fmt .Errorf ("git.IsEmpty: %v" , err )
1042
- }
1043
-
1044
- if ! opts .Releases && ! repo .IsEmpty {
1045
- // Try to get HEAD branch and set it as default branch.
1046
- headBranch , err := gitRepo .GetHEADBranch ()
1047
- if err != nil {
1048
- return repo , fmt .Errorf ("GetHEADBranch: %v" , err )
1049
- }
1050
- if headBranch != nil {
1051
- repo .DefaultBranch = headBranch .Name
1052
- }
1053
-
1054
- if err = SyncReleasesWithTags (repo , gitRepo ); err != nil {
1055
- log .Error ("Failed to synchronize tags to releases for repository: %v" , err )
1056
- }
1057
- }
1058
-
1059
- if err = repo .UpdateSize (); err != nil {
1060
- log .Error ("Failed to update size for repository: %v" , err )
1061
- }
1062
-
1063
- if opts .Mirror {
1064
- if _ , err = x .InsertOne (& Mirror {
1065
- RepoID : repo .ID ,
1066
- Interval : setting .Mirror .DefaultInterval ,
1067
- EnablePrune : true ,
1068
- NextUpdateUnix : timeutil .TimeStampNow ().AddDuration (setting .Mirror .DefaultInterval ),
1069
- }); err != nil {
1070
- return repo , fmt .Errorf ("InsertOne: %v" , err )
1071
- }
1072
-
1073
- repo .IsMirror = true
1074
- err = UpdateRepository (repo , false )
1075
- } else {
1076
- repo , err = CleanUpMigrateInfo (repo )
1077
- }
1078
-
1079
- return repo , err
1080
- }
1081
-
1082
- // cleanUpMigrateGitConfig removes mirror info which prevents "push --all".
1083
- // This also removes possible user credentials.
1084
- func cleanUpMigrateGitConfig (configPath string ) error {
1085
- cfg , err := ini .Load (configPath )
1086
- if err != nil {
1087
- return fmt .Errorf ("open config file: %v" , err )
1088
- }
1089
- cfg .DeleteSection ("remote \" origin\" " )
1090
- if err = cfg .SaveToIndent (configPath , "\t " ); err != nil {
1091
- return fmt .Errorf ("save config file: %v" , err )
1092
- }
1093
- return nil
962
+ // CreateDelegateHooks creates all the hooks scripts for the repo
963
+ func CreateDelegateHooks (repoPath string ) error {
964
+ return createDelegateHooks (repoPath )
1094
965
}
1095
966
1096
967
// createDelegateHooks creates all the hooks scripts for the repo
@@ -1132,32 +1003,6 @@ func createDelegateHooks(repoPath string) (err error) {
1132
1003
return nil
1133
1004
}
1134
1005
1135
- // CleanUpMigrateInfo finishes migrating repository and/or wiki with things that don't need to be done for mirrors.
1136
- func CleanUpMigrateInfo (repo * Repository ) (* Repository , error ) {
1137
- repoPath := repo .RepoPath ()
1138
- if err := createDelegateHooks (repoPath ); err != nil {
1139
- return repo , fmt .Errorf ("createDelegateHooks: %v" , err )
1140
- }
1141
- if repo .HasWiki () {
1142
- if err := createDelegateHooks (repo .WikiPath ()); err != nil {
1143
- return repo , fmt .Errorf ("createDelegateHooks.(wiki): %v" , err )
1144
- }
1145
- }
1146
-
1147
- _ , err := git .NewCommand ("remote" , "rm" , "origin" ).RunInDir (repoPath )
1148
- if err != nil && ! strings .HasPrefix (err .Error (), "exit status 128 - fatal: No such remote " ) {
1149
- return repo , fmt .Errorf ("CleanUpMigrateInfo: %v" , err )
1150
- }
1151
-
1152
- if repo .HasWiki () {
1153
- if err := cleanUpMigrateGitConfig (path .Join (repo .WikiPath (), "config" )); err != nil {
1154
- return repo , fmt .Errorf ("cleanUpMigrateGitConfig (wiki): %v" , err )
1155
- }
1156
- }
1157
-
1158
- return repo , UpdateRepository (repo , false )
1159
- }
1160
-
1161
1006
// initRepoCommit temporarily changes with work directory.
1162
1007
func initRepoCommit (tmpPath string , u * User ) (err error ) {
1163
1008
commitTimeStr := time .Now ().Format (time .RFC3339 )
0 commit comments