Просмотр исходного кода

Mirror repository should not allow fork

Unknwon лет назад: 8
Родитель
Сommit
119dec51f2
5 измененных файлов с 9 добавлено и 6 удалено
  1. 0 1
      .bra.toml
  2. 5 0
      models/repo.go
  3. 2 3
      routers/repo/pull.go
  4. 1 1
      templates/repo/header.tmpl
  5. 1 1
      templates/repo/header_old.tmpl

+ 0 - 1
.bra.toml

@@ -13,7 +13,6 @@ watch_dirs = [
 watch_exts = [".go"]
 build_delay = 1500
 cmds = [
-	#["go-bindata", "-o=modules/bindata/bindata.go", "-ignore=\\.DS_Store|README", "-pkg=bindata", "conf/..."],
 	["go", "install", "-tags", "sqlite"],# redis memcache cert pam
 	["go", "build", "-tags", "sqlite"],
 	["./gogs", "web"]

+ 5 - 0
models/repo.go

@@ -272,6 +272,11 @@ func (repo *Repository) IsOwnedBy(userID int64) bool {
 	return repo.OwnerID == userID
 }
 
+// CanBeForked returns true if repository meets the requirements of being forked.
+func (repo *Repository) CanBeForked() bool {
+	return !repo.IsBare && !repo.IsMirror
+}
+
 func (repo *Repository) NextIssueIndex() int64 {
 	return int64(repo.NumIssues+repo.NumPulls) + 1
 }

+ 2 - 3
routers/repo/pull.go

@@ -38,9 +38,8 @@ func getForkRepository(ctx *middleware.Context) *models.Repository {
 		return nil
 	}
 
-	// Cannot fork bare repo.
-	if forkRepo.IsBare {
-		ctx.Handle(404, "", nil)
+	if !forkRepo.CanBeForked() {
+		ctx.Handle(404, "getForkRepository", nil)
 		return nil
 	}
 

+ 1 - 1
templates/repo/header.tmpl

@@ -29,7 +29,7 @@
 					    {{.NumStars}}
 					  </a>
 					</div>
-					{{if not .IsBare}}
+					{{if .CanBeForked}}
 					<div class="ui labeled button" tabindex="0">
 					  <a class="ui grey button {{if eq .OwnerID $.SignedUserID}}poping up{{end}}" {{if not (eq .OwnerID $.SignedUserID)}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{else}} data-content="{{$.i18n.Tr "repo.fork_from_self"}}" data-position="top center" data-variation="tiny"{{end}}>
 					    <i class="icon octicon octicon-repo-forked"></i>{{$.i18n.Tr "repo.fork"}}

+ 1 - 1
templates/repo/header_old.tmpl

@@ -48,7 +48,7 @@
                     </button>
                 </a>
             </li>
-            {{if not .IsBare}}
+            {{if .CanBeForked}}
             <li id="repo-header-fork">
                 <a id="repo-header-fork-btn" {{if or (not $.IsRepositoryAdmin) $.Owner.IsOrganization}}href="{{AppSubUrl}}/repo/fork/{{.ID}}"{{end}}>
                     <button class="btn btn-gray text-bold btn-radius">