Skip to content

Commit cbb6ad0

Browse files
committed
fix
1 parent 439ebe7 commit cbb6ad0

File tree

8 files changed

+215
-215
lines changed

8 files changed

+215
-215
lines changed

modules/optional/option.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ package optional
55

66
import "strconv"
77

8+
// Option is a generic type that can hold a value of type T or be empty (None).
9+
//
10+
// It must use the slice type to work with "chi" form values binding:
11+
// * non-existing value are represented as an empty slice (None)
12+
// * existing value is represented as a slice with one element (Some)
13+
// * multiple values are represented as a slice with multiple elements (Some), the Value is the first element (not well-defined in this case)
814
type Option[T any] []T
915

1016
func None[T any]() Option[T] {

routers/web/repo/editor.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,13 +288,20 @@ func editFilePost(ctx *context.Context, form forms.EditRepoFileForm, isNewFile b
288288
return
289289
}
290290

291-
operation := "update"
291+
var operation string
292292
if isNewFile {
293293
operation = "create"
294-
} else if !form.Content.Has() && ctx.Repo.TreePath != form.TreePath {
295-
// The form content only has data if file is representable as text, is not too large and not in lfs. If it doesn't
296-
// have data, the only possible operation is a rename
294+
} else if form.Content.Has() {
295+
// The form content only has data if the file is representable as text, is not too large and not in lfs.
296+
operation = "update"
297+
} else if ctx.Repo.TreePath != form.TreePath {
298+
// If it doesn't have data, the only possible operation is a "rename"
297299
operation = "rename"
300+
} else {
301+
// It should never happen, just in case
302+
ctx.Flash.Error(ctx.Tr("error.occurred"))
303+
ctx.HTML(http.StatusOK, tplEditFile)
304+
return
298305
}
299306

300307
if _, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{

services/packages/cargo/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ func alterRepositoryContent(ctx context.Context, doer *user_model.User, repo *re
310310
}
311311

312312
func writeObjectToIndex(ctx context.Context, t *files_service.TemporaryUploadRepository, path string, r io.Reader) error {
313-
hash, err := t.HashObject(ctx, r)
313+
hash, err := t.HashObjectAndWrite(ctx, r)
314314
if err != nil {
315315
return err
316316
}

services/repository/files/diff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func GetDiffPreview(ctx context.Context, repo *repo_model.Repository, branch, tr
2929
}
3030

3131
// Add the object to the database
32-
objectHash, err := t.HashObject(ctx, strings.NewReader(content))
32+
objectHash, err := t.HashObjectAndWrite(ctx, strings.NewReader(content))
3333
if err != nil {
3434
return nil, err
3535
}

services/repository/files/temp_repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ func (t *TemporaryUploadRepository) RemoveFilesFromIndex(ctx context.Context, fi
164164
return nil
165165
}
166166

167-
// HashObject writes the provided content to the object db and returns its hash
168-
func (t *TemporaryUploadRepository) HashObject(ctx context.Context, content io.Reader) (string, error) {
167+
// HashObjectAndWrite writes the provided content to the object db and returns its hash
168+
func (t *TemporaryUploadRepository) HashObjectAndWrite(ctx context.Context, content io.Reader) (string, error) {
169169
stdOut := new(bytes.Buffer)
170170
stdErr := new(bytes.Buffer)
171171

0 commit comments

Comments
 (0)