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

move_file.go « commit « gitaly-git2go-v14 « cmd - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 39209630d1ccbf171d1892f4f4e6e0555ef81be9 (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
31
32
33
34
35
36
37
38
39
40
41
42
//go:build static && system_libgit2
// +build static,system_libgit2

package commit

import (
	git "github.com/libgit2/git2go/v33"
	"gitlab.com/gitlab-org/gitaly/internal/git2go"
)

func applyMoveFile(action git2go.MoveFile, index *git.Index) error {
	entry, err := index.EntryByPath(action.Path, 0)
	if err != nil {
		if git.IsErrorCode(err, git.ErrorCodeNotFound) {
			return git2go.FileNotFoundError(action.Path)
		}

		return err
	}

	if err := validateFileDoesNotExist(index, action.NewPath); err != nil {
		return err
	}

	oid := entry.Id
	if action.OID != "" {
		oid, err = git.NewOid(action.OID)
		if err != nil {
			return err
		}
	}

	if err := index.Add(&git.IndexEntry{
		Path: action.NewPath,
		Mode: entry.Mode,
		Id:   oid,
	}); err != nil {
		return err
	}

	return index.RemoveByPath(entry.Path)
}