Home

git-age @main - refs - log - search -
https://git.jolheiser.com/git-age.git
git-crypt, but with age
cmd/rekey.go - raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
}