Browse Source

Fixes per Unknwon's requests

pull/3287/head
Richard Mahn 9 years ago
parent
commit
c2895dc742
  1. 8
      cmd/web.go
  2. 12
      conf/app.ini
  3. 14
      conf/locale/locale_en-US.ini
  4. 2
      models/error.go
  5. 1
      models/issue.go
  6. 30
      models/repo.go
  7. 1
      models/working_pool.go
  8. 3
      modules/auth/repo_form.go
  9. 6
      routers/repo/branch.go
  10. 4
      routers/repo/delete.go
  11. 18
      routers/repo/edit.go
  12. 12
      routers/repo/upload.go
  13. 4
      routers/repo/view.go

8
cmd/web.go

@ -494,17 +494,17 @@ func runWeb(ctx *cli.Context) error {
Post(bindIgnErr(auth.CreateIssueForm{}), repo.CompareAndPullRequestPost)
m.Group("", func() {
m.Combo("/edit/*").Get(repo.EditFile).
m.Combo("/_edit/*").Get(repo.EditFile).
Post(bindIgnErr(auth.EditRepoFileForm{}), repo.EditFilePost)
m.Combo("/new/*").Get(repo.EditNewFile).
Post(bindIgnErr(auth.EditRepoFileForm{}), repo.EditNewFilePost)
m.Combo("/_new/*").Get(repo.NewFile).
Post(bindIgnErr(auth.EditRepoFileForm{}), repo.NewFilePost)
m.Post("/preview/*", bindIgnErr(auth.EditPreviewDiffForm{}), repo.DiffPreviewPost)
m.Combo("/upload/*").Get(repo.UploadFile).
Post(bindIgnErr(auth.UploadRepoFileForm{}), repo.UploadFilePost)
m.Post("/delete/*", bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
m.Post("/branches", bindIgnErr(auth.NewBranchForm{}), repo.NewBranchPost)
m.Post("/upload-file", repo.UploadFileToServer)
m.Post("/upload-remove", bindIgnErr(auth.UploadRemoveFileForm{}), repo.UploadRemoveFileFromServer)
m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
}, context.RepoRef(), context.RepoAssignment(), reqRepoWriter)
}, reqSignIn, context.RepoAssignment(), repo.MustBeNotBare)

12
conf/app.ini

@ -23,22 +23,22 @@ PULL_REQUEST_QUEUE_LENGTH = 10000
[editor]
; List of file extensions that should have line wraps in the CodeMirror editor
; Separate extensions with a comma. To line wrap files w/o extension, just put a comma
LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,,
LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,
; Valid file modes that have a preview API associated with them, such as api/v1/markdown
; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
PREVIEW_TAB_APIS = markdown
[upload]
; Whether uploads are enabled. Defaults to `true`
; Whether repository file uploads are enabled. Defaults to `true`
ENABLE_UPLOADS = true
; Path for uploads. Defaults to `data/tmp/uploads` (tmp gets deleted on gogs restart)
UPLOAD_TEMP_PATH = data/tmp/uploads
TEMP_PATH = data/tmp/uploads
; One or more allowed types, e.g. image/jpeg|image/png. Nothing means any file type
UPLOAD_ALLOWED_TYPES =
ALLOWED_TYPES =
; Max size of each file in MB. Defaults to 32MB
UPLOAD_FILE_MAX_SIZE = 32
FILE_MAX_SIZE = 32
; Max number of files per upload. Defaults to 10
UPLOAD_MAX_FILES = 10
MAX_FILES = 10
[ui]
; Number of repositories that are showed in one explore page

14
conf/locale/locale_en-US.ini

@ -428,7 +428,7 @@ new_file = New file
upload_files = Upload files
find_file = Find file
commit_changes = Commit Changes
default_commit_message = Add an optional extended description…
default_commit_message = Add an optional extended description...
last_commit_info = %s edited this file %s
delete_this_file = Delete this file
edit_this_file = Edit this file
@ -457,8 +457,8 @@ from = from
upload_file = Upload file
add_files_to_dir = Add files to %s
unable_to_upload_files = Unable to upload files, an error occurred.
add_subdir = Add subdirectory…
name_your_file = Name your file…
add_subdir = Add subdirectory...
name_your_file = Name your file...
user_has_committed_since_you_started_editing = %s has committed since you started editing.
see_what_changed = See what changed.
pressing_commit_again_will_overwrite_those_changes = Pressing '%s' again will overwrite those changes.
@ -489,7 +489,7 @@ issues.new.clear_assignee = Clear assignee
issues.new.no_assignee = No assignee
issues.create = Create Issue
issues.new_label = New Label
issues.new_label_placeholder = Label name…
issues.new_label_placeholder = Label name...
issues.create_label = Create Label
issues.open_tab = %d Open
issues.close_tab = %d Closed
@ -676,7 +676,7 @@ settings.delete_collaborator = Delete
settings.collaborator_deletion = Collaborator Deletion
settings.collaborator_deletion_desc = This user will no longer have collaboration access to this repository after deletion. Do you want to continue?
settings.remove_collaborator_success = Collaborator has been removed.
settings.search_user_placeholder = Search user…
settings.search_user_placeholder = Search user...
settings.org_not_allowed_to_be_collaborator = Organization is not allowed to be added as a collaborator.
settings.user_is_org_member = User is organization member who cannot be added as a collaborator.
settings.add_webhook = Add Webhook
@ -768,7 +768,7 @@ release.title = Title
release.content = Content
release.write = Write
release.preview = Preview
release.loading = Loading…
release.loading = Loading...
release.prerelease_desc = This is a pre-release
release.prerelease_helper = We'll point out that this release is not production-ready.
release.cancel = Cancel
@ -857,7 +857,7 @@ teams.read_permission_desc = This team grants <strong>Read</strong> access: memb
teams.write_permission_desc = This team grants <strong>Write</strong> access: members can read from and push to the team's repositories.
teams.admin_permission_desc = This team grants <strong>Admin</strong> access: members can read from, push to, and add collaborators to the team's repositories.
teams.repositories = Team Repositories
teams.search_repo_placeholder = Search repository…
teams.search_repo_placeholder = Search repository...
teams.add_team_repository = Add Team Repository
teams.remove_repo = Remove
teams.add_nonexistent_repo = The repository you're trying to add does not exist, please create it first.

2
models/error.go

@ -427,7 +427,7 @@ func IsErrRepoFileAlreadyExist(err error) bool {
}
func (err ErrRepoFileAlreadyExist) Error() string {
return fmt.Sprintf("Repo file already exists [file name: %s]", err.FileName)
return fmt.Sprintf("repository file already exists [file name: %s]", err.FileName)
}
// __________ .__

1
models/issue.go

@ -425,7 +425,6 @@ func NewIssue(repo *Repository, issue *Issue, labelIDs []int64, uuids []string)
act := &Action{
ActUserID: issue.Poster.ID,
ActUserName: issue.Poster.Name,
ActEmail: issue.Poster.Email,
OpType: ACTION_CREATE_ISSUE,
Content: fmt.Sprintf("%d|%s", issue.Index, issue.Name),

30
models/repo.go

@ -9,7 +9,9 @@ import (
"errors"
"fmt"
"html/template"
"io"
"io/ioutil"
"mime/multipart"
"os"
"os/exec"
"path"
@ -35,8 +37,6 @@ import (
"github.com/gogits/gogs/modules/markdown"
"github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting"
"mime/multipart"
"io"
)
const (
@ -2223,8 +2223,8 @@ func (repo *Repository) CheckoutNewBranch(oldBranchName, newBranchName string) e
func checkoutNewBranch(repoPath, localPath, oldBranch, newBranch string) error {
if !com.IsExist(localPath) {
if error := updateLocalCopy(repoPath, localPath, oldBranch); error != nil {
return error
if err := updateLocalCopy(repoPath, localPath, oldBranch); error != nil {
return err
}
}
if err := git.Checkout(localPath, git.CheckoutOptions{
@ -2248,7 +2248,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, oldBranchName, branchName, ol
return fmt.Errorf("UpdateLocalRepo: %s - %v", oldBranchName, err)
}
if( oldBranchName != branchName ){
if oldBranchName != branchName {
if err := repo.CheckoutNewBranch(oldBranchName, branchName); err != nil {
return fmt.Errorf("CheckoutNewBranch: %s - %s: %v", oldBranchName, branchName, err)
}
@ -2265,9 +2265,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, oldBranchName, branchName, ol
}
}
if ! com.IsExist(filepath.Dir(filePath)) {
os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
}
// If new file, make sure it doesn't exist; if old file, move if file name change
if isNewFile {
@ -2308,9 +2306,7 @@ func (repo *Repository) GetPreviewDiff(repoPath, branchName, treeName, text stri
localPath := repo.LocalRepoPath()
filePath := path.Join(localPath, treeName)
if ! com.IsExist(filepath.Dir(filePath)) {
os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
}
if err = ioutil.WriteFile(filePath, []byte(text), 0666); err != nil {
return nil, fmt.Errorf("WriteFile: %v", err)
@ -2403,19 +2399,17 @@ func (repo *Repository) UploadRepoFiles(doer *User, oldBranchName, branchName, t
return fmt.Errorf("UpdateLocalRepo: %v", err)
}
if( oldBranchName != branchName ){
if oldBranchName != branchName {
repo.CheckoutNewBranch(oldBranchName, branchName)
}
dirPath := path.Join(localPath, treeName)
if ! com.IsExist(dirPath) {
os.MkdirAll(dirPath, os.ModePerm)
}
// Copy uploaded files into repository.
for _, uuid := range uuids {
upload, err := getUpload(uuid, doer.Id, repo.ID)
upload, err := getUpload(uuid, doer.ID, repo.ID)
if err != nil {
if IsErrUploadNotExist(err) {
continue
@ -2425,10 +2419,10 @@ func (repo *Repository) UploadRepoFiles(doer *User, oldBranchName, branchName, t
uuidPath := upload.LocalPath()
filePath := dirPath + "/" + upload.Name
if err := os.Rename(uuidPath, filePath); err != nil {
DeleteUpload(upload, true);
DeleteUpload(upload, true)
return fmt.Errorf("Rename[%s -> %s]: %v", uuidPath, filePath, err)
}
DeleteUpload(upload, false); // false because we have moved the file
DeleteUpload(upload, false) // false because we have moved the file
}
if len(message) == 0 {
@ -2534,13 +2528,13 @@ func RemoveUpload(uuid string, userId, repoId int64) (err error) {
return nil
}
func getUpload(uuid string, userId, repoId int64) (*Upload, error) {
up := &Upload{UUID: uuid, UID: userId, RepoID: repoId}
func getUpload(uuid string, userID, repoID int64) (*Upload, error) {
up := &Upload{UUID: uuid, UID: userID, RepoID: repoID}
has, err := x.Get(up)
if err != nil {
return nil, err
} else if !has {
return nil, ErrUploadNotExist{0, uuid, userId, repoId}
return nil, ErrUploadNotExist{0, uuid, userID, repoID}
}
return up, nil
}

1
models/working_pool.go

@ -45,4 +45,3 @@ func (p *workingPool) CheckOut(name string) {
p.count[name]--
}
}

3
modules/auth/repo_form.go

@ -319,7 +319,7 @@ func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors)
return validate(errs, ctx.Data, f, ctx.Locale)
}
type UploadRemoveFileForm struct {
type RemoveUploadFileForm struct {
File string `binding:"Required;MaxSize(50)"`
}
@ -342,7 +342,6 @@ func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors)
return validate(errs, ctx.Data, f, ctx.Locale)
}
// __________ .__
// \______ \____________ ____ ____ | |__
// | | _/\_ __ \__ \ / \_/ ___\| | \

6
routers/repo/branch.go

@ -5,13 +5,13 @@
package repo
import (
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/log"
"strings"
"net/url"
"github.com/gogits/gogs/models"
"strings"
)
const (

4
routers/repo/delete.go

@ -5,10 +5,10 @@
package repo
import (
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/models"
)
func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {

18
routers/repo/edit.go

@ -6,17 +6,17 @@ package repo
import (
"io/ioutil"
"strings"
"path"
"strings"
"github.com/gogits/git-module"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/template"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/template"
)
const (
@ -29,7 +29,7 @@ func EditFile(ctx *context.Context) {
editFile(ctx, false)
}
func EditNewFile(ctx *context.Context) {
func NewFile(ctx *context.Context) {
editFile(ctx, true)
}
@ -124,11 +124,11 @@ func editFile(ctx *context.Context, isNewFile bool) {
ctx.HTML(200, EDIT)
}
func EditFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
func FilePost(ctx *context.Context, form auth.EditRepoFileForm) {
editFilePost(ctx, form, false)
}
func EditNewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
func NewFilePost(ctx *context.Context, form auth.EditRepoFileForm) {
editFilePost(ctx, form, true)
}
@ -193,7 +193,7 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
return
}
if( oldBranchName != branchName ){
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
ctx.Data["Err_Branchname"] = true
ctx.RenderWithErr(ctx.Tr("repo.branch_already_exists"), EDIT, &form)
@ -343,7 +343,7 @@ func DiffPreviewPost(ctx *context.Context, form auth.EditPreviewDiffForm) {
return
}
if(diff.NumFiles() == 0){
if diff.NumFiles() == 0 {
ctx.Error(200, ctx.Tr("repo.no_changes_to_show"))
return
}

12
routers/repo/upload.go

@ -7,15 +7,15 @@ package repo
import (
"strings"
"fmt"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/context"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/auth"
"path"
"github.com/gogits/gogs/modules/setting"
"fmt"
"net/http"
"github.com/gogits/gogs/models"
"path"
)
const (
@ -104,7 +104,7 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
return
}
if( oldBranchName != branchName ){
if oldBranchName != branchName {
if _, err := ctx.Repo.Repository.GetBranch(branchName); err == nil {
ctx.Data["Err_Branchname"] = true
ctx.RenderWithErr(ctx.Tr("repo.branch_already_exists"), UPLOAD, &form)
@ -232,7 +232,7 @@ func UploadFileToServer(ctx *context.Context) {
})
}
func UploadRemoveFileFromServer(ctx *context.Context, form auth.UploadRemoveFileForm) {
func RemoveUploadFileFromServer(ctx *context.Context, form auth.RemoveUploadFileForm) {
if !setting.UploadEnabled {
ctx.Error(404, "upload is not enabled")
return

4
routers/repo/view.go

@ -49,10 +49,10 @@ func Home(ctx *context.Context) {
branchLink := ctx.Repo.RepoLink + "/src/" + branchName
treeLink := branchLink
rawLink := ctx.Repo.RepoLink + "/raw/" + branchName
editLink := ctx.Repo.RepoLink + "/edit/" + branchName
editLink := ctx.Repo.RepoLink + "/_edit/" + branchName
newFileLink := ctx.Repo.RepoLink + "/_new/" + branchName
deleteLink := ctx.Repo.RepoLink + "/delete/" + branchName
forkLink := setting.AppSubUrl + "/repo/fork/" + strconv.FormatInt(ctx.Repo.Repository.ID, 10)
newFileLink := ctx.Repo.RepoLink + "/new/" + branchName
uploadFileLink := ctx.Repo.RepoLink + "/upload/" + branchName
// Get tree path

Loading…
Cancel
Save