Skip to content

Commit

Permalink
Merge pull request #2218 from rsteube/git-maintenance
Browse files Browse the repository at this point in the history
git: added maintenance
  • Loading branch information
rsteube authored Feb 4, 2024
2 parents b59f3f2 + 8ba69df commit 6ece4cc
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 0 deletions.
19 changes: 19 additions & 0 deletions completers/git_completer/cmd/maintenance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var maintenanceCmd = &cobra.Command{
Use: "maintenance",
Short: "Run tasks to optimize Git repository data",
Run: func(cmd *cobra.Command, args []string) {},
GroupID: groups[group_main].ID,
}

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

rootCmd.AddCommand(maintenanceCmd)
}
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/maintenance_register.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var maintenance_registerCmd = &cobra.Command{
Use: "register",
Short: "Initialize Git config values",
Run: func(cmd *cobra.Command, args []string) {},
}

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

maintenanceCmd.AddCommand(maintenance_registerCmd)
}
27 changes: 27 additions & 0 deletions completers/git_completer/cmd/maintenance_run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cmd

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

var maintenance_runCmd = &cobra.Command{
Use: "run",
Short: "Start running maintenance on the current repository",
Run: func(cmd *cobra.Command, args []string) {},
}

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

maintenance_runCmd.Flags().Bool("auto", false, "run tasks based on the state of the repository")
maintenance_runCmd.Flags().Bool("quiet", false, "don't report progress or other information to stderr")
maintenance_runCmd.Flags().Bool("schedule", false, "run tasks based on frequency")
maintenance_runCmd.Flags().StringSlice("task", []string{}, "run a specific task")
maintenanceCmd.AddCommand(maintenance_runCmd)

carapace.Gen(maintenance_runCmd).FlagCompletion(carapace.ActionMap{
"task": git.ActionMaintenanceTasks(),
})
}
29 changes: 29 additions & 0 deletions completers/git_completer/cmd/maintenance_start.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var maintenance_startCmd = &cobra.Command{
Use: "start",
Short: "Start running maintenance on the current repository",
Run: func(cmd *cobra.Command, args []string) {},
}

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

maintenance_startCmd.Flags().String("scheduler", "", "specify scheduler")
maintenanceCmd.AddCommand(maintenance_startCmd)

carapace.Gen(maintenance_startCmd).FlagCompletion(carapace.ActionMap{
"scheduler": carapace.ActionValuesDescribed(
"auto", "",
"crontab", "POSIX",
"systemd-timer", "Linux",
"launchctl", "macOS",
"schtasks", "Windows",
),
})
}
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/maintenance_stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var maintenance_stopCmd = &cobra.Command{
Use: "stop",
Short: "Halt the background maintenance schedule",
Run: func(cmd *cobra.Command, args []string) {},
}

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

maintenanceCmd.AddCommand(maintenance_stopCmd)
}
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/maintenance_unregister.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var maintenance_unregisterCmd = &cobra.Command{
Use: "unregister",
Short: "Remove the current repository from background maintenance",
Run: func(cmd *cobra.Command, args []string) {},
}

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

maintenanceCmd.AddCommand(maintenance_unregisterCmd)
}
18 changes: 18 additions & 0 deletions pkg/actions/tools/git/maintenance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package git

import "github.com/rsteube/carapace"

// ActionMaintenanceTasks completes maintenance tasks
//
// commit-graph (Update the commit-graph files incrementally)
// prefetch (Updates the object directory with the latest objects from all registered remotes)
func ActionMaintenanceTasks() carapace.Action {
return carapace.ActionValuesDescribed(
"commit-graph", "Update the commit-graph files incrementally",
"prefetch", "Updates the object directory with the latest objects from all registered remotes",
"gc", "Clean up unnecessary files and optimize the local repository",
"loose-objects", "Clean up loose objects and places them into pack-files",
"incremental-repack", "Repack the object directory using the multi-pack-index feature",
"pack-refs", "Collect the loose reference files and collects them into a single file",
)
}

0 comments on commit 6ece4cc

Please sign in to comment.