Skip to content

Commit

Permalink
git: ActionChanges uid
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Feb 7, 2025
1 parent d1fc676 commit cf02158
Showing 1 changed file with 16 additions and 4 deletions.
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")
}

0 comments on commit cf02158

Please sign in to comment.