MCPcopy Index your code
hub / github.com/git-lfs/git-lfs / GetCommitSummary

Function GetCommitSummary

git/git.go:757–793  ·  view source on GitHub ↗

Get summary information about a commit

(commit string)

Source from the content-addressed store, hash-verified

755
756// Get summary information about a commit
757func GetCommitSummary(commit string) (*CommitSummary, error) {
758 cmd, err := gitNoLFS("show", "-s",
759 `--format=%H|%h|%P|%ai|%ci|%ae|%an|%ce|%cn|%s`, commit)
760 if err != nil {
761 return nil, errors.New(tr.Tr.Get("failed to find `git show`: %v", err))
762 }
763
764 out, err := cmd.CombinedOutput()
765 if err != nil {
766 return nil, errors.New(tr.Tr.Get("failed to call `git show`: %v %v", err, string(out)))
767 }
768
769 // At most 10 substrings so subject line is not split on anything
770 fields := strings.SplitN(string(out), "|", 10)
771 // Cope with the case where subject is blank
772 if len(fields) >= 9 {
773 ret := &CommitSummary{}
774 // Get SHAs from output, not commit input, so we can support symbolic refs
775 ret.Sha = fields[0]
776 ret.ShortSha = fields[1]
777 ret.Parents = strings.Split(fields[2], " ")
778 // %aD & %cD (RFC2822) matches Go's RFC1123Z format
779 ret.AuthorDate, _ = ParseGitDate(fields[3])
780 ret.CommitDate, _ = ParseGitDate(fields[4])
781 ret.AuthorEmail = fields[5]
782 ret.AuthorName = fields[6]
783 ret.CommitterEmail = fields[7]
784 ret.CommitterName = fields[8]
785 if len(fields) > 9 {
786 ret.Subject = strings.TrimRight(fields[9], "\n")
787 }
788 return ret, nil
789 } else {
790 msg := tr.Tr.Get("Unexpected output from `git show`: %v", string(out))
791 return nil, errors.New(msg)
792 }
793}
794
795func GitAndRootDirs() (string, string, error) {
796 cmd, err := gitNoLFS("rev-parse", "--git-dir", "--show-toplevel")

Callers 3

fetchRecentFunction · 0.92
AddCommitsMethod · 0.92

Calls 5

NewFunction · 0.92
gitNoLFSFunction · 0.85
ParseGitDateFunction · 0.85
CombinedOutputMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected