mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 04:19:41 -08:00
feat(git): add SHA1 to commit metadata
This commit is contained in:
parent
fcc1daeb36
commit
672f108d22
|
@ -21,6 +21,7 @@ type Commit struct {
|
|||
Committer *User
|
||||
Subject string
|
||||
Timestamp time.Time
|
||||
Sha string
|
||||
}
|
||||
|
||||
type User struct {
|
||||
|
@ -195,7 +196,7 @@ func (g *Git) Commit() *Commit {
|
|||
Author: &User{},
|
||||
Committer: &User{},
|
||||
}
|
||||
commitBody := g.getGitCommandOutput("log", "-1", "--pretty=format:an:%an%nae:%ae%ncn:%cn%nce:%ce%nat:%at%nsu:%s")
|
||||
commitBody := g.getGitCommandOutput("log", "-1", "--pretty=format:an:%an%nae:%ae%ncn:%cn%nce:%ce%nat:%at%nsu:%s%nha:%H")
|
||||
splitted := strings.Split(strings.TrimSpace(commitBody), "\n")
|
||||
for _, line := range splitted {
|
||||
line = strings.TrimSpace(line)
|
||||
|
@ -219,6 +220,8 @@ func (g *Git) Commit() *Commit {
|
|||
}
|
||||
case "su:":
|
||||
g.commit.Subject = line
|
||||
case "ha:":
|
||||
g.commit.Sha = line
|
||||
}
|
||||
}
|
||||
return g.commit
|
||||
|
|
|
@ -942,6 +942,7 @@ func TestGitCommit(t *testing.T) {
|
|||
ce:jan@ohmyposh.dev
|
||||
at:1673176335
|
||||
su:docs(error): you can't use cross segment properties
|
||||
ha:1234567891011121314
|
||||
`,
|
||||
Expected: &Commit{
|
||||
Author: &User{
|
||||
|
@ -954,6 +955,7 @@ func TestGitCommit(t *testing.T) {
|
|||
},
|
||||
Subject: "docs(error): you can't use cross segment properties",
|
||||
Timestamp: time.Unix(1673176335, 0),
|
||||
Sha: "1234567891011121314",
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -997,7 +999,7 @@ func TestGitCommit(t *testing.T) {
|
|||
|
||||
for _, tc := range cases {
|
||||
env := new(mock.MockedEnvironment)
|
||||
env.MockGitCommand("", tc.Output, "log", "-1", "--pretty=format:an:%an%nae:%ae%ncn:%cn%nce:%ce%nat:%at%nsu:%s")
|
||||
env.MockGitCommand("", tc.Output, "log", "-1", "--pretty=format:an:%an%nae:%ae%ncn:%cn%nce:%ce%nat:%at%nsu:%s%nha:%H")
|
||||
g := &Git{
|
||||
scm: scm{
|
||||
env: env,
|
||||
|
|
|
@ -183,6 +183,7 @@ Local changes use the following syntax:
|
|||
| `.Committer` | `User` | the comitter of the commit (see below) |
|
||||
| `.Subject` | `string` | the commit subject |
|
||||
| `.Timestamp` | `time.Time` | the commit timestamp |
|
||||
| `.Sha` | `string` | the commit SHA1 |
|
||||
|
||||
### User
|
||||
|
||||
|
|
Loading…
Reference in a new issue