Skip to content

Commit

Permalink
git: merge-base
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Aug 15, 2024
1 parent da21659 commit 7c430d0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 35 deletions.
43 changes: 43 additions & 0 deletions completers/git_completer/cmd/mergeBase.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cmd

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

var mergeBaseCmd = &cobra.Command{
Use: "merge-base",
Short: "Find as good common ancestors as possible for a merge",
Run: func(cmd *cobra.Command, args []string) {},
GroupID: groups[group_low_level_interrogator].ID,
}

func init() {
carapace.Gen(mergeBaseCmd).Standalone()

mergeBaseCmd.Flags().BoolP("all", "a", false, "output all merge bases for the commits")
mergeBaseCmd.Flags().Bool("fork-point", false, "find the point at which a branch forked from another branch <ref>")
mergeBaseCmd.Flags().Bool("independent", false, "print a minimal subset of the supplied commits with the same ancestors")
mergeBaseCmd.Flags().Bool("is-ancestor", false, "check if the first <commit> is an ancestor of the second <commit>")
mergeBaseCmd.Flags().Bool("octopus", false, "compute the best common ancestors of all supplied commits")
rootCmd.AddCommand(mergeBaseCmd)

mergeBaseCmd.MarkFlagsMutuallyExclusive(
"fork-point",
"independent",
"is-ancestor",
"octopus",
)

carapace.Gen(mergeBaseCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
switch {
case mergeBaseCmd.Flag("is-ancestor").Changed && len(c.Args) > 1,
mergeBaseCmd.Flag("fork-point").Changed && len(c.Args) > 1:
return carapace.ActionValues()
}
return git.ActionRefs(git.RefOption{}.Default())
}),
)
}
23 changes: 0 additions & 23 deletions completers/git_completer/cmd/merge_base_generated.go

This file was deleted.

12 changes: 0 additions & 12 deletions completers/git_completer/cmd/pretty.txt

This file was deleted.

0 comments on commit 7c430d0

Please sign in to comment.