From 70048c9260fc2a5dc23e9f84968dcffa1466b0f5 Mon Sep 17 00:00:00 2001 From: rsteube Date: Wed, 23 Oct 2024 19:33:58 +0200 Subject: [PATCH] git: restore - support `--source` --- completers/git_completer/cmd/diff.go | 2 +- completers/git_completer/cmd/restore.go | 7 +++++++ pkg/actions/tools/git/diff.go | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/completers/git_completer/cmd/diff.go b/completers/git_completer/cmd/diff.go index 52dcec4a49..489c15ce4f 100644 --- a/completers/git_completer/cmd/diff.go +++ b/completers/git_completer/cmd/diff.go @@ -89,7 +89,7 @@ func actionDiffArgs(cmd *cobra.Command) carapace.Action { var action carapace.Action if cmd.Flag("cached").Changed { if len(expanded) > 0 { - action = git.ActionCachedDiffs(expanded[0]) + action = git.ActionCachedRefDiffs(expanded[0]) } } else { action = git.ActionRefDiffs(expanded...) diff --git a/completers/git_completer/cmd/restore.go b/completers/git_completer/cmd/restore.go index c2138366cb..43e9feba90 100644 --- a/completers/git_completer/cmd/restore.go +++ b/completers/git_completer/cmd/restore.go @@ -44,8 +44,15 @@ func init() { carapace.Gen(restoreCmd).PositionalAnyCompletion( carapace.ActionCallback(func(c carapace.Context) carapace.Action { if restoreCmd.Flag("staged").Changed { + if f := restoreCmd.Flag("source"); f.Changed { + return git.ActionCachedRefDiffs(f.Value.String()) + } return git.ActionChanges(git.ChangeOpts{Staged: true}).FilterArgs() } + + if f := restoreCmd.Flag("source"); f.Changed { + return git.ActionRefDiffs(f.Value.String()) + } return git.ActionChanges(git.ChangeOpts{Unstaged: true}).FilterArgs() }), ) diff --git a/pkg/actions/tools/git/diff.go b/pkg/actions/tools/git/diff.go index 6d943c44f3..34245b8d4d 100644 --- a/pkg/actions/tools/git/diff.go +++ b/pkg/actions/tools/git/diff.go @@ -138,7 +138,7 @@ func ActionRefDiffs(refs ...string) carapace.Action { } // ActionCachedDiffs completes changes between stage and given ref -func ActionCachedDiffs(ref string) carapace.Action { +func ActionCachedRefDiffs(ref string) carapace.Action { return actionRefDiffs(true, ref) }