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

commit.go « git2go « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ee24862d96815790b08ed924360afe1c6860366a (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package git2go

import (
	"bytes"
	"context"
	"encoding/gob"
	"fmt"
)

// InvalidArgumentError is returned when an invalid argument is provided.
type InvalidArgumentError string

func (err InvalidArgumentError) Error() string { return string(err) }

// FileNotFoundError is returned when an action attempts to operate on a non-existing file.
type FileNotFoundError string

func (err FileNotFoundError) Error() string {
	return fmt.Sprintf("file not found: %q", string(err))
}

// FileExistsError is returned when an action attempts to overwrite an existing file.
type FileExistsError string

func (err FileExistsError) Error() string {
	return fmt.Sprintf("file exists: %q", string(err))
}

// DirectoryExistsError is returned when an action attempts to overwrite a directory.
type DirectoryExistsError string

func (err DirectoryExistsError) Error() string {
	return fmt.Sprintf("directory exists: %q", string(err))
}

// CommitParams contains the information and the steps to build a commit.
type CommitParams struct {
	// Repository is the path of the repository to operate on.
	Repository string
	// Author is the author of the commit.
	Author Signature
	// Message is message of the commit.
	Message string
	// Parent is the OID of the commit to use as the parent of this commit.
	Parent string
	// Actions are the steps to build the commit.
	Actions []Action
}

// Commit builds a commit from the actions, writes it to the object database and
// returns its object id.
func (b Executor) Commit(ctx context.Context, params CommitParams) (string, error) {
	input := &bytes.Buffer{}
	if err := gob.NewEncoder(input).Encode(params); err != nil {
		return "", err
	}

	output, err := run(ctx, b.binaryPath, input, "commit")
	if err != nil {
		return "", err
	}

	var result Result
	if err := gob.NewDecoder(output).Decode(&result); err != nil {
		return "", err
	}

	return result.CommitID, result.Error
}