Skip to content

Commit

Permalink
Merge pull request #2054 from rsteube/git-headcommits
Browse files Browse the repository at this point in the history
git: ActionHeadCommits - always use `~` style
  • Loading branch information
rsteube authored Dec 4, 2023
2 parents 1773f19 + 4a9800a commit 5ff2d9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
6 changes: 1 addition & 5 deletions pkg/actions/tools/git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ func ActionHeadCommits(limit int) carapace.Action {

vals := make([]string, 0)
for index, line := range lines[:len(lines)-1] {
if index == 0 {
vals = append(vals, "HEAD", strings.TrimSpace(line[10:]))
} else {
vals = append(vals, "HEAD~"+fmt.Sprintf("%0"+strconv.Itoa(len(strconv.Itoa(limit-1)))+"d", index), strings.TrimSpace(line[10:]))
}
vals = append(vals, "HEAD~"+fmt.Sprintf("%0"+strconv.Itoa(len(strconv.Itoa(limit-1)))+"d", index), strings.TrimSpace(line[10:]))
}
return carapace.ActionValuesDescribed(vals...).Style(styles.Git.HeadCommit)
})
Expand Down
9 changes: 2 additions & 7 deletions pkg/actions/tools/git/ref.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"

"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/styles"
)

func rootDir(c carapace.Context) (string, error) {
Expand Down Expand Up @@ -58,12 +57,8 @@ func ActionRefs(refOption RefOption) carapace.Action {
batch = append(batch, ActionRecentCommits(refOption.Commits))
}

switch refOption.HeadCommits {
case 0:
case 1: // add with `~` for convenience
batch = append(batch, carapace.ActionValues("HEAD~").NoSpace('~').Style(styles.Git.HeadCommit).Tag("head commits"))
default:
batch = append(batch, ActionHeadCommits(refOption.HeadCommits))
if refOption.HeadCommits > 0 {
batch = append(batch, ActionHeadCommits(refOption.HeadCommits).MultiParts("~"))
}

if refOption.Tags {
Expand Down

0 comments on commit 5ff2d9e

Please sign in to comment.