Skip to content

Commit

Permalink
Merge pull request #1994 from rsteube/jj-next
Browse files Browse the repository at this point in the history
jj: next
  • Loading branch information
rsteube authored Nov 3, 2023
2 parents 0f59926 + 2726181 commit 0b0db74
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion completers/jj_completer/cmd/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/pkg/actions/tools/jj"
"github.com/spf13/cobra"
)

var nextCmd = &cobra.Command{
Use: "next",
Use: "next [OPTIONS] [AMOUNT]",
Short: "Move the current working copy commit to the next child revision in the repository.",
Run: func(cmd *cobra.Command, args []string) {},
}
Expand All @@ -17,4 +18,8 @@ func init() {
nextCmd.Flags().Bool("edit", false, "Instead of creating a new working-copy commit on top of the target commit (like `jj new`), edit the target commit directly (like `jj edit`)")
nextCmd.Flags().BoolP("help", "h", false, "Print help (see more with '--help')")
rootCmd.AddCommand(nextCmd)

carapace.Gen(nextCmd).PositionalCompletion(
jj.ActionNextCommits(100),
)
}
14 changes: 14 additions & 0 deletions pkg/actions/tools/jj/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ func ActionPrevCommits(limit int) carapace.Action {
}).Tag("previous commits")
}

func ActionNextCommits(limit int) carapace.Action {
return carapace.ActionExecCommand("jj", "log", "--no-graph", "--template", `commit_id.short() ++ "\t" ++ description.first_line() ++ "\n"`, "--revisions", "@-::", "--limit", strconv.Itoa(limit))(func(output []byte) carapace.Action {
lines := strings.Split(string(output), "\n")
format := "%0" + strconv.Itoa(len(strconv.Itoa(limit-1))) + "d"

vals := make([]string, 0)
for index, line := range lines[1 : len(lines)-1] {
splitted := strings.SplitN(line, "\t", 2)
vals = append(vals, fmt.Sprintf(format, len(lines)-3-index), splitted[1])
}
return carapace.ActionValuesDescribed(vals...).Style(styles.Git.HeadCommit)
}).Tag("previous commits")
}

// ActionRecentCommits completes recent commits
//
// 3b61f0a729f7 (compat: added cobra bridge)
Expand Down

0 comments on commit 0b0db74

Please sign in to comment.