Skip to content

Commit

Permalink
Merge pull request #2351 from carapace-sh/git-fix-actionrefs
Browse files Browse the repository at this point in the history
git: ActionRefs - fix delimiter
  • Loading branch information
rsteube authored Apr 16, 2024
2 parents df400e3 + cabe748 commit e95f07d
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions completers/git_completer/cmd/show.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package cmd

import (
"path/filepath"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/git"
"github.com/carapace-sh/carapace/pkg/util"
"github.com/carapace-sh/carapace/pkg/traverse"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,19 +41,21 @@ func init() {
})

carapace.Gen(showCmd).PositionalAnyCompletion(
carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOption{}.Default()).NoSpace()
case 1:
path, err := util.FindReverse(c.Dir, ".git")
if err != nil {
return carapace.ActionMessage(err.Error())
}
return git.ActionRefFiles(c.Parts[0]).Chdir(filepath.Dir(path))
default:
return carapace.ActionFiles()
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
delimiter := ":"
if strings.Contains(c.Value, "{") {
delimiter = "}:"
}

return carapace.ActionMultiPartsN(delimiter, 2, func(c carapace.Context) carapace.Action {
switch len(c.Parts) {
case 0:
return git.ActionRefs(git.RefOption{}.Default()).NoSpace()
default:
ref := c.Parts[0] + strings.TrimSuffix(delimiter, ":")
return git.ActionRefFiles(ref).ChdirF(traverse.GitWorkTree)
}
})
}),
)
}

0 comments on commit e95f07d

Please sign in to comment.