diff options
author | Unknwon <u@gogs.io> | 2016-08-29 00:10:21 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-08-29 00:10:21 -0700 |
commit | 62b0dc4853d3c8147c5ec164e9aba452f95259b8 (patch) | |
tree | c25da80cb09a4854a6d0afac127532a60f71f143 /models/repo_editor.go | |
parent | 429c92c0ce15213e52fdacb3d28ee2f3a3a5a63f (diff) | |
download | gitea-62b0dc4853d3c8147c5ec164e9aba452f95259b8.tar.gz gitea-62b0dc4853d3c8147c5ec164e9aba452f95259b8.zip |
Web editor: fix cannot create new file in subdirectory
Diffstat (limited to 'models/repo_editor.go')
-rw-r--r-- | models/repo_editor.go | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/models/repo_editor.go b/models/repo_editor.go index c80bf05991..31b94f631e 100644 --- a/models/repo_editor.go +++ b/models/repo_editor.go @@ -96,6 +96,7 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) ( } localPath := repo.LocalCopyPath() + oldFilePath := path.Join(localPath, opts.OldTreeName) filePath := path.Join(localPath, opts.NewTreeName) os.MkdirAll(path.Dir(filePath), os.ModePerm) @@ -106,8 +107,9 @@ func (repo *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) ( } } - // If update a file, move if file name change. - if len(opts.OldTreeName) > 0 && len(opts.NewTreeName) > 0 && opts.OldTreeName != opts.NewTreeName { + // Ignore move step if it's a new file under a directory. + // Otherwise, move the file when name changed. + if com.IsFile(oldFilePath) && opts.OldTreeName != opts.NewTreeName { if err = git.MoveFile(localPath, opts.OldTreeName, opts.NewTreeName); err != nil { return fmt.Errorf("git mv %s %s: %v", opts.OldTreeName, opts.NewTreeName, err) } |