git: restore - support --source

This commit is contained in:
rsteube 2024-10-23 19:33:58 +02:00
parent 50e3839ec3
commit 70048c9260
3 changed files with 9 additions and 2 deletions

View File

@ -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...)

View File

@ -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()
}),
)

View File

@ -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)
}