diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go index 5913288f05d20bab5012df8a3f03061424c95537..373af1749f25117eeccec1322c8b193fbc5e3cb6 100644 --- a/internal/gitaly/service/operations/commit_files.go +++ b/internal/gitaly/service/operations/commit_files.go @@ -256,6 +256,18 @@ func applyAction( return translateError(err, action.Path) } case updateFile: + entry, err := root.Get(action.Path) + if err != nil { + return translateError(err, action.Path) + } + + if entry.Type != localrepo.Blob { + return indexError{ + path: action.Path, + errorType: errFileNotFound, + } + } + if err := root.Modify( action.Path, func(entry *localrepo.TreeEntry) error { @@ -415,7 +427,6 @@ func (s *Server) userCommitFilesGit( header *gitalypb.UserCommitFilesRequestHeader, parentCommitOID git.ObjectID, quarantineRepo *localrepo.Repo, - repoPath string, actions []commitAction, ) (git.ObjectID, error) { committerSignature, err := git.SignatureFromRequest(header) @@ -693,7 +704,6 @@ func (s *Server) userCommitFiles( header, parentCommitOID, quarantineRepo, - repoPath, actions, ) if err != nil { diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go index e4f7dcf568980273979b05ec8495ba70db877c91..eb305121db152d60e5b4ec2972e43363eb11ef8f 100644 --- a/internal/gitaly/service/operations/commit_files_test.go +++ b/internal/gitaly/service/operations/commit_files_test.go @@ -459,6 +459,28 @@ func testUserCommitFiles(t *testing.T, ctx context.Context) { }, }, }, + { + desc: "update file fails if the target is a directory", + steps: []step{ + { + actions: []*gitalypb.UserCommitFilesRequest{ + createDirHeaderRequest("directory"), + }, + repoCreated: true, + branchCreated: true, + treeEntries: []gittest.TreeEntry{ + {Mode: DefaultMode, Path: "directory/.gitkeep"}, + }, + }, + { + actions: []*gitalypb.UserCommitFilesRequest{ + updateFileHeaderRequest("directory"), + actionContentRequest("content"), + }, + expectedErr: structuredIndexError(t, &indexError{path: "directory", errorType: errFileNotFound}), + }, + }, + }, { desc: "move file with traversal in source", steps: []step{