Skip to content

Commit

Permalink
added git stash
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Oct 25, 2020
1 parent 52bc138 commit 1e4e273
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 3 deletions.
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,21 @@ func ActionMergeStrategyOptions(strategy string) carapace.Action {
return carapace.ActionValues()
}
}

func ActionStashes() carapace.Action {
return carapace.ActionCallback(func(args []string) carapace.Action {
if output, err := exec.Command("git", "stash", "list").Output(); err != nil {
return carapace.ActionValues(err.Error())
} else {
lines := strings.Split(string(output), "\n")
vals := make([]string, (len(lines)-1)*2)

for index, line := range lines[:len(lines)-1] {
splitted := strings.SplitN(line, ": ", 2)
vals[index*2] = splitted[0]
vals[(index*2)+1] = splitted[1]
}
return carapace.ActionValuesDescribed(vals...)
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import (
var stashCmd = &cobra.Command{
Use: "stash",
Short: "Stash the changes in a dirty working directory away",
Run: func(cmd *cobra.Command, args []string) {
},
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {

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

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action"
"github.com/spf13/cobra"
)

var stash_branchCmd = &cobra.Command{
Use: "branch",
Short: "create and check out a new branch with the stashes changes",
Run: func(cmd *cobra.Command, args []string) {},
}

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

stashCmd.AddCommand(stash_branchCmd)

carapace.Gen(stash_branchCmd).PositionalCompletion(
action.ActionRefs(action.RefOption{LocalBranches: true}),
action.ActionStashes(),
)
}
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/stash_clear.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 stash_clearCmd = &cobra.Command{
Use: "clear",
Short: "remove all the stash entries",
Run: func(cmd *cobra.Command, args []string) {},
}

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

stashCmd.AddCommand(stash_clearCmd)
}
22 changes: 22 additions & 0 deletions completers/git_completer/cmd/stash_drop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action"
"github.com/spf13/cobra"
)

var stash_dropCmd = &cobra.Command{
Use: "drop",
Short: "remove a single stash entry",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(stash_dropCmd).Standalone()
stash_dropCmd.Flags().BoolP("quiet", "q", false, "suppress feedback messages")

stashCmd.AddCommand(stash_dropCmd)

carapace.Gen(stash_dropCmd).PositionalCompletion(action.ActionStashes())
}
18 changes: 18 additions & 0 deletions completers/git_completer/cmd/stash_list.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 stash_listCmd = &cobra.Command{
Use: "list",
Short: "list the stash entries that you currently have",
Run: func(cmd *cobra.Command, args []string) {},
}

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

stashCmd.AddCommand(stash_listCmd)
}
24 changes: 24 additions & 0 deletions completers/git_completer/cmd/stash_pop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action"
"github.com/spf13/cobra"
)

var stash_popCmd = &cobra.Command{
Use: "pop",
Aliases: []string{"apply"},
Short: "remove a single stashed state",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(stash_popCmd).Standalone()
stash_popCmd.Flags().Bool("index", false, "try to reinstate index changes as well")
stash_popCmd.Flags().BoolP("quiet", "q", false, "suppress feedback messages")

stashCmd.AddCommand(stash_popCmd)

carapace.Gen(stash_popCmd).PositionalCompletion(action.ActionStashes())
}
31 changes: 31 additions & 0 deletions completers/git_completer/cmd/stash_push.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cmd

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

var stash_pushCmd = &cobra.Command{
Use: "push",
Short: "save your local modifications to a new stash",
Run: func(cmd *cobra.Command, args []string) {},
}

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

stash_pushCmd.Flags().BoolP("all", "a", false, "also stash ignored and untracked")
stash_pushCmd.Flags().BoolP("include-untracked", "u", false, "also stash untracked")
stash_pushCmd.Flags().BoolP("keep-index", "k", false, "keep changed added to index")
stash_pushCmd.Flags().StringP("message", "m", "", "set description")
stash_pushCmd.Flags().Bool("no-keep-index", false, "also apply to index")
stash_pushCmd.Flags().BoolP("patch", "p", false, "interactively select hunks between HEAD and working tree")
stash_pushCmd.Flags().Bool("pathspec-file-nul", false, "pathspec elemts are seperated by NUL")
stash_pushCmd.Flags().String("pathspec-from-file", "", "read pathspec from file")
stash_pushCmd.Flags().BoolP("quiet", "q", false, "suppress feedback messages")
stashCmd.AddCommand(stash_pushCmd)

carapace.Gen(stash_pushCmd).FlagCompletion(carapace.ActionMap{
"pathspec-from-file": carapace.ActionFiles(""),
})
}
21 changes: 21 additions & 0 deletions completers/git_completer/cmd/stash_show.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/git_completer/cmd/action"
"github.com/spf13/cobra"
)

var stash_showCmd = &cobra.Command{
Use: "show",
Short: "show the changes recorded in the stash entry",
Run: func(cmd *cobra.Command, args []string) {},
}

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

stashCmd.AddCommand(stash_showCmd)

carapace.Gen(stash_showCmd).PositionalCompletion(action.ActionStashes())
}

0 comments on commit 1e4e273

Please sign in to comment.