Welcome to mirror list, hosted at ThFree Co, Russian Federation.

create_directory.go « commit « gitaly-git2go « cmd - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c7059c0a311cb70529095fb24dff45d0b4d99958 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// +build static,system_libgit2

package commit

import (
	"fmt"
	"path/filepath"

	git "github.com/libgit2/git2go/v30"
	"gitlab.com/gitlab-org/gitaly/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,
	})
}