-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: migrate readme & fix permissions
- Loading branch information
1 parent
58ac5a3
commit afc0b57
Showing
8 changed files
with
167 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package git | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"github.com/gobwas/glob" | ||
) | ||
|
||
// LatestFile returns the contents of the first file at the specified path pattern in the repository and its file path. | ||
func LatestFile(repo *Repository, pattern string) (string, string, error) { | ||
g := glob.MustCompile(pattern) | ||
dir := filepath.Dir(pattern) | ||
head, err := repo.HEAD() | ||
if err != nil { | ||
return "", "", err | ||
} | ||
t, err := repo.TreePath(head, dir) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
ents, err := t.Entries() | ||
if err != nil { | ||
return "", "", err | ||
} | ||
for _, e := range ents { | ||
te := e | ||
fp := filepath.Join(dir, te.Name()) | ||
if te.IsTree() { | ||
continue | ||
} | ||
if g.Match(fp) { | ||
if te.IsSymlink() { | ||
bts, err := te.Contents() | ||
if err != nil { | ||
return "", "", err | ||
} | ||
fp = string(bts) | ||
te, err = t.TreeEntry(fp) | ||
if err != nil { | ||
return "", "", err | ||
} | ||
} | ||
bts, err := te.Contents() | ||
if err != nil { | ||
return "", "", err | ||
} | ||
return string(bts), fp, nil | ||
} | ||
} | ||
return "", "", ErrFileNotFound | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.