diff options
Diffstat (limited to 'cmd/gitaly-git2go/commit/create_directory.go')
-rw-r--r-- | cmd/gitaly-git2go/commit/create_directory.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/cmd/gitaly-git2go/commit/create_directory.go b/cmd/gitaly-git2go/commit/create_directory.go new file mode 100644 index 000000000..061666ed3 --- /dev/null +++ b/cmd/gitaly-git2go/commit/create_directory.go @@ -0,0 +1,30 @@ +//go:build static && system_libgit2 + +package commit + +import ( + "fmt" + "path/filepath" + + git "github.com/libgit2/git2go/v33" + "gitlab.com/gitlab-org/gitaly/v15/internal/git2go" +) + +func applyCreateDirectory(action git2go.CreateDirectory, repo *git.Repository, index *git.Index) error { + if err := validateFileDoesNotExist(index, action.Path); err != nil { + return err + } else if err := validateDirectoryDoesNotExist(index, action.Path); err != nil { + return err + } + + emptyBlobOID, err := repo.CreateBlobFromBuffer([]byte{}) + if err != nil { + return fmt.Errorf("create blob from buffer: %w", err) + } + + return index.Add(&git.IndexEntry{ + Path: filepath.Join(action.Path, ".gitkeep"), + Mode: git.FilemodeBlob, + Id: emptyBlobOID, + }) +} |