-
Notifications
You must be signed in to change notification settings - Fork 130
Expand file tree
/
Copy pathrepo_blob.go
More file actions
45 lines (38 loc) · 1.03 KB
/
repo_blob.go
File metadata and controls
45 lines (38 loc) · 1.03 KB
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
package git
import "context"
// CatFileBlobOptions contains optional arguments for verifying the objects.
//
// Docs: https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt
type CatFileBlobOptions struct {
CommandOptions
}
// CatFileBlob returns the blob corresponding to the given revision of the repository.
func (r *Repository) CatFileBlob(ctx context.Context, rev string, opts ...CatFileBlobOptions) (*Blob, error) {
var opt CatFileBlobOptions
if len(opts) > 0 {
opt = opts[0]
}
// Type conversions work because all three option types share the same
// underlying structure (CommandOptions only).
rev, err := r.RevParse(ctx, rev, RevParseOptions(opt)) //nolint
if err != nil {
return nil, err
}
typ, err := r.CatFileType(ctx, rev, CatFileTypeOptions(opt))
if err != nil {
return nil, err
}
if typ != ObjectBlob {
return nil, ErrNotBlob
}
return &Blob{
TreeEntry: &TreeEntry{
mode: EntryBlob,
typ: ObjectBlob,
id: MustIDFromString(rev),
parent: &Tree{
repo: r,
},
},
}, nil
}