Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Improving / Exposing Git-Trees related features for Git-Trees API. #123

Merged
merged 5 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions repo_tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ func (repo *Repository) getTree(id SHA1) (*Tree, error) {

// GetTree find the tree object in the repository.
func (repo *Repository) GetTree(idStr string) (*Tree, error) {
if len(idStr) != 40 {
res, err := NewCommand("rev-parse", idStr).RunInDir(repo.Path)
if err != nil {
return nil, err;
}
if len(res) > 0 {
idStr = res[:len(res)-1]
}
}
id, err := NewIDFromString(idStr)
if err != nil {
return nil, err
Expand Down
14 changes: 14 additions & 0 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,17 @@ func (t *Tree) ListEntries() (Entries, error) {
t.entries, err = parseTreeEntries(stdout, t)
return t.entries, err
}

// ListEntriesRecursive returns all entries of current tree recursively including all subtrees
func (t *Tree) ListEntriesRecursive() (Entries, error) {
if t.entriesParsed {
return t.entries, nil
}
stdout, err := NewCommand("ls-tree", "-t", "-r", t.ID.String()).RunInDirBytes(t.repo.Path)

if err != nil {
return nil, err
}
t.entries, err = parseTreeEntries(stdout, t)
return t.entries, err
}
15 changes: 10 additions & 5 deletions tree_entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ type EntryMode int
// one of these.
const (
// EntryModeBlob
EntryModeBlob EntryMode = 0100644
EntryModeBlob EntryMode = 0x0100644
// EntryModeExec
EntryModeExec EntryMode = 0100755
EntryModeExec EntryMode = 0x0100755
// EntryModeSymlink
EntryModeSymlink EntryMode = 0120000
EntryModeSymlink EntryMode = 0x0120000
// EntryModeCommit
EntryModeCommit EntryMode = 0160000
EntryModeCommit EntryMode = 0x0160000
// EntryModeTree
EntryModeTree EntryMode = 0040000
EntryModeTree EntryMode = 0x0040000
)

// TreeEntry the leaf in the git tree
Expand All @@ -50,6 +50,11 @@ func (te *TreeEntry) Name() string {
return te.name
}

// Mode returns the mode of the entry
func (te *TreeEntry) Mode() EntryMode {
return te.mode
}

// Size returns the size of the entry
func (te *TreeEntry) Size() int64 {
if te.IsDir() {
Expand Down