git-age/cmd/rekey.go

46 lines
808 B
Go

package cmd
import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"github.com/bmatcuk/doublestar/v4"
"github.com/urfave/cli/v2"
)
var Rekey = &cli.Command{
Name: "rekey",
Aliases: []string{"r"},
Description: "Re-key secrets",
Action: actionRekey,
}
func actionRekey(ctx *cli.Context) error {
cfg, err := LoadConfig()
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
return nil
}
return err
}
dir, err := gitBaseDir()
if err != nil {
return err
}
os.Setenv(REKEY, "1")
for glob := range cfg {
files, err := doublestar.FilepathGlob(glob, doublestar.WithFilesOnly())
if err != nil {
return fmt.Errorf("bad glob %q: %w", glob, err)
}
for _, file := range files {
cmd("git", "add", "--renormalize", filepath.Join(dir, file))
}
}
return nil
}