mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-25 12:24:47 +02:00
show tags in commits panel
This commit is contained in:
parent
78b62be96f
commit
0034cfef5c
@ -61,7 +61,8 @@ func (c *Commit) GetDisplayStrings(isFocused bool) []string {
|
||||
if c.Action != "" {
|
||||
actionString = cyan.Sprint(utils.WithPadding(c.Action, 7)) + " "
|
||||
} else if len(c.Tags) > 0 {
|
||||
tagString = utils.ColoredString(strings.Join(c.Tags, " "), color.FgMagenta) + " "
|
||||
tagColor := color.New(color.FgMagenta, color.Bold)
|
||||
tagString = utils.ColoredStringDirect(strings.Join(c.Tags, " "), tagColor) + " "
|
||||
}
|
||||
|
||||
return []string{shaColor.Sprint(c.Sha[:8]), actionString + tagString + defaultColor.Sprint(c.Name)}
|
||||
|
@ -45,6 +45,44 @@ func NewCommitListBuilder(log *logrus.Entry, gitCommand *GitCommand, osCommand *
|
||||
}, nil
|
||||
}
|
||||
|
||||
// nameAndTag takes a line from a git log and extracts the sha, message and tag (if present)
|
||||
// example inputs:
|
||||
// 66e6369c284e96ed5af5 (tag: v0.14.4) allow fastforwarding the current branch
|
||||
// 32e650e0bb3f4327749f (HEAD -> show-tags) this is my commit
|
||||
// 32e650e0bb3f4327749e this is my other commit
|
||||
func (c *CommitListBuilder) commitLineParts(line string) (string, string, []string) {
|
||||
re := regexp.MustCompile(`(\w+) (.*)`)
|
||||
shaMatch := re.FindStringSubmatch(line)
|
||||
|
||||
if len(shaMatch) <= 1 {
|
||||
return line, "", nil
|
||||
}
|
||||
sha := shaMatch[1]
|
||||
rest := shaMatch[2]
|
||||
|
||||
if !strings.HasPrefix(rest, "(") {
|
||||
return sha, rest, nil
|
||||
}
|
||||
|
||||
re = regexp.MustCompile(`\((.*)\) (.*)`)
|
||||
|
||||
parensMatch := re.FindStringSubmatch(rest)
|
||||
if len(parensMatch) <= 1 {
|
||||
return sha, rest, nil
|
||||
}
|
||||
|
||||
notes := parensMatch[1]
|
||||
message := parensMatch[2]
|
||||
re = regexp.MustCompile(`tag: ([^,]+)`)
|
||||
tagMatch := re.FindStringSubmatch(notes)
|
||||
if len(tagMatch) <= 1 {
|
||||
return sha, message, nil
|
||||
}
|
||||
|
||||
tag := tagMatch[1]
|
||||
return sha, message, []string{tag}
|
||||
}
|
||||
|
||||
// GetCommits obtains the commits of the current branch
|
||||
func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
|
||||
commits := []*Commit{}
|
||||
@ -69,16 +107,15 @@ func (c *CommitListBuilder) GetCommits(limit bool) ([]*Commit, error) {
|
||||
|
||||
// now we can split it up and turn it into commits
|
||||
for _, line := range utils.SplitLines(log) {
|
||||
splitLine := strings.Split(line, " ")
|
||||
sha := splitLine[0]
|
||||
sha, name, tags := c.commitLineParts(line)
|
||||
_, unpushed := unpushedCommits[sha]
|
||||
status := map[bool]string{true: "unpushed", false: "pushed"}[unpushed]
|
||||
commits = append(commits, &Commit{
|
||||
Sha: sha,
|
||||
Name: strings.Join(splitLine[1:], " "),
|
||||
Name: name,
|
||||
Status: status,
|
||||
DisplayString: strings.Join(splitLine, " "),
|
||||
// TODO: add tags here
|
||||
DisplayString: line,
|
||||
Tags: tags,
|
||||
})
|
||||
}
|
||||
if rebaseMode != "" {
|
||||
@ -288,7 +325,7 @@ func (c *CommitListBuilder) getLog(limit bool) string {
|
||||
limitFlag = "-30"
|
||||
}
|
||||
|
||||
result, err := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git log --oneline %s --abbrev=%d", limitFlag, 20))
|
||||
result, err := c.OSCommand.RunCommandWithOutput(fmt.Sprintf("git log --decorate --oneline %s --abbrev=%d", limitFlag, 20))
|
||||
if err != nil {
|
||||
// assume if there is an error there are no commits yet for this branch
|
||||
return ""
|
||||
|
@ -163,7 +163,7 @@ func TestCommitListBuilderGetLog(t *testing.T) {
|
||||
"Retrieves logs",
|
||||
func(cmd string, args ...string) *exec.Cmd {
|
||||
assert.EqualValues(t, "git", cmd)
|
||||
assert.EqualValues(t, []string{"log", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
assert.EqualValues(t, []string{"log", "--decorate", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
|
||||
return exec.Command("echo", "6f0b32f commands/git : add GetCommits tests refactor\n9d9d775 circle : remove new line")
|
||||
},
|
||||
@ -175,7 +175,7 @@ func TestCommitListBuilderGetLog(t *testing.T) {
|
||||
"An error occurred when retrieving logs",
|
||||
func(cmd string, args ...string) *exec.Cmd {
|
||||
assert.EqualValues(t, "git", cmd)
|
||||
assert.EqualValues(t, []string{"log", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
assert.EqualValues(t, []string{"log", "--decorate", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
return exec.Command("test")
|
||||
},
|
||||
func(output string) {
|
||||
@ -212,7 +212,7 @@ func TestCommitListBuilderGetCommits(t *testing.T) {
|
||||
assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args)
|
||||
return exec.Command("echo")
|
||||
case "log":
|
||||
assert.EqualValues(t, []string{"log", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
assert.EqualValues(t, []string{"log", "--decorate", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
return exec.Command("echo")
|
||||
case "merge-base":
|
||||
assert.EqualValues(t, []string{"merge-base", "HEAD", "master"}, args)
|
||||
@ -239,7 +239,7 @@ func TestCommitListBuilderGetCommits(t *testing.T) {
|
||||
assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args)
|
||||
return exec.Command("echo", "8a2bb0e")
|
||||
case "log":
|
||||
assert.EqualValues(t, []string{"log", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
assert.EqualValues(t, []string{"log", "--decorate", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
return exec.Command("echo", "8a2bb0e commit 1\n78976bc commit 2")
|
||||
case "merge-base":
|
||||
assert.EqualValues(t, []string{"merge-base", "HEAD", "master"}, args)
|
||||
@ -280,7 +280,7 @@ func TestCommitListBuilderGetCommits(t *testing.T) {
|
||||
assert.EqualValues(t, []string{"rev-list", "@{u}..HEAD", "--abbrev-commit"}, args)
|
||||
return exec.Command("echo", "8a2bb0e")
|
||||
case "log":
|
||||
assert.EqualValues(t, []string{"log", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
assert.EqualValues(t, []string{"log", "--decorate", "--oneline", "-30", "--abbrev=20"}, args)
|
||||
return exec.Command("echo", "8a2bb0e commit 1\n78976bc commit 2")
|
||||
case "merge-base":
|
||||
assert.EqualValues(t, []string{"merge-base", "HEAD", "master"}, args)
|
||||
|
Loading…
x
Reference in New Issue
Block a user