30
30
wikiWorkingPool = sync .NewExclusivePool ()
31
31
)
32
32
33
+ const (
34
+ DefaultRemote = "origin"
35
+ DefaultBranch = "master"
36
+ )
37
+
33
38
func nameAllowed (name string ) error {
34
39
if util .IsStringInSlice (name , reservedWikiNames ) {
35
40
return repo_model.ErrWikiReservedName {
@@ -81,7 +86,7 @@ func InitWiki(ctx context.Context, repo *repo_model.Repository) error {
81
86
return fmt .Errorf ("InitRepository: %v" , err )
82
87
} else if err = repo_module .CreateDelegateHooks (repo .WikiPath ()); err != nil {
83
88
return fmt .Errorf ("createDelegateHooks: %v" , err )
84
- } else if _ , _ , err = git .NewCommand (ctx , "symbolic-ref" , "HEAD" , git .BranchPrefix + "master" ).RunStdString (& git.RunOpts {Dir : repo .WikiPath ()}); err != nil {
89
+ } else if _ , _ , err = git .NewCommand (ctx , "symbolic-ref" , "HEAD" , git .BranchPrefix + DefaultBranch ).RunStdString (& git.RunOpts {Dir : repo .WikiPath ()}); err != nil {
85
90
return fmt .Errorf ("unable to set default wiki branch to master: %v" , err )
86
91
}
87
92
return nil
@@ -94,7 +99,7 @@ func prepareWikiFileName(gitRepo *git.Repository, wikiName string) (bool, string
94
99
escaped := NameToFilename (wikiName )
95
100
96
101
// Look for both files
97
- filesInIndex , err := gitRepo .LsTree ("master" , unescaped , escaped )
102
+ filesInIndex , err := gitRepo .LsTree (DefaultBranch , unescaped , escaped )
98
103
if err != nil {
99
104
if strings .Contains (err .Error (), "Not a valid object name master" ) {
100
105
return false , escaped , nil
@@ -130,7 +135,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
130
135
return fmt .Errorf ("InitWiki: %v" , err )
131
136
}
132
137
133
- hasMasterBranch := git .IsBranchExist (ctx , repo .WikiPath (), "master" )
138
+ hasMasterBranch := git .IsBranchExist (ctx , repo .WikiPath (), DefaultBranch )
134
139
135
140
basePath , err := repo_module .CreateTemporaryPath ("update-wiki" )
136
141
if err != nil {
@@ -148,7 +153,7 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
148
153
}
149
154
150
155
if hasMasterBranch {
151
- cloneOpts .Branch = "master"
156
+ cloneOpts .Branch = DefaultBranch
152
157
}
153
158
154
159
if err := git .Clone (ctx , repo .WikiPath (), basePath , cloneOpts ); err != nil {
@@ -246,8 +251,8 @@ func updateWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
246
251
}
247
252
248
253
if err := git .Push (gitRepo .Ctx , basePath , git.PushOptions {
249
- Remote : "origin" ,
250
- Branch : fmt .Sprintf ("%s:%s%s" , commitHash .String (), git .BranchPrefix , "master" ),
254
+ Remote : DefaultRemote ,
255
+ Branch : fmt .Sprintf ("%s:%s%s" , commitHash .String (), git .BranchPrefix , DefaultBranch ),
251
256
Env : repo_module .FullPushingEnvironment (
252
257
doer ,
253
258
doer ,
@@ -299,7 +304,7 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
299
304
if err := git .Clone (ctx , repo .WikiPath (), basePath , git.CloneRepoOptions {
300
305
Bare : true ,
301
306
Shared : true ,
302
- Branch : "master" ,
307
+ Branch : DefaultBranch ,
303
308
}); err != nil {
304
309
log .Error ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
305
310
return fmt .Errorf ("Failed to clone repository: %s (%v)" , repo .FullName (), err )
@@ -360,8 +365,8 @@ func DeleteWikiPage(ctx context.Context, doer *user_model.User, repo *repo_model
360
365
}
361
366
362
367
if err := git .Push (gitRepo .Ctx , basePath , git.PushOptions {
363
- Remote : "origin" ,
364
- Branch : fmt .Sprintf ("%s:%s%s" , commitHash .String (), git .BranchPrefix , "master" ),
368
+ Remote : DefaultRemote ,
369
+ Branch : fmt .Sprintf ("%s:%s%s" , commitHash .String (), git .BranchPrefix , DefaultBranch ),
365
370
Env : repo_module .PushingEnvironment (doer , repo ),
366
371
}); err != nil {
367
372
if git .IsErrPushOutOfDate (err ) || git .IsErrPushRejected (err ) {
0 commit comments