Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git: ActionChanges uid #2697

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions pkg/actions/tools/git/change.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package git

import (
"net/url"
"path/filepath"
"strings"

"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/style"
"github.com/carapace-sh/carapace/pkg/uid"
"github.com/carapace-sh/carapace/pkg/util"
)

Expand Down Expand Up @@ -55,7 +57,7 @@ func ActionChanges(opts ChangeOpts) carapace.Action {
path = splitted[1]
}

relativePath, err := filepath.Rel(evaluatedDir, root+"/"+path)
relativePath, err := filepath.Rel(evaluatedDir, filepath.Join(root, path))
if err != nil {
return carapace.ActionMessage(err.Error())
}
Expand All @@ -73,10 +75,20 @@ func ActionChanges(opts ChangeOpts) carapace.Action {
if strings.HasPrefix(c.Value, "./") {
action = action.Prefix("./")
}
return action
return action.UidF(func(s string, uc uid.Context) (*url.URL, error) {
abs, err := filepath.Abs(filepath.Join(evaluatedDir, s))
if err != nil {
return nil, err
}
rel, err := filepath.Rel(root, abs)
if err != nil {
return nil, err
}
return Uid("change")(rel, uc)
})
}
})
}).Tag("changed files")
}).Tag("changes")
}

// ActionRefChanges completes changes made in given ref
Expand Down Expand Up @@ -109,5 +121,5 @@ func ActionRefChanges(ref string) carapace.Action {

return carapace.ActionValues(vals...).StyleF(style.ForPathExt)
})
}).Tag("changed files")
}).Tag("ref changes")
}