Skip to content

Commit

Permalink
Web editor: improve delete file process
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon committed Aug 28, 2016
1 parent dad5c15 commit 0114fdc
Show file tree
Hide file tree
Showing 19 changed files with 217 additions and 174 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra

![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)

##### Current tip version: 0.9.90 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)
##### Current tip version: 0.9.91 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions)

| Web | UI | Preview |
|:-------------:|:-------:|:-------:|
Expand Down
3 changes: 2 additions & 1 deletion cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ func runWeb(ctx *cli.Context) error {
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.Combo("/_delete/*").Get(repo.DeleteFile).
Post(bindIgnErr(auth.DeleteRepoFileForm{}), repo.DeleteFilePost)
// m.Post("/upload-file", repo.UploadFileToServer)
// m.Post("/upload-remove", bindIgnErr(auth.RemoveUploadFileForm{}), repo.RemoveUploadFileFromServer)
}, reqRepoWriter, context.RepoRef(), func(ctx *context.Context) {
Expand Down
25 changes: 11 additions & 14 deletions conf/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -426,43 +426,40 @@ file_view_raw = View Raw
file_permalink = Permalink
file_too_large = This file is too large to be shown
cancel = Cancel
cancel_lower = cancel
or = or
new_file = New file
upload_files = Upload files
find_file = Find file
commit_changes = Commit Changes
default_commit_message = Add an optional extended description...
last_commit_info = %s edited this file %s
delete_this_file = Delete this file
edit_file = Edit file
delete_confirm_message = Are you sure you want to delete this file?
delete_commit_message = Write a note about this delete (optional)
unable_to_update_file = Unable to update this file, error occurred
must_be_writer = You must have write access to make or propose changes to this file
filename_help = To add directory, just type it and press /. To remove a directory, go to the beginning of the field and press backspace.
new_branch = new branch
editor.new_file = New file
editor.cannot_edit_non_text_files = Cannot edit non-text files
editor.edit_this_file = Edit this file
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file
editor.fork_before_edit = You must fork this repository before editing the file
editor.delete_this_file = Delete this file
editor.must_have_write_access = You must have write access to make or propose changes to this file
editor.file_delete_success = File '%s' has been deleted successfully!
editor.commit_changes = Commit Changes
editor.add_tmpl = Add '%s/<filename>'
editor.add = Add '%s'
editor.update = Update '%s'
editor.delete = Delete '%s'
editor.commit_message_desc = Add an optional extended description...
editor.commit_directly_to_this_branch = Commit directly to the <strong class="branch-name">%s</strong> branch.
editor.create_new_branch = Create a <strong>new branch</strong> for this commit and start a pull request.
editor.new_branch_name_desc = New branch name...
editor.cancel = Cancel
editor.filename_cannot_be_empty = Filename cannot be empty.
editor.branch_already_exists = Branch '%s' already exists in this repository.
editor.directory_is_a_file = Entry '%s' in the parent path is a file not a directory in this repository.
editor.filename_is_a_directory = The filename '%s' is an existing directory in this repository.
editor.file_editing_no_longer_exists = The file '%s' you are editing no longer exists in the repository.
editor.file_changed_while_editing = File content has been changed since you started editing. <a target="_blank" href="%s">Click here</a> to see what have been changed or <strong>press commit again</strong> to overwrite those changes.
editor.file_already_exists = A file with name '%s' already exists in this repository.
editor.add = Add '%s'
editor.update = Update '%s'
editor.failed_to_upload_files = An error occurred while updating file: %v
editor.no_changes_to_show = There are no changes to show.
create_branch = Create branch
from = from
upload_file = Upload file
add_files_to_dir = Add files to %s
add_subdir = Add subdirectory...
Expand Down
2 changes: 1 addition & 1 deletion gogs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)

const APP_VER = "0.9.90.0828"
const APP_VER = "0.9.91.0828"

func init() {
runtime.GOMAXPROCS(runtime.NumCPU())
Expand Down
41 changes: 18 additions & 23 deletions models/repo_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) (
}
}

if len(opts.Message) == 0 {
if opts.IsNewFile {
opts.Message = "Add '" + opts.NewTreeName + "'"
} else {
opts.Message = "Update '" + opts.NewTreeName + "'"
}
}

localPath := repo.LocalCopyPath()
filePath := path.Join(localPath, opts.NewTreeName)
os.MkdirAll(path.Dir(filePath), os.ModePerm)
Expand Down Expand Up @@ -228,7 +220,8 @@ func (repo *Repository) GetDiffPreview(branch, treePath, content string) (diff *

type DeleteRepoFileOptions struct {
LastCommitID string
Branch string
OldBranch string
NewBranch string
TreePath string
Message string
}
Expand All @@ -237,19 +230,21 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
repoWorkingPool.CheckIn(com.ToStr(repo.ID))
defer repoWorkingPool.CheckOut(com.ToStr(repo.ID))

localPath := repo.LocalCopyPath()
if err = discardLocalRepoBranchChanges(localPath, opts.Branch); err != nil {
return fmt.Errorf("discardLocalRepoBranchChanges [branch: %s]: %v", opts.Branch, err)
} else if err = repo.UpdateLocalCopyBranch(opts.Branch); err != nil {
return fmt.Errorf("UpdateLocalCopyBranch [branch: %s]: %v", opts.Branch, err)
if err = repo.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
return fmt.Errorf("DiscardLocalRepoBranchChanges [branch: %s]: %v", opts.OldBranch, err)
} else if err = repo.UpdateLocalCopyBranch(opts.OldBranch); err != nil {
return fmt.Errorf("UpdateLocalCopyBranch [branch: %s]: %v", opts.OldBranch, err)
}

if err = os.Remove(path.Join(localPath, opts.TreePath)); err != nil {
return fmt.Errorf("Remove: %v", err)
if opts.OldBranch != opts.NewBranch {
if err := repo.CheckoutNewBranch(opts.OldBranch, opts.NewBranch); err != nil {
return fmt.Errorf("CheckoutNewBranch [old_branch: %s, new_branch: %s]: %v", opts.OldBranch, opts.NewBranch, err)
}
}

if len(opts.Message) == 0 {
opts.Message = "Delete file '" + opts.TreePath + "'"
localPath := repo.LocalCopyPath()
if err = os.Remove(path.Join(localPath, opts.TreePath)); err != nil {
return fmt.Errorf("Remove: %v", err)
}

if err = git.AddChanges(localPath, true); err != nil {
Expand All @@ -259,18 +254,18 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
Message: opts.Message,
}); err != nil {
return fmt.Errorf("CommitChanges: %v", err)
} else if err = git.Push(localPath, "origin", opts.Branch); err != nil {
return fmt.Errorf("git push origin %s: %v", opts.Branch, err)
} else if err = git.Push(localPath, "origin", opts.NewBranch); err != nil {
return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
}

gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
log.Error(4, "OpenRepository: %v", err)
return nil
}
commit, err := gitRepo.GetBranchCommit(opts.Branch)
commit, err := gitRepo.GetBranchCommit(opts.NewBranch)
if err != nil {
log.Error(4, "GetBranchCommit [branch: %s]: %v", opts.Branch, err)
log.Error(4, "GetBranchCommit [branch: %s]: %v", opts.NewBranch, err)
return nil
}

Expand All @@ -283,7 +278,7 @@ func (repo *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (
PusherName: doer.Name,
RepoOwnerID: repo.MustOwner().ID,
RepoName: repo.Name,
RefFullName: git.BRANCH_PREFIX + opts.Branch,
RefFullName: git.BRANCH_PREFIX + opts.NewBranch,
OldCommitID: opts.LastCommitID,
NewCommitID: commit.ID.String(),
Commits: pushCommits,
Expand Down
3 changes: 3 additions & 0 deletions modules/auth/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Error

type DeleteRepoFileForm struct {
CommitSummary string `binding:"MaxSize(100)`
CommitMessage string
CommitChoice string `binding:"Required;MaxSize(50)"`
NewBranchName string `binding:"AlphaDashDot;MaxSize(100)"`
}

func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
Expand Down
4 changes: 2 additions & 2 deletions modules/bindata/bindata.go

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions public/js/gogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,16 @@ function setCodeMirror($editArea) {
}

function initEditor() {
$('.js-quick-pull-choice-option').change(function () {
if ($(this).val() == 'commit-to-new-branch') {
$('.quick-pull-branch-name').show();
$('.quick-pull-branch-name input').prop('required',true);
} else {
$('.quick-pull-branch-name').hide();
$('.quick-pull-branch-name input').prop('required',false);
}
});

var $editFilename = $("#file-name");
$editFilename.keyup(function (e) {
var $section = $('.breadcrumb span.section');
Expand Down Expand Up @@ -841,16 +851,6 @@ function initEditor() {
codeMirrorEditor.setOption("lineWrapping", false);
}
}).trigger('keyup');


$('.js-quick-pull-choice-option').change(function () {
if ($(this).val() == 'commit-to-new-branch') {
$('.quick-pull-branch-name').show();
} else {
$('.quick-pull-branch-name').hide();
}
});

}

function initOrganization() {
Expand Down
Loading

0 comments on commit 0114fdc

Please sign in to comment.